%%%% k-COLORING

:-use_module(library(clpfd)).
:-use_module(library(lists)).

coloring(K, Vars) :-
         graph(Nodes, Edges),length(Nodes,N),
         length(Vars,N),
         domain(Vars, 1, K),
         constraints(Edges, Nodes, Vars),
         labeling([ff], Vars).
constraints([],_,_).
constraints([[A,B]|R], Nodes, Vars) :-
         nth(IdfA,Nodes,A),nth(IdfA,Vars,ColA),
         nth(IdfB,Nodes,B),nth(IdfB,Vars,ColB),
         ColA #\= ColB,
         constraints(R, Nodes, Vars).
