Michael Codish, Michael Frank, Amit Metodi Logic Programming with Max-Clique and its Application to Graph Coloring morad muslimany Ben-Gurion University of the Negev Joint work with: Michael Codish, Michael Frank, Amit Metodi {mcodish,frankm,moradm,amitmet}@cs.bgu.ac.il
Logic Programming with Max-Clique and its Application to Graph Coloring We will present pl-cliquer, a Prolog interface to the cliquer tool for the maximum clique problem. Agenda: Problem definitions and examples pl-cliquer Usage examples Experiments
Cliques, Maximum Cliques A clique in a graph 𝐺=(𝑉,𝐸) is a set 𝐶⊆𝑉 of pairwise adjacent vertices (∀ 𝑣 1 , 𝑣 2 ∈𝐶: 𝑣 1 , 𝑣 2 ∈𝐸) The maximum clique problem is about finding the largest clique in the graph
Cliques, Maximum Cliques A clique in a graph 𝐺=(𝑉,𝐸) is a set 𝐶⊆𝑉 of pairwise adjacent vertices (∀ 𝑣 1 , 𝑣 2 ∈𝐶: 𝑣 1 , 𝑣 2 ∈𝐸) The maximum clique problem is about finding the largest clique in the graph
Graph Coloring The problem of graph coloring is to find a labeling 𝑐:𝑉→𝑁 of the vertices of the graph such that 𝑖,𝑗 ∈𝐸⇔𝑐 𝑖 ≠𝑐(𝑗). The minimal graph coloring problem is to color the graph while using as few colors as possible. This number is called the Chromatic Number of the graph.
Graph Coloring The problem of graph coloring is to find a labeling 𝑐:𝑉→𝑁 of the vertices of the graph such that 𝑖,𝑗 ∈𝐸⇔𝑐 𝑖 ≠𝑐(𝑗). The minimal graph coloring problem is to color the graph while using as few colors as possible. This number is called the Chromatic Number of the graph.
Cliques and colorings Finding cliques is tremendously useful in the problem of Graph Coloring It is easy to show that the chromatic number of a graph 𝐺, 𝜒(𝐺), is greater than or equal to the size of the maximum clique, as all clique vertices must get different colors.
Hardness of these problems The clique decision problem (is there a clique of size ≤𝑘 in a graph) is NP-Complete Subsequently, the problem of finding a maximum clique is also NP-Hard. The graph coloring decision problem is NP- Complete In particular, the minimal graph coloring problem is NP-Hard
Hard but solvable in practice… Although the problem of maximum-clique is NP-Hard, it is solvable in practice in many graphs by various tools Cliquer is one such tool, which is a set of C routines for finding cliques in a graph
Logic Programming with Max-Clique and its Application to Graph Coloring We will present pl-cliquer, a Prolog interface to the Cliquer tool for the maximum clique problem. Agenda: Problem definitions and examples pl-cliquer Usage examples Experiments
pl-cliquer We have written an interface that connects Cliquer with SWI-Prolog, called pl-cliquer Provides five high-level predicates, and we will focus on the following three: graph_read_dimacs_file/5 clique_find_single/4 clique_find_n_sols/6
graph_read_dimacs_file(FileName,NVert,Weights,Graph,Options) Converts a graph in the standard DIMACS format to a Prolog representation as a Boolean adjacency matrix. Running example graph: FileName (content) NVert Weights Graph Options graph_read_dimacs_file(FileName,NVert,Weights,Graph,Options)
graph_read_dimacs_file(FileName,NVert,Weights,Graph,Options) Converts a graph in the standard DIMACS format to a Prolog representation as a Boolean adjacency matrix. Running example graph: 7 FileName (content) NVert Weights Graph Options graph_read_dimacs_file(FileName,NVert,Weights,Graph,Options)
clique_find_single(NVert,Graph,Clique,Options) Provides an interface to the Cliquer routine by the same name. Finds a single clique in the graph. 7 NVert Graph Clique Options clique_find_single(NVert,Graph,Clique,Options)
clique_find_single(NVert,Graph,Clique,Options) Provides an interface to the Cliquer routine by the same name. Finds a single clique in the graph. 7 NVert Graph Clique Options clique_find_single(NVert,Graph,Clique,Options)
clique_find_n_sols(MaxSols,NVert,Graph,Sols,Total,Options) Allows finding several cliques in a graph. min_weight(3) max_weight(4) maximal(false) 10 7 MaxSols NVert Graph Sols Total Options clique_find_n_sols(MaxSols,NVert,Graph,Sols,Total,Options)
clique_find_n_sols(MaxSols,NVert,Graph,Sols,Total,Options) Allows finding several cliques in a graph. min_weight(3) max_weight(4) maximal(false) 10 7 6 MaxSols NVert Graph Sols Total Options clique_find_n_sols(MaxSols,NVert,Graph,Sols,Total,Options)
Logic Programming with Max-Clique and its Application to Graph Coloring We will present pl-cliquer, a Prolog interface to the cliquer tool for the maximum clique problem. Agenda: Problem definitions and examples pl-cliquer Usage examples Experiments
Solving the Graph Coloring Problem We model the problem using a constraint language (BEE) The constraints model is then compiled to SAT using the BEE compiler (written in Prolog) The SAT instance is solved using a SAT solver via the Prolog interface (BEE allows a variety of solvers at its backend) The satisfied SAT instance assignment is decoded back to a graph coloring
Main Predicate We model the problem using a constraint language (BEE) The constraints model is then compiled to SAT using the BEE compiler (written in Prolog) The SAT instance is solved using a SAT solver via the Prolog interface (BEE allows a variety of solvers at its backend) The satisfied SAT instance assignment is decoded back to a graph coloring
?- graphColoring(Graph,5,Coloring) Example Can we solve our running example with 5 colors? ?- graphColoring(Graph,5,Coloring)
Example graphColoring(Graph, 5, Coloring)
?- graphColoring(Graph,5,Coloring) Example ?- graphColoring(Graph,5,Coloring)
pl-cliquer & graph coloring As well known, the maximum clique vertices can be preassigned different colors
pl-cliquer & graph coloring As well known, the maximum clique vertices can be preassigned different colors
pl-cliquer & graph coloring
Example – with pl-cliquer graphColoring(Graph,5,Coloring)
Logic Programming with Max-Clique and its Application to Graph Coloring We will present pl-cliquer, a Prolog interface to the cliquer tool for the maximum clique problem. Agenda: Problem definitions and examples pl-cliquer Usage examples Experiments
DIMACS Benchmarks – Selected Results With pl-cliquer and clique symmetry breaks Without pl-cliquer Instance Colors Cliquer Time BEE Time Clauses Vars SAT Time queen9_9 10 0.01 0.06 12026 547 6.91/sat myciel5 5 1170 195 0.85/unsat fpsol2.i.1 65 0.02 0/sat(BEE) school1_nsh 13 26.6 0/unsat(cl) BEE Time Clauses Vars SAT Time 0.06 24927 891 14.36/sat 0.01 1697 235 109.24/unsat 2.26 1121026 17781 1.87/sat 0.67 216343 4711 793.22/unsat
Toronto Benchmarks – Selected Results With pl-cliquer and clique symmetry breaks Without pl-cliquer Instance Colors Cliquer Time BEE Time Clauses Vars SAT Time pur-s-93 31 0.5 2.85 1098306 39613 3.36/sat 30 2.77 1005456 37849 1.44/unsat car-s-91 27 0.06 1.93 407155 12672 1578.48/sat car-f-92 0.2 1.15 179749 7634 0.73/sat BEE Time Clauses Vars SAT Time 14.43 3448166 71911 17.6/sat 7.18 3321648 70275 >86400 2.5 1018280 19897 2.6 713441 15616 4.35/sat
Questions?