- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试解决在 https://en.wikipedia.org/wiki/Integer_programming#Example 中找到的简单示例在 Python 2.7 上使用 CVXOPT 库;最佳答案是 (1,2) 或 (2,2)。我得到(0.0,0.0)。我在下面的代码中做错了什么?谢谢!
import numpy as np
import cvxopt
from cvxopt import glpk
c=cvxopt.matrix([0,-1]) #-1 since we're maximising the 2nd variable
G=cvxopt.matrix([[-1,1],[3,2],[2,3],[-1,0],[0,-1]],tc='d')
h=cvxopt.matrix([1,12,12,0,0],tc='d')
(status, x)=glpk.ilp(c,G.T,h,B=set([0,1]))
print status
print x[0],x[1] #should be (1,2) or (2,2)
print sum(c.T*x)
最佳答案
您的代码基本正确,但需要进行两处小修改:
然后,给出了一个可行的解决方案:
import numpy as np
import cvxopt
c=cvxopt.matrix([0,-1],tc='d')
G=cvxopt.matrix([[-1,1],[3,2],[2,3],[-1,0],[0,-1]],tc='d')
h=cvxopt.matrix([1,12,12,0,0],tc='d')
(status, x)=cvxopt.glpk.ilp(c,G.T,h,I=set([0,1]))
print status
print x[0],x[1]
print sum(c.T*x)
关于python-2.7 - Python - CVXOPT 中的整数线性规划 (ILP) 函数未生成正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33785396/
我有一个来自关系数据库的庞大数据集,我需要为其创建分类模型。通常对于这种情况我会使用 ILP 但由于特殊情况我不能这样做。 解决这个问题的另一种方法是在我有对外关系时尝试汇总值,但是我有数千个重要且不
integer linear programming 的运行时复杂度是多少? (ILP) 问题,当有N 个变量和R 个约束条件时?出于编码目的,我使用 Matlab 的 intlinprog功能。任何
我正在学习算法,最近发现了一个有趣的挑战。 它会给我们一些行/列,我们的任务是用只显示一次的整数 1~N 填充表格,并且它们的行和列之和等于给定的行/列。 挑战简单示例: [ ] [ ]
Java 或一些类似语言中的并发性是通过线程或任务级并行性来实现的。但在幕后,硬件或运行时也使用 ILP 来实现最佳性能。 进一步阐述:在具有多个线程(例如每个核心 2 个)(即每个系统总共 8 个线
我有一个整数线性规划问题,我尝试过的求解器(CPLEX、CBC)需要很长时间才能解决,即使它们很早就找到了最优解。他们只是需要很长时间才能完全证明这一点。 很容易为我的最小化问题的目标值计算一个微不足
我观察到 IPC 下降,因为 ILP 在尝试加速我的加密内核时针对 32-bit int 操作上升。内核由 ADD 和 XOR 操作的长序列相当展开的循环组成,每个 192 的吞吐量应为 160 op
NVIDIA GPU 是否支持乱序执行? 我的第一个猜测是它们不包含如此昂贵的硬件。但是,在阅读 CUDA progamming guide 时,该指南建议使用指令级并行 (ILP) 来提高性能。 I
我有一个 ILP 问题,我在其中表达了实现 A OR B 的一些约束,其中 A 和 B 是逻辑与的结果(假设 A = A1 AND A2,B = B1 AND B2 AND B3)。在我的问题的这一点
我正在开发一个用于优化问题的 Java 框架。到目前为止,我已经实现了lp_solve和 GLPK因此我可以处理线性问题(LP)和整数线性问题(ILP)。现在我想提供使用进化算法作为求解器的可能性,以
我有一个混合整数规划问题(使用列生成来削减库存),我已经在 AMPL 中解决了这个问题,并且我使用 cvxopt 移植到了 Python。 CVXOPT“op”没有提供我需要的二进制变量选项,所以我用
我想使用 Microsoft Solver Foundation 解决 C# 中的二进制线性问题。我不知道为什么我得到错误的答案。目标值应该是 41.1,但我得到了 213。5 个变量的值应该是 1,
我正在使用 Java 中的 ILOG CPLEX 库来解决 ILP 问题。我使用的是默认设置,没有调整任何参数。我使用了我在主循环示例中在线找到的示例代码: if (cplex.solve()) {
众所周知,CPU 是流水线,如果命令序列彼此独立,它的工作效率最高 - 这称为 ILP(指令级并行):http://en.wikipedia.org/wiki/Instruction-level_pa
我正在尝试解决在 https://en.wikipedia.org/wiki/Integer_programming#Example 中找到的简单示例在 Python 2.7 上使用 CVXOPT 库
我之前完成了一个 ILP,它工作正常。 opt = SolverFactory('glpk') model = AbstractModel() model.obj = Objective(...) #
我是一名优秀的程序员,十分优秀!