Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %
- % Let V(G) be a set of vertices of the graph G, let N(v)
- % be a set of all neighbours of the vertex v in V, and
- % let a coloring be any assignment of the form V -> Colors,
- % where Colors = {1,2,3,...}. Find a coloring, which uses
- % a minimal number of colors, such that all sums of colors
- % of N(v) for every vertex v are pairvise distinct.
- % coloring([[2,3,4,5],[1,3],[1,2,4],[1,3,5],[1,4]],L).
- %
- :- use_module(library(clpfd)).
- coloring2(Graph,Coloring) :-
- length(Graph,N),
- length(Coloring,N),
- length(Tints,N),
- Cn in 1..N,
- labeling([ff], [Cn]),
- Coloring ins 1..Cn,
- constr(Graph,Coloring,Tints),
- all_different(Tints),
- labeling([ff], Tints).
- constr(Graph,Coloring,Tints) :-
- maplist(vert_sum(Coloring),Graph,Tints).
- vert_sum(VertexColoring,VertNeighInds, VertSum) :-
- maplist(ind_to_vert(VertexColoring),VertNeighInds,VertNeighs),
- sum(VertNeighs, #=, VertSum).
- ind_to_vert(VertexColoring,VertI,Vert) :-
- nth1(VertI,VertexColoring,Vert).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement