如何让 CBC 在时限内返回最佳解决方案? (皮莫)

2024-04-17

我正在尝试在 Pyomo 上使用 CBC(v2.10.3) 来解决整数线性问题。

执行求解器时,我当前设置的时间限制为 600 秒。

opt = SolverFactory ("cbc")

opt.options['seconds'] =600

在这个时间限制内,求解器设法找到多个可行的解决方案。但是,当它在 600 秒结束时超时时,它不会返回找到的最佳整数解。相反,它返回一个非整数解。

有没有办法在 pyomo 上使用 CBC 在时间限制结束时返回最佳整数解决方案?

(我知道设置了一个最优差距。但是,最好解决给定的时间并返回找到的最佳解决方案。)

Cbc0010I After 144000 nodes, 17010 on tree, 51.908959 best solution, best possible 5.2447218 (566.79 seconds)
Cbc0010I After 145000 nodes, 16985 on tree, 51.908959 best solution, best possible 5.2447218 (568.59 seconds)
Cbc0010I After 146000 nodes, 17412 on tree, 51.908959 best solution, best possible 5.2447218 (576.34 seconds)
Cbc0010I After 147000 nodes, 17433 on tree, 51.908959 best solution, best possible 5.2447218 (578.44 seconds)
Cbc0010I After 148000 nodes, 17486 on tree, 51.908959 best solution, best possible 5.2447218 (580.85 seconds)
Cbc0010I After 149000 nodes, 17542 on tree, 51.908959 best solution, best possible 5.2447218 (583.95 seconds)
Cbc0010I After 150000 nodes, 17983 on tree, 51.908959 best solution, best possible 5.2447218 (592.30 seconds)
Cbc0010I After 151000 nodes, 18070 on tree, 51.908959 best solution, best possible 5.2447218 (595.20 seconds)
Cbc0010I After 152000 nodes, 18138 on tree, 51.908959 best solution, best possible 5.2447218 (599.62 seconds)
Cbc0020I Exiting on maximum time
Cbc0005I Partial search - best objective 51.908959 (best possible 5.2447218), took 2633537 iterations and 152193 nodes (600.40 seconds)
Cbc0032I Strong branching done 27294 times (118365 iterations), fathomed 967 nodes and fixed 3958 variables
Cbc0035I Maximum depth 321, 459 variables fixed on reduced cost
0  Obj 3.5097934 Primal inf 30287.686 (125) Dual inf 3.9849334e+15 (82)
Stopped - objective value 4.7188173e+14
Cuts at root node changed objective from 5.22475 to 5.24432
Probing was tried 187648 times and created 142527 cuts of which 0 were active after adding rounds of cuts (35.562 seconds)
Gomory was tried 89556 times and created 384764 cuts of which 0 were active after adding rounds of cuts (40.036 seconds)
Knapsack was tried 361 times and created 4 cuts of which 0 were active after adding rounds of cuts (0.233 seconds)
Clique was tried 361 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.001 seconds)
MixedIntegerRounding2 was tried 89572 times and created 84177 cuts of which 0 were active after adding rounds of cuts (33.927 seconds)
FlowCover was tried 361 times and created 14 cuts of which 0 were active after adding rounds of cuts (0.473 seconds)
TwoMirCuts was tried 89556 times and created 342658 cuts of which 0 were active after adding rounds of cuts (51.857 seconds)
ZeroHalf was tried 361 times and created 136 cuts of which 0 were active after adding rounds of cuts (0.365 seconds)

Result - Stopped on time limit

Objective value:                100000000000000007629769841091887003294964970946560.00000000
Lower bound:                    5.245
Gap:                            19066788138679049496143571255167978698885048565760.00
Enumerated nodes:               152193
Total iterations:               2633537
Time (CPU seconds):             600.48
Time (Wallclock seconds):       600.48

Total time (CPU seconds):       600.50   (Wallclock seconds):       600.51

感谢您的帮助!


我有同样的问题,我想我找到了解决方案。问题是求解器退出时状态为“已中止”。有两种方法可以更改求解器的状态:

  1. 解决问题后、加载解决方案之前,只需更改状态即可:

    from pyomo.opt.results import SolverStatus
    ...
    optimizer = SolverFactory('cbc')
    result = optimizer.solve(prob,tee=True) 
    result.Solver.Status = SolverStatus.warning
    prob.solutions.load_from(result)   
    
  2. 在文件“...\pyomo\solvers\plugins\solvers\CBCplugin.py”中,替换每个SolverStatus.aborted with a SolverStatus.warning(就我而言,有 2 行)。这可以防止求解器处于中止状态。

它适用于我使用 pyomo==5.6.9 和 cbc==2.10.3

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让 CBC 在时限内返回最佳解决方案? (皮莫) 的相关文章

