Reputation: 825
I'm studying this code, and there is a + in the color function which I have no idea what it does. I'm very confused by this and I'm basically stuck on this because I can't understand what it does.
/* prolog tutorial 2.9 Map coloring redux */
adjacent(X,Y,Map) :- member([X,Y],Map) ; member([Y,X],Map).
find_regions([],R,R).
find_regions([[X,Y]|S], R,A) :-
(member(X,R) ->
(member(Y,R) -> find_regions(S,R,A) ; find_regions(S,[Y|R],A)) ;
(member(Y,R) -> find_regions(S,[X|R],A) ; find_regions(S,[X,Y|R],A) ) ).
color(Map,Colors,Coloring) :-
find_regions(Map,[],Regions),
color_all(Regions,Colors,Coloring),
\+ conflict(Map,Coloring).
color_all([R|Rs],Colors,[[R,C]|A]) :-
member(C,Colors),
color_all(Rs,Colors,A).
color_all([],_,[]).
conflict(Map,Coloring) :-
member([R1,C],Coloring),
member([R2,C],Coloring),
adjacent(R1,R2,Map).
map1([[1,2],[1,3],[1,4],[1,5],[2,3],[2,4],[3,4],[4,5]] ).
Upvotes: 2
Views: 7019
Reputation: 1383
"In standard Prolog the operator + means negation as failure"
There ist a good Tutorial found here.
Upvotes: 2