DM811 - Heuristics for Combinatorial Optimization
Assignment Sheet 1, Autumn 2011 [pdf format]

Submission deadline: Monday, September 05, 2011 at 12:00.

This series of obligatory assignments has the goal of preparing the student to the final project, thus setting up the development environment, gaining practical experience on the methods discussed in class and carrying out analysis of experimental results. The content of the assignments will also provide elements for discussion in class. The student is encouraged to search feedback among peers, posting on the discussion board within the Black Board, or posing questions in class. Working in groups of maximum three persons is allowed, but only in form of discussion and exchange of idea. Since submissions must be individual each student has to develop his own code (this will be good for the final project, which is going to be independent work).

The first assignments are focused on the well known Graph Coloring Problem.

1  Graph Coloring Problem

The graph (vertex) coloring problem (GCP) asks to find an assignment of colors to vertices of a graph in such a way that no adjacent vertices receive the same color. Graph coloring problems arise in many real life applications like register allocation, air traffic flow management, frequency assignment, light wavelengths assignment in optical networks and timetabling. More formally, let G = (V, E) be an undirected graph, with V being the set of |V| = n vertices and E being the set of edges. A k-coloring of G is a mapping ϕ : V → Γ, where Γ = 1, 2,…, k is a set of |Γ| = k integers, each one representing a color. A k-coloring is feasible or proper if for all [u, v] ∈ E it holds that ϕ(u) = ϕ(v); otherwise it is infeasible. If for some [u, v] ∈ E it is ϕ(u) = ϕ(v), the vertices u and v are in conflict. A feasible k-coloring in which some vertices are uncolored is said to be a partial k-coloring.

The GCP can be posed as a decision or as an optimization problem. In the decision version, also called the (vertex) k-coloring problem, the question to be answered is whether for some given k a feasible k-coloring exists. The optimization version of the GCP asks for the smallest number k such that a feasible k-coloring exists; for a graph G, this number is called the chromatic number χG.

For some graphs the chromatic number is known. A famous example is the four color theorem: if a graph is planar then it admits a feasible 4-coloring. However, deciding for a planar graph whether it also admits a 3-coloring has been shown to be an NP-complete problem. For general graphs it remains NP-complete and, consequently, the chromatic number problem is NP-hard (Karp 1972).

2  Coloring Queen Graphs

A famous chess puzzle asks to dispose n queens on an n × n chessboard such that none of them is able to attack any other using the standard chess queen’s moves. Thus, a solution requires that no two queens share the same row, column, or diagonal. Derived from this puzzle, the n2 queen puzzle asks to dispose in a n × n chessboard n × n queens subdivided into n subgroups such that no two queens belonging to the same group can attack each other. See Figure 1 for an example, where queens are represented by the integers 0, … , n−1 and each integer indicates a queen group.

The n2 has a solution whenever (n mod 6) ≡ 1 or 5. This condition is sufficient. It is also necessary when n < 12. Thus none of the n2 queen problems with n = 2, 3, 4, 6, 8, 9 have solution, while for n = 5 and n = 7 a feasible solution is reported in Figure 1. For n ≥ 12 counterexamples have been found, eg, for n = 12, 14, 15, 16, 18, 20, 21, 22, 24, 28, 32, that are solvable despite of the fact that the condition does not hold.


0   1   2   3   4 
3   4   0   1   2 
1   2   3   4   0 
4   0   1   2   3 
2   3   4   0   1 
   
0   1   2   3   4   5   6
5   6   0   1   2   3   4
3   4   5   6   0   1   2
1   2   3   4   5   6   0
6   0   1   2   3   4   5
4   5   6   0   1   2   3
2   3   4   5   6   0   1
Figure 1: A solution to the 5× 5 and 7× 7 queen problem.

