CMPT 477 / 777 Formal Verification Programming Assignment 1
This assignment is due by 11:59pm PT on Wednesday Oct 2, 2024. Please submit it to Canvas.
Late policy:Suppose you can get n (out of 100) points based on your code and report
- If you submit before the deadline, you can get all n points.
- If you submit between 11:59pm PT Oct 2 and 11:59pm PT Oct 3, you get n − 10 points.
- If you submit between 11:59pm PT Oct 3 and 11:59pm PT Oct 4, you get n − 20 points.
- If you submit after 11:59pm PT Oct 4, you get 0 points.
1 Problem Description
(100 points) A solution to a graph coloring problem is an assignment of colors to vertices such that notwo adjacent vertices have the same color. Formally, a finite graph G = (V, E) consists of vertices V ={v1, . . . , vn} and edges E = {(vi1 , wi1 ), . . . ,(vik , wik )}. The finite set of colors is given by C = {c1, . . . , cm}.
A problem instance is given by a graph and a set of colors: the problem is to assign each vertex v ∈ V a color(v) ∈ C such that for every edge (v, w) ∈ E, color(v) = color(w). Clearly, not all instances havesolutions.Please write a Java program with Z3 APIs to solve the graph coloring problem. The input is a file inthe following format
where the first line contains two positive integers: N is the number of vertices, and M is the number of colors(separated by a space). Without loss of generality, we can assume V = {1, . . . , N} and C = {1, . . . , M}.Each of the rest line contains two positive integers vij and wij that are no more than N, which correspondsto an edge (vij , wij ).The output is also a file. If an instance does not have 代 写CMPT 477 / 777 Formal Verification Programming a solution, write “No Solution” in the output file.Otherwise, write an assignment of colors to vertices in the following format.where vi denotes the vertex and ci denotes its color, i.e., color(vi) = ci , separated by a space.You might want to use the following hints for encoding:
- Introduce a boolean variable pv,c for color(v) = c.
- Describe the formula asserting every vertex is colored.1• Describe the formula asserting every vertex has at most one color.
- Describe the formula asserting that no two connected vertices have the same color.
2 Sample Input and Output
Suppose we have an input file input.txt that contains the following six lineswhich represents the following graph
After running the program, we can get a file with the following lines (not unique)1 1It means the colors of vertices v1, v2, v3, v4 are c1, c2, c2, c3, respectively.
3 Compilation and Execution
Compilation. The provided codebase uses the Maven build system. After you enter the verif-sat directory, the project can be easily compiled with one command
$ mvn packageThen you should be able to see the message “BUILD SUCCESS”. A directory called target will be createdand a jar file called verif-sat-1.0.jar will be generated inside the target.
Execution. In the verif-sat directory, you can execute the program using the following command (use ;instead of : on Windows)
$ java -cp lib/com.microsoft.z3.jar:target/verif-sat-1.0.jar sat.GraphColoring <in-path> <out-path>
where <in-path> is the path to the input file and <out-path> is the path to the output file.
For example, you can run
$ java -cp lib/com.microsoft.z3.jar:target/verif-sat-1.0.jar sat.GraphColoring input.txt output.txtYou will see a runtime exception with message “To be implemented”, because the program is not implemented yet. After you finish the implementation, you should see a file named output.txt with the contentas shown in Section 2.
24 Deliverable A zip file called P1 SFUID.zip (SFUID is replaced with your 9-digit student ID number) that contains the
followings:
- The verif-sat directory that contains your Java program. You can have multiple source files if youwant, but you need to make sure the project can be built and executed in the way described in Section 3.
- A short report called P1 SFUID.pdf that describes your encoding and explains the design choices,features, issues (if any), and anything else that you want to explain about your program.