Can't stop search after getting one feasible solution

572 views
Skip to first unread message

Weiyu Tan

unread,
Apr 1, 2021, 7:00:23 AM4/1/21
to or-tools-discuss
I want to get feasible answer as early as possible in CP-SAT model and I have set these codes.

solver.parameters.log_search_progress = True
status = solver.Solve(model) 
if status == cp_model.FEASIBLE or status == cp_model.OPTIMAL:
    ......

But when running codes it can't stop after getting  feasible solution and got stuck.
487E9877-5B3F-4307-8D0B-D4019EF56421.png
ADA3D8589B29D986C70016866D0CB0AB.jpg

I have to add command like:
solver.parameters.max_time_in_seconds = 10.0
so that it can stop searching after 10s. But I want to stop searching as long as it finds at least one feasible answer. Where is the problem?

Priidik Vilumaa

unread,
Apr 1, 2021, 7:07:04 AM4/1/21
to or-tools-discuss
if status == cp_model.FEASIBLE or status == cp_model.OPTIMAL:
This line is executed in Python after the search is complete so it won't help you.

You can either solve without an objective function (then the first feasible solution is optimal) or solve with solution callback and stop the search as soon as a feasible solution is found.

Best,
Priidik
Reply all
Reply to author
Forward
0 new messages