簡體   English   中英

C++ 中使用 Google 或工具進行線性規划:使用回調 function 停止搜索

[英]Linear Programming with Google or-tools in C++: Use callback function to stop search

我正在使用 Google 的 or-tools 庫結合 SCIP 求解器來求解 integer 線性程序,通過利用 MP Solver MPSolver 我希望每次找到新的候選解決方案時都會調用一個可自定義的回調 function。 這個回調 function 應該能夠評估解決方案,並且如果基於某些用戶標准解決方案“足夠好”,則盡早停止 ilp-solver。 Gurobi-py 中的等價物看起來像這樣:


  def callback(model_cb: gp.Model, where):
        assert where != gp.GRB.Callback.MULTIOBJ
        if where == gp.GRB.Callback.MIPSOL:
                model_cb._check_is_success(model_cb.cbGetSolution(s)):
                model._interrupted_success = True
                model_cb.terminate()
model = gp.Model()
model._check_is_success = check_is_success
model._interrupted_success = False
[...]
# Set up model
model.optimize(callback)

我在 [OR-Tools 文檔}(https://developers.google.com/optimization/reference/linear_solver/linear_solver/MPSolver) 中找到了MPSolver class 的SetCallback ,但沒有使用示例。 我在哪里可以找到有關如何在 or-tools 中使用回調函數提前終止 ILP 求解器的示例?

你的問題純粹是積分嗎?

您可以使用原生 CP-sat API。

它是一個更好的線性 integer 求解器,支持所有語言的回調。

https://github.com/google/or-tools/blob/stable/ortools/sat/docs/solver.md#c-code-4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM