
coloring(Regions,Map,Colors,Ass) :-
     assign(Regions,Colors,Ass), 
     valid(Map,Ass).

assign([],_,[]).
assign([R|Regions],Colors,[[R,C]|Ass]) :-
     member(C,Colors),
     assign(Regions,Colors,Ass).

valid([],_).
valid([[R1,R2]|Map],Ass) :-
     member([R1,C1],Ass),
     member([R2,C2],Ass), 
     C1 \== C2,
     valid(Map,Ass).
     
member(X,[X|_R]).
member(X,[_Y|R]) :-
     member(X,R).



% Sample goals
%
% ?- coloring([r1,r2,r3],[[r1,r2],[r2,r3]],[c1,c2],Ass).
%
% ?- coloring([r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12],
%              [[r1,r2],[r2,r3],[r3,r4],[r4,r5],[r5,r6],[r6,r7],[r7,r8],[r8,r9],[r9,r10],[r10,r11],[r11,r12]],
%              [c1,c2,c3,c4],
%              Ass).


regions(1,[r1,r2,r3]).
regions(2,[italy,austria,swiss,france,slovenia]).
%regions(3,[r1,r2,r3,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12]).
regions(3,[r1,r2,r3,r4,r5,r6,r7,r8,r9,r10]).

map(1,[[r1,r2],[r2,r3]]).
map(2,[[italy,austria],[italy,france],[italy,slovenia],
       [italy,swiss],[austria,swiss],
       [austria,slovenia],[france,swiss]]).
%map(3,[[r1,r2],[r2,r3],[r3,r4],[r4,r5],[r5,r6],[r6,r7],[r7,r8],[r8,r9],[r9,r10],
%      [r10,r11],[r11,r12]]).
map(3,[[r1,r2],[r2,r3],[r3,r4],[r4,r5],[r5,r6],[r6,r7],[r7,r8],[r8,r9],[r9,r10]]).

colors(1,[c1,c2]).
colors(2,[white,yellow,red,blue]).
colors(3,[white,yellow,red,blue]).

sample_coloring(N,Ass) :-
       regions(N,R), 
       map(N,M),
       colors(N,C), 
       coloring(R,M,C,Ass).

% Sample goal
%
% ?- sample_coloring(2,Ass).
