簡體   English   中英

使用 pyomo 和 gurobi 尋找解決方案

[英]Finding the solutions using pyomo and gurobi

我有一個使用 pyomo 和 gurobi 的代碼,但是當我嘗試運行它時,它並沒有給我最佳解決方案,只是說它們存在。 我能做些什么?

我有這個:

TransformationFactory('gdp.bigm').apply_to(model)
opt = SolverFactory("gurobi", solver_io="python") 
opt.options['NonConvex'] = 2
opt.solve(model).write()

它給了我這個:

# ==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem:
- Name: unknown
  Lower bound: 3722.006655208413
  Upper bound: 3722.0163664746015
  Number of objectives: 1
  Number of constraints: 98859
  Number of variables: 57239
  Number of binary variables: 13996
  Number of integer variables: 13996
  Number of continuous variables: 29247
  Number of nonzeros: 200378
  Number of solutions: 10
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver:
- Name: Gurobi 9.52
  Status: ok
  Wallclock time: 56.91826629638672
  Termination condition: optimal
  Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
 ----------------------------------------------------------
   Solution Information
 ----------------------------------------------------------
Solution:
- number of solutions: 0
  number of solutions displayed: 0

pyomo從求解器接收到解時,它會保留加載到所有變量中的最優值。 所以,你有很多選擇。

如果您想查看整個 model,您可以display哪些替換值:

model.display()

或僅針對一個變量

model.x.display()

或者您可以查詢對象的結果,例如您的目標 function

value(model.obj)   # assumes your objective function is named obj

這里的valuepyomo function,所以如果你導入和重命名(推薦),比如:

import pyomo.environ as pyo

那么它將是

pyo.value(model.obj)

暫無
暫無

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

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