-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchromatic_number.lp
More file actions
37 lines (28 loc) · 967 Bytes
/
chromatic_number.lp
File metadata and controls
37 lines (28 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
%*
* File: chromatic_number.lp
* Author: David Gonzalez, Joshua T. Guerin
*
* Description: Given a graph, find the minimal set of colors s.t. no
adjacent veritices share a color.
* Use: clingo chromatic_number.lp instance.lp
*%
% Count the number of nodes/max colors.
count(N) :- N = #count{X : node(X)}.
% Set of available colors (max=number of nodes).
color(1..N) :- count(N).
% Edges are symmetric.
% Assumes potentially directed description of an undirected graph.
edge(M, N) :- edge(N, M).
% Each vertex is assigned a single color.
1 { color(N, C) : color(C) } 1 :- node(N).
% No two adjecent vertices can have the same color.
:- edge(N, M), color(N, C), color(M, C).
% Count the number of colors.
number(X) :- X = #count{ C : color(N, C) }.
% Minimize the number of colors used.
#minimize { X : number(X) }.
% PRINT
% Optional--display of color information is likely useful.
#show color/2.
% The chromatic number.
#show number/1.