我正在尝试在 google colab 中使用 Gurobi 求解器而不是 GLPK,但我不知道如何去做。我不知道在 SolverFactory 中导入和使用它的代码。
我尝试使用以下命令行:
!apt-get install -y -qq glpk-utils
#SolverFactory('glpk', executable='/usr/bin/glpsol').solve(model).write()
SolverFactory("gurobi", solver_io="python").solve(model).write()
我在“glpk”求解器中发表了评论,并尝试对 gurobi 做同样的事情,但我没有导入 gurobi 或之前安装了一些东西。我错过了什么?我应该做什么或代码应该是什么?
你必须安装
gurobipy
和pyomo
:
!pip install gurobipy pyomo
Edit:对于更大的问题,您必须申请 WLS 许可证(在您的情况下为学术)
获得许可后,使用:
# Create an environment with your WLS license
params = {
"WLSACCESSID": 'your wls accessid (string)',
"WLSSECRET": 'your wls secret (string)',
"LICENSEID": <your license id (integer)>,
}
env = gp.Env(params=params)
# Create the model within the Gurobi environment
model = gp.Model(env=env)