Information

Deadline No deadline
Submission limit No limitation

Sign in

[Part1 Exercise] Graph coloring problem

In this assignment, you will model a Graph Coloring Problem by using TinyCSP.

Go to the GraphColoringTinyCSP.java file within the tinycsp.examples package.

It contains one task inside the solve method, highlighted with a TODO. You will need to:

  1. Create the variables for solving the problem (using TinyCSP.makeVariable()). Each variable should represent the color of a node.
  2. Add constraints on the variables saying that two nodes connected by an edge (GraphColoringInstance.edges) cannot have the same color.
  3. Return the first valid solution that you encounter.
public static int[] solve(GraphColoringInstance instance) {
    // TODO: solve the graph coloring problem using TinyCSP and return a solution
    // Hint: you can stop the search on first solution throwing and catching an exception
    //       in the onSolution closure or you can modify the dfs search
}

Unsure on how to do that? You can have a look at the NQueensTinyCSP.java class to see how to create the variables, add constraints on them and processing the solution.

The implementation needs to be done within your personal repository that you have setup before.

You can check that your implementation is correct by running the tests within GraphColoringTinyCSPTest.