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.