3  Your tasks

  1. Formulate the n2-queen problem as a Constraint Satisfaction Problem.
  2. Show how the n2-queen problem can be modeled as a graph coloring problem.
  3. Write a program that for a given n outputs the graph corresponding to the n2-queen.

    Write the graph in a text file in which each line begins with a letter that defines the content of the line. The legal lines are:

  4. Model the graph coloring problem defining the solution representation and the constraints.
  5. Design some solution algorithms, preferably construction heuristics.
  6. At the course web page you find for C++ the source code of a random generator, a timer and a class for reading the input file in the DIMACS format. Alternatively, in Java, you find a framework in form of example for the TSP. Get acquainted with one of these environments. For insights on how to organize the classes and methods in your program you may read the article on EasyLocal++ [A1] or download and inspect that framework (links from the web page).
  7. Implement in the framework selected the heuristics designed.
  8. Check the correctness of the coloring found by your program using the verifier: http://www.imada.sdu.dk/~marco/Files/test_sol-2.3.tgz. The verifier takes in input the problem instance file in DIMACS format and a solution file. The solution file must report a column of numbers corresponding to the colors assigned to each vertex. After each entry the character \n (new line) has to be printed. Colors start from 1 and the first color in the column represents the color assigned to vertex 1. All vertices must receive a color, if your solution has uncolored vertices assign to them any color at random.
  9. Submit the solution files that have been verified and that correspond to the best algorithm you implemented. There should be a solution file for each of the graphs of Table 1. The table indicates the chromatic number for each graph of the corresponding n2-problem. A dash indicates that the chromatic number is not known yet, that is, it is unknown whether a coloring with n colors exists. In addition submit the another file reporting in one single line, the number of colors used by the proper coloring found and the number of seconds your algorithm took to find that solution. See in the Appendix the details for the submission.

    n234567891011121314151617
    col.345577910111212141516 
    n181920212223242526272829303132 
    col.18202122242832 
    Table 1: Known solutions to the n2 queen.

Appendix

The submission has to comply to the requirements described in this appendix. The submission for the final exam will follow a very similar procedure. In the assignments, if your submission is not compliant you will be asked to resubmit (up to a limited number of times), but at the final exam a resubmission is not allowed.

Delivery

Your work must be handed in electronically within the given deadline. (In the final exam, in addition to the electronic submission, you must also deposit two printed copy of your report at the teacher’s mailbox in the secretary office.) The submission is done via BlackBoard. Your files must be organized as follows:

Main directory:

    CPRN/ 

where CPRN is the student’s CPR number without the last four digits (eg, 030907) and content:

    CPRN/README
    CPRN/Makefile
    CPRN/src/
    CPRN/bin/
    CPRN/res/
    CPRN/doc/

The file README reports the name of the student and the manual for the compilation of the program. The directory src contains the source files, which may be in Comet, C, C++, Java or python. If needed a Makefile can be included either in the root directory or in src. After compilation the executable must be placed in bin. For java programs, a jar package can also be submitted. The directory doc will contain the written report (only in the final project), that will be the main source for the evaluation of the project. The report must be kept anonymous and only identified by the CPRN.

For this assignment you will have to provide the solutions in res. For every queen problem, identified by n you must provide two files. The first containing the solution in the format required by the verifier and the second consisting of a single line made by two numbers separated by a space. The first number must be an integer indicating the number of colors used by the solution provided and the second number must be a real indicating the number of seconds used to find the solutions (you must produce your results in IMADA machines). For example in the case of n=8:

    CPRN/res/queen8_8.sol
    CPRN/res/queen8_8.txt
> cat CPRN/res/queen8_8.sol
1
2
4
3
2
2
1
...
> cat CPRN/res/queen8_8.txt
8 10.6

Use the same name patterns and extensions as in the example.

Program Options and Output

Programs must work on IMADA’s computers under Linux Ubuntu operating system and with the compilers and other applications present on IMADA’s computers. You are free to develop your program elsewhere, but it is your own responsibility to transfer the program to IMADA’s system and make the necessary adjustments such that it works at IMADA.1 The Comet version is assumed to be the last one available.

Your program will be run by typing in the directory CPRN/:

    bin/gcp -i INSTANCE -t TIME -s SEED -o OUTPUT

For example: gcp -i queen8_8.col -o queen8_8.sol -t 300 -s 1 will run the program on the instance queen8_8.col opportunely retrieved from the given path for 300 seconds with random seed 1 and write the solution in the file queen8_8.sol. It is advisable to have a log of algorithm activities during the run. This can be achieved by printing on the standard error or in a file (which maybe determined with a option -o filename) further information. A suggested format is to output a line whenever a new best solution is found containing at least the following pieces of information:

    best 853 col 10 time 0.000000 iter 0 par_iter 0 

1
Past issues: the java compiler path is /usr/local/bin/javac; in C, any routine that uses subroutines from the math.c library should be compiled with the -lm flag – eg, cc floor.c -lm.