1

I have the following code:

from clingo import Control

def on_model(m):
    print(m, m.optimality_proven)

ctl = Control(["0"])
ctl.add("base", (), "0 { a } 1. :~ a. [-1@0]")
ctl.ground([("base", ())])
solution = ctl.solve(on_model=on_model)
assert solution.exhausted

When I run it, the output is:

 False
a False

I am confused about why the optimality_proven flag is set to False in the second case. Clingo first checks the empty model, which is suboptimal, then it checks the model containing the single atom a, which is optimal. But for some reason it does not know it's optimal, even though the search is exhausted? Is that because the exhaustion only happens after this model is checked? But then, how do I get this flag to ever be se to True? I mean, I could do some workarounds like storing and comparing the generated models inside the on_model function to check for optimality myself, but that feels very unnatural, considering the API hints at the functionality already being available with this optimality_proven attribute.

user1747134
  • 2,374
  • 1
  • 19
  • 26

1 Answers1

1

My understanding is that you need to instantiate clingo control as follows:

ctl = Control(["0", "--opt-mode=optN"])

In this case, it will 'enumerate' optimal models after finding one with the m.optimality_proven flag set:

  False

a False

a True

Clingo outputs model once it finds them, so it probably doesn't know that the model is optimal when it outputs the second line. It is only known after it exhausts the search.

Evgenii.Balai
  • 939
  • 13
  • 30