问题标签 [glpk]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1601 浏览

binary - 在 GLPK 中添加二进制变量

我在 Linux 下使用 GLPK 来解决一些线性规划问题。在我的限制之一中,我有:

哪里binary_val是定义为“二进制”的变量。

如果binary_val取值1,它的总和是2,还是二进制,它会返回0还是1

0 投票
1 回答
856 浏览

cplex - 在 MathProg 中设置解中的初始值

我正在使用 MathProg 语言和 GLPK 来解决 MIP 问题。如果我有一个“好的”启发式整数解决方案,有没有办法在 MathProg 语言中设置初始解决方案(并由 GLPK 解决)?这是 CPLEX 中的一个很棒的功能,可以大大加快求解 MIP 的速度。谢谢!

0 投票
1 回答
2836 浏览

ampl - MathProg (GLPK) 中的“域外”错误

我正在为 MathProg 中一个看似简单的模型而苦苦挣扎。模型如下:

当我运行它时,它给了我错误feasibility.glp:11: b[v1,w1] out of domain。我不知道出了什么问题。对我来说更奇怪的是,如果我将相关行更改为b[j,i]它会一直给出完全相同的错误(不像b[w1,v1]我预期的那样)。

我仔细检查了AMPL 饮食示例,尽管我发现模型的相关部分没有任何差异,但它仍然不起作用。怎么了?

0 投票
1 回答
698 浏览

c++ - GLPK API 中“glpsol”的等价物

我想知道命令行函数“glpsol”的 GLPK Api 中是否有等效项。

因为我有一个模型,它写在 .mod 文件中,数据写在 .dat 文件中。在命令行中,我可以通过调用此行来解决它:

我想在不执行“execv()”调用的情况下解决 C/C++ 程序中的相同问题。

0 投票
1 回答
1965 浏览

python - GLPK linear programming

I am working on some very large scale linear programming problems. (Matrices are currently roughly 1000x1000 and these are the 'mini' ones.)

I thought that I had the program running successfully, only I have realized that I am getting some very unintuitive answers. For example, let's say I were to maximize x+y+z subject to a set of constraints x+y<10 and y+z <5. I run this and get an optimal solution. Then, I run the same equation but with different constraints: x+y<20 and y+z<5. Yet in the second iteration, my maximization decreases!

I have painstakingly gone through and assured myself that the constraints are loading correctly.

Does anyone know what the problem might be?

I found something in the documentation about lpx_check_kkt which seems to tell you when your solution is likely to be correct or high confidence (or low confidence for that matter), but I don't know how to use it.

I made an attempt and got the error message lpx_check_kkt not defined.

I am adding some code as an addendum in hopes that someone can find an error. The result of this is that it claims an optimal solution has been found. And yet every time I raise an upper bound, it gets less optimal.
I have confirmed that my bounds are going up and not down.

0 投票
1 回答
19636 浏览

linear-programming - 如何在 GLPK 中为我的变量编写 if 条件?

这是我的全部问题:

在此处输入图像描述

信息:

*最大限度。总投资:125美元

*支付是购买单位的总和 x 支付/单位

*每次投资成本:购买成本 + 成本/单位 x 单位数量(如果您购买至少一个单位)

*成本为每次投资成本的总和

约束:

*您不能同时投资 2 和 5。

*仅当您至少投资 2 和 3 之一时,您才可以投资 1。

*您必须至少投资 3,4,5 中的两个。

*您的投资不得超过最大单位数。

问题:最大化利润:回报 - 成本

这是我的问题:

例如我有这个二进制变量 y

我将 i 声明为数据集

我不知道如何将 if else 条件添加到 glpk 中的 y 变量。你能帮帮我吗?

我的建模:

我收到此语法错误:

0 投票
2 回答
2185 浏览

model - 使用 Glpk 进行线性规划建模时的语法错误

这是我的全部问题:

在此处输入图像描述

信息:

*最大限度。总投资:125美元

*支付是购买单位的总和 x 支付/单位

*每次投资成本:购买成本 + 成本/单位 x 单位数量(如果您购买至少一个单位)

*成本为每次投资成本的总和

约束:

*您不能同时投资 2 和 5。

*仅当您至少投资 2 和 3 之一时,您才可以投资 1。

*您必须至少投资 3,4,5 中的两个。

*您的投资不得超过最大单位数。

问题:最大化利润:回报 - 成本

我的建模:

我收到此语法错误:

你能帮帮我吗?

0 投票
1 回答
1719 浏览

glpk - GLPK 在约束中使用变量

我正在尝试编写约束,但出现此错误:

这是代码:

错误是针对“C4”约束的。我的问题是在“c4”中如何在其条件下使用变量?我该如何解决这个错误?

0 投票
2 回答
456 浏览

python - 未知类型名称“glp_long”(mac osx python,pyglpk)

我正在尝试安装 pyglpk-0.3 以将其与 cobrapie(matlab cobra 工具箱的 python 版本)一起使用。每次我开始安装时,都会出现以下错误:(其中的一部分)

这是提到的c文件的一部分:

我错过了要安装的东西吗?我使用 Python 2.7.5 |Anaconda 1.6.1 (x86_64)| 和 glpk @4.48_0(活动)与 osx 10.8.4

0 投票
1 回答
658 浏览

linear-programming - glpsol 工具拆分 MIP 和 LP 解决方案

我正在使用 glpsol 来解决一个相当大的整数优化问题。Simplex 算法在其上运行大约 30 分钟,然后glpsol尝试使用 MIP 求解器找到整数解。

问题:我可以仅使用 glpsol 命令工具将其分为两个步骤,还是应该使用 glpk API?

我已经尝试过根据文档的“读取”和“nomip”选项

从提供的文件名中读取解决方案,而不是使用求解器找到它

这种格式:

在那之后

但我收到一个错误:

这当然是正确的,因为 WhiskasModel.mip 是具有非整数值的 LP 解决方案。

我发现它glpsol toolkit相当强大,我想玩一些 MIP 选项,但每一步等待 30 分钟是相当无聊的。我可以告诉它,“使用这个 LP 解决方案并启动 MIP”吗?