Gurobi-设置多种中止准则(multiple termination criteria)

How do I set multiple termination criteria for a model?

说明:这篇内容转自Gurobi-support,为了防止
原链接如下:https://support.gurobi.com/hc/en-us/articles/360013419411-How-do-I-set-multiple-termination-criteria-for-a-model-

When multiple termination parameters are used, Gurobi Optimizer will stop when it reaches the first one. For example, if you want to stop when you reach 10% MIP gap or when 60 seconds have elapsed, then set MIPGap=0.1 and TimeLimit=60.
当使用多个终止参数时,Gurobi Optimizer 将在到达第一个时停止。例如,如果你想在达到 10% 的MIP 差距时或在 60 秒过去后停止,则设置 MIPGap=0.1 和 TimeLimit=60。

If a more complex set of stopping criteria is required, one possibility is to use warm starts. For example:
如果需要一组更复杂的停止标准,一种可能性是使用热启动。例如:

  • Suppose you need a 1% MIP gap, while a smaller MIP gap is preferable if it takes less than 300 seconds. To implement this rule set, start with TimeLimit=300. If the value of the MIPGap attribute is larger than 0.01 when the time limit is reached, then increase the TimeLimit parameter, set the MIPGap parameter to 0.01, and continue to solve the MIP.
    假设您需要 1% 的 MIP gap,而如果用时少于 300 秒,则更小的 MIP gap更可取。要实施此规则集,请从 TimeLimit=300 开始。如果达到时间限制时MIPGap属性的值大于0.01,则增加TimeLimit参数,将MIPGap参数设置为0.01,继续求解MIP。

  • To set a time limit that is considered only if at least one feasible solution has been found, you could use:
    要设置仅在找到至少一个可行解决方案时才考虑的时间限制,可以使用下面的代码:

timeLimit = 20
try:
    m = read('b1c1s1.mps.gz')
    oldSolutionLimit = m.Params.SolutionLimit
    m.Params.SolutionLimit = 1
    m.optimize()
    m.Params.TimeLimit = timeLimit - m.getAttr(GRB.Attr.Runtime)
    m.Params.SolutionLimit = oldSolutionLimit - m.Params.SolutionLimit
    m.optimize()
except (GurobiError, AttributeError, Exception) as e:
    print('Caught: ' + e.message)

这篇文章提到的热启动,我理解的是先进行一次求解.optimize(),如果发现能满足自己的要求,则再求解.optimize()一次,进行输出。然后就可以把第一次的求解称为是热启动。

For more complex termination criteria, you may want to consider using callbacks. Please see “How do I use callbacks to terminate the solver?” for more information.
对于更复杂的终止条件,您可能需要考虑使用回调。请参阅 如何使用回调来终止求解器? 了解更多信息。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值