I have a predicate pred/2, how do I #show this predicate in the answer that is sorted by the first argument, given that the first argument will be numerical?
I couldn't find any relevant documentation on how Clingo orders its output predicates.
I have a predicate pred/2, how do I #show this predicate in the answer that is sorted by the first argument, given that the first argument will be numerical?
I couldn't find any relevant documentation on how Clingo orders its output predicates.
On
Depending on your use case... you can encourage the discovered answer sets to be sorted (and adjacent) if you structure its choices:
% Equivalent to: { pred(N) : N=1..100 }.
{ pred(1) }.
{ pred(N+1) } :- pred(N), N < 100.
Now the answer sets containing pred(_) will always start at 1 and be sequential, and will be sorted in the output.
In my brief experiments, the drawback was ~3% increase in solution time.
The clingo system allows you to solve exponentially hard problems. It has no sophisticated options to sort the output. Use the clingo python API or a postprocessor to do so.