随机推荐

  • VSCode 中是否有快捷方式可以在调试 REPL 中执行当前行或选择?

    我正在使用 Python 进行开发 并且通常在集成终端中运行代码Shift Enter 不过调试的时候过程似乎比较复杂 我需要复制代码 将焦点移至调试 REPL Ctrl Shift Y 粘贴 运行并将焦点移回编辑器 有没有更简单的方法来做
  • pip3 安装不起作用 - 没有名为“pip._vendor.pkg_resources”的模块

    当尝试安装 Python 3 的软件包 在 Ubuntu 中 时 使用pip3 install packageName or sudo pip3 install packageName 我收到以下错误消息 Traceback most re
  • 从数据库上传模型时丢失数据注释

    我有一个大数据库现有数据库可以与之通信 并且我首先使用 EF 5 0 数据库 我遇到的问题是 如果我创建任何数据装饰 例如 stringlength 50 在课堂上 然后上传数据库 当我 从数据库上传 时 所有数据注释都消失了 我该怎么做才
  • 如何禁用/更改 ion-nav-view 中视图之间的动画

    我开始了一个 Ionic 选项卡项目 这个项目带来了视图之间的默认动画 进入时从左到右 返回时从右到左 我想通过指定两种类型的视图动画来保留对此的控制 从下到上 没有动画 到目前为止 我尝试按如下方式禁用动画 正如建议的那样离子论坛主题 h
  • Rails:渴望加载 as_json 包括

    render json gt playlist gt playlist description songs gt playlist songs as json include gt playlist songs gt only gt id
  • 在 Qt 中检查 QObject 派生类类型的正确方法

    假设我有两门课 class A public QObject class B public QObject 那我去 QObject a new A QObject b new B 现在 我如何确保 a 是A类的实例 而 b 是B类的实例 目
  • numpy.unique 生成的列表在哪些方面是唯一的?

    如果您输入一个包含一般对象的数组numpy unique 结果将是唯一的 基于什么 我努力了 import numpy as np class A object probably exists a nice mixin for this P
  • SQL Server 优先级排序

    我有一个包含任务的表 我想根据任务的优先级对这些任务进行明确的排序 我能想到的唯一方法是通过uniqueint 列 根据优先级对任务所在位置进行索引 即 1 为前 1000 为低 问题是 假设我想更新任务并将其优先级设置为较低的值 我将必须
  • Eclipse 插件导出时出现错误:“无法解析导入 javafx.embed.swt”

    我正在尝试导出 Eclipse 插件 这只是我从此处的示例创建的一个 Eclipse 视图 http help eclipse org mars index jsp nav 2F2 0 http help eclipse org mars
  • 如何使实体框架异步执行

    我在 ASP Net MVC 5 应用程序中遇到异步控制器问题 我正在使用 Entity Framework 6 Code First 方法 我有一个方法 public async Task
  • 如何使用 NPOI 设置 Excel 中的行高?

    如何使用 NPOI 在 C 中设置行高 为了指定列的宽度 我使用 XSSFSheet SetColumnWidth 但是单元格高度的命令是什么样的 尝试下面的方法 var row sheet CreateRow 0 row Height 1
  • 有没有类似 sed 的 cmd.exe 实用程序? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我想使用 Windows 命令行以编程方式编辑文件内容 cmd exe http en wikiped
  • C++ 通用链表

    对于下面的代码 include
  • 使用 pip 在 Mac 上安装 Pandas

    我正在尝试安装Pandas with pip 但遇到了问题 详细信息如下 Mac OS Sierra which python gt usr bin python python version gt Python 2 7 10 Inside
  • OpenXml:确定 Excel 中单元格中的图像[重复]

    这个问题在这里已经有答案了 可能的重复 如何检查单元格是否有图片 https stackoverflow com questions 2320826 how to check if a cell has a picture OpenXML
  • 匹配条件时更改列值

    我需要更换一个NULL仅当其他条件匹配时列中的值 Columns Parent Child flag01 lag02 父栏目有很多NULL值 但我想替换null仅当flag01 and flag02是 好的 If flag01 and fl
  • 展平 RDD 中的 Scala 映射

    我有一个 RDD 如下所示 uidProcessedKeywords org apache spark rdd RDD Long Map String Double 如何展平 RDD 中的地图以获得以下结果 org apache spark
  • Flash AS3 - 如何访问其他帧(也称为非一帧)中的显示对象

    只要该子项位于第一帧中 getChildByName name 就会起作用 其他框架中的显示对象还没有被实例化 所以并不是说不能访问它们 它们不存在可供访问的地方 当播放头进入具有特定对象的关键帧时 会创建该对象并将其添加到舞台中 当播放头
  • Python 多线程

    我有这样的场景 使用 Zope Plone 和一些我的 python API 创建的网页 有一个网页 称之为 a 它通过 python 方法调用数据库 Postgres 并返回一些信息 在页面 a 上 您可以 离线 修改数 据库数据 我的意
  • 如何让 CBC 在时限内返回最佳解决方案? (皮莫)

    我正在尝试在 Pyomo 上使用 CBC v2 10 3 来解决整数线性问题 执行求解器时 我当前设置的时间限制为 600 秒 opt SolverFactory cbc opt options seconds 600 在这个时间限制内 求