maxanswer-set-programmingclingo

Find the maximum of an atom in clingo


I am a starter with clingo and I can't for the life of me figure out how to get the max value of a given atom.
e.g.

x(1..9).
x_max(X) :- x(X), x(Y), X>Y.

The result I would like to have in this case would be x_max(9).


Solution

  • Try this:

    max_x(X) :- x(X), #max {XX,1:x(XX)} = X.