Google OR-Tools (using SCIP solver) - How to access the intermediate solutions found by the solver?

只谈情不闲聊 提交于 2021-01-29 17:20:39

问题


I'm new to Google OR-Tools.

Using Python, I implemented a MIP model with SCIP as a solver. The objective function is for minimization (solver.Minimize(C)) and I am accessing the final solution through solver.Objective().Value().

However, I also need to access the intermediate solutions that the solver finds, before reaching the final one, and their timestamp. (The final goal is to plot a graph with the solutions evolution through time).

I tried to use a while loop:

solutions_evolution = {} # dict to store miliseconds (as keys) and solutions (as values)
localtime = (solver.wall_time()) #in miliseconds
limit_break = localtime + 60*5*1000 #sets a time limit of 5 minutes 

while (localtime <= limit_break) & (status != pywraplp.Solver.OPTIMAL & status != pywraplp.Solver.FEASIBLE):
new_localtime = (solver.wall_time())
solutions_evolution[new_localtime] = solver.Objective().Value() 
localtime = new_localtime

But it's not working since solver.Objective().Value() gives only the final solution.

I've been struggling for days. Can anyone please help me? Thank you.


回答1:


In non C++ languages, you cannot access the solver object, and incumbent callbacks are not accessible in python.

You can use solution pool though with SCIP.

Just run Solve(), then loop on NextSolution().

If your problem is purely integral, you can use the CP-SAT solver (directly, not through the linear solver wrapper). It supports solution callback in python.



来源:https://stackoverflow.com/questions/65664045/google-or-tools-using-scip-solver-how-to-access-the-intermediate-solutions-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!