我正在研究大规模 MILP。因此,我必须将时间限制设置为合理的值,或者必须将 MIPGap 设置为合理的水平。我已经知道 gurobi 的文档了。MIPGap:https://www.gurobi.com/documentation/6.5/refman/mipgap.html时间限制:https://www.gurobi.com/documentation/8.0/refman/timelimit.html#parameter :TimeLimit当 MIPGap Gurobi 在最佳百分比范围内找到解决方案时,它将停止TimeLimit Gurobi 将在一定时间后停止。但是您能否给我发送一个示例,其中将时间限制设置为 5 分钟或将 MIPGap 设置为 5%?我不知道如何具体实现这些角色?请帮助我,我对 python 很陌生我尝试过,但这不起作用 model.Params.TimeLimit = 5
model.setParam("MIPGap", mipgap)这是我的模型的简短版本from gurobipy import * import csvimport geopandas as gpdimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.patches as mpatchesfrom pandas.core.common import flattenimport math################################# SOLVE function START ###################################################################def solve( vpmaint, wpunit, wuunit, vumaint, kfuel, koil, kbio, hb, ht, cj, ci, zinvestp, zinvestu, DEMAND, DEMANDM, LOCATION, SOURCE, BTYPE, SOURCEM, osi, oij, ojm ): model = Model("Biomass to liquid supply chain network design")################################# SOLVE function END ########################################################################################################################## variable section START #####################################################################################################binary variables ############################# Binary 1-2 #####################################################binary 1: Pyrolyse i with capacity p open? fpopen = {} for i in LOCATION: for p in R: fpopen[i,p] = model.addVar(vtype = GRB.BINARY,name = "fpopen_%s_%s" % (i,p))#binary 2: Upgrading j with capacity r and technology t open? fuopen = {} for j in LOCATION: for r in R: for t in TECHNOLOGY: fuopen[j,r,t] = model.addVar(vtype = GRB.BINARY,name = "fuopen_%s_%s_%s" % (j,r,t))
2 回答
![?](http://img1.sycdn.imooc.com/5458477300014deb02200220-100-100.jpg)
喵喵时光机
TA贡献1846条经验 获得超7个赞
或者,您可以调用模型的setParam()
方法:
model.setParam('MIPGap', 0.05) model.setParam('Timelimit', 300)
![?](http://img1.sycdn.imooc.com/545864000001644402200220-100-100.jpg)
慕容708150
TA贡献1831条经验 获得超4个赞
您需要在调用 Model.optimize() 之前设置参数。此外,MIPGap 和 TimeLimit 的单位分别是分数和秒。所以你的代码应该是:
model.Params.MIPGap = 0.05 # 5%
model.Params.TimeLimit = 300 # 5 minutes
model.optimize()
添加回答
举报
0/150
提交
取消