potassco / clasp

⚙️ A conflict-driven nogood learning answer set solver

Home Page:https://potassco.org/clasp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

infinite loop when optimizing

rkaminsk opened this issue · comments

The following program goes into an infinite loop when optimizing (always repeating the same suboptimal model):

{a; b; c; d}.
:- b, c.
:- a, d.

x :- a.
x :- b.

#minimize {
    -2@2,a:a; -2@2,b:b; -1@2,c:c;
    1@1,a:a;
    1@0,b:b
}.

@rkaminsk Thanks for the report.
This is due to a bug in the minimize pre-processing and creation of the sparse weights representation.
Internally, clasp maps priorities into consecutive levels with level 0 having the highest priority. Furthermore, literals to minimize always have a positive weight at the most relevant level. After preprocessing, clasp minimizes literals -a,(2@0, -1@1), -b,(2@0, -1@2), and -c,(1@0).

The algorithm assumes that the final set of literals to minimize is ordered by decreasing weights but when writing the comparator for sparse weight lists, I failed to realize that missing levels might actually be relevant. That is, I missed that -a,(2@0, -1@1) is actually not greater than -b,(2@0, -1@2) since the latter is actually -b,(2@0, 0@1,-1@2) and 0 is indeed greater than -1 😞

Anyhow, once the literals are ordered correctly, clasp computes the correct optimum. I'll try to push a fix in the next days.

Since lexicographic optimization is working in most cases it could only be a nasty corner case. Always these pesky details. 😈 Thanks, for the quick investigation.