Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infinite loop when optimizing #96

Closed
rkaminsk opened this issue Sep 29, 2023 · 3 comments
Closed

infinite loop when optimizing #96

rkaminsk opened this issue Sep 29, 2023 · 3 comments

Comments

@rkaminsk
Copy link
Member

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
}.
@BenKaufmann
Copy link
Contributor

@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.

@rkaminsk
Copy link
Member Author

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.

BenKaufmann added a commit that referenced this issue Oct 1, 2023
* MinimizeBuilder::CmpWeight failed to handle missing levels correctly.
  In particular, if a tuple R with *negative* weight w at level p was
  compared to a tuple L with missing weight at p, RHS was incorrectly
  considered to be greater than L. Fix this so that now the weight at
  p is compared to 0 (no weight at p).
@rkaminsk
Copy link
Member Author

rkaminsk commented Oct 1, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants