I want to run a clingo program containing an optimization. I already have a (suboptimal) model. Is there a way to "help" clingo with the existing model? I'm using the python api.
Minimal example (n queens, but minimize the sum of the product of the coordinates):
from clingo import Control
ctl = Control(["0"])
ctl.add("base", [], """
#const n = 8.
{ q(I,1..n) } == 1 :- I = 1..n.
{ q(1..n,J) } == 1 :- J = 1..n.
:- { q(D-J,J) } >= 2, D = 2..2*n.
:- { q(D+J,J) } >= 2, D = 1-n..n-1.
#minimize{X*Y:q(X,Y)}.
""")
ctl.ground([("base", [])])
lastmdl = None
with ctl.solve(yield_=True) as models:
for model in models:
lastmdl = model.symbols(atoms=True)
print(lastmdl, model.cost)
will give me the output
[q(7,1), q(1,2), q(3,3), q(8,4), q(6,5), q(4,6), q(2,7), q(5,8)] [158]
[q(4,1), q(8,2), q(1,3), q(3,4), q(6,5), q(2,6), q(7,7), q(5,8)] [154]
[q(2,1), q(6,2), q(8,3), q(3,4), q(1,5), q(4,6), q(7,7), q(5,8)] [132]
[q(6,1), q(8,2), q(2,3), q(4,4), q(1,5), q(7,6), q(5,7), q(3,8)] [128]
[q(1,1), q(6,2), q(8,3), q(3,4), q(7,5), q(4,6), q(2,7), q(5,8)] [126]
In a previous step I already found a model with a value of 132. How can I use the knowledge of this existing model to my advantage in the sense that I could skip the first 3 models in the current solve call? To be clear: The goal is to speed up the search for the optimal model.