【问题标题】:PULP - How to get the CPLEX solver status instead of the LpStatus stauts?PULP - 如何获取 CPLEX 求解器状态而不是 LpStatus 状态?
【发布时间】:2021-01-01 13:27:23
【问题描述】:

我在 Python 中通过 PULP 使用 CPLEX 求解器。当我解决时间限制问题时,CPLEX 将代码107 打印到屏幕上,这意味着“超出时间限制,但存在整数解”。但是,如果我打印pulp.LpStatus[problem.status] 的状态,我得到的是值 1,根据纸浆的documentation 表示已找到最佳解决方案,这实际上是错误的。

如何访问 CPLEX 状态代码而不是 PULP 的?

【问题讨论】:

    标签: python linear-programming cplex pulp


    【解决方案1】:

    您可以直接访问 CPLEX 状态代码和状态字符串。考虑以下示例:

    >>> import pulp 
    >>> prob = pulp.LpProblem("example", pulp.LpMinimize)
    >>> x = pulp.LpVariable('x', lowBound=0, upBound=1)
    >>> prob+= x <= -1
    
    • 示例 1 - 超出时间限制

      >>> solver = pulp.CPLEX_PY(msg=0, timeLimit=0)
      >>> prob.setSolver(solver)
      >>> prob.solve()
      -3
      >>> solver.solverModel.solution.get_status()
      108
      >>> solver.solverModel.solution.get_status_string()
      'time limit exceeded, no integer solution'
      
    • 示例 2 - 不可行

      >>> solver = pulp.CPLEX_PY(msg=0)
      >>> prob.setSolver(solver)
      >>> prob.solve()
      -1
      >>> solver.solverModel.solution.get_status()
      103
      >>> solver.solverModel.solution.get_status_string()
      'integer infeasible'
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 2012-03-09
      • 2018-03-01
      相关资源
      最近更新 更多