I have the graph coloring problem defined in Clingo as so:
node(sa;wa;nt;q;nsw;v;t).
color(r;g;b).
edge(sa,(wa;nt;q;nsw;v)).
edge(wa,nt). edge(nt,q). edge(q,nsw). edge(nsw,v).
edge(X,Y) :- edge(Y,X).
and I have the solution characterized like this:
{assign(N,C) : color(C)} = 1 :- node(N).
:- edge(X,Y), assign(X,C1), assign(Y,C2), C1 == C2.
#show assign/2.
I cannot understand what the = 1 in the generate portion of the code means. I know that it is "set cardinality", but I do not understand how, as the code must generate seven nodes in each answer. Additionally, the following generator (which generates all combos of nodes and colors choosing in a set of length 7) requires an = 7:
{assign(N,C) : color(C), node(N)} = 7.
Here is a picture of the graph coloring problem I am solving: https://i.stack.imgur.com/5Sucr.jpg
and clingo: https://potassco.org/clingo/run/
This means "choose exactly one color for each node". Or, more precisely, for each node
n, pick one colorcsuch thatassign(n, c)becomes true.To understand this better, we need to dig into the semantics of ASP. Here N occurs outside of the cardinality constraint, so it can be viewed as a "global variable" in this rule. The rule is essentially a shorthand for:
Now, this set
{assign(sa,C) : color(C)}is just a shorthand for{assign(sa,r), assign(sa,g), assign(sa,b)}. Now,{assign(sa,r), assign(sa,g), assign(sa,b)}=1roughly speaking means pick one element from the set{assign(sa,r), assign(sa,g), assign(sa,b)}.If you look at clingo manual, the general syntax is
{assign(sa,r), assign(sa,g), assign(sa,b)} rel EXPR, whererelis an arithmetic relation andEXPRis some expression.