gpt4 book ai didi

按列公式 CPLEX - 在列中添加新的约束集

转载 作者:太空宇宙 更新时间:2023-11-04 03:54:22 25 4
gpt4 key购买 nike

我使用 C/C++ 的可调用库来编写一组分区公式。我使用类似柱状的公式。我有两组约束。

每当我添加列时,我都会使用:

for (i = 1; i <= colIdx ; i++) {   //For all columns
...
status = CPXaddcols(env, lp, 1, colNum, obj, cmatbeg, cmatind , cmatval,
lb, ub, NULL);}

但是; colNum、cmatind 和constraint sense 对于这两个约束集是不同的。如果我将另一个 CPXaddcols 用于第二个约束集,它会添加新变量,但我只想在给定列中添加新行。

我该如何解决这个问题?

最佳答案

是的,您可以通过调用 CPXaddcols 向您的 CPLEX 问题添加多行(约束)。

只需确保在调用 CPXcreateprob 之后和调用上面的 CPXaddcols 之前,您已经调用了适当数量的 CPXnewrows 以通知 CPLEX 这些约束不为零。

如 CPLEX 帮助所述 here

CPXaddcols cannot add coefficients in rows that do not already exist (that is, in rows with index greater than the number returned by CPXgetnumrows); 
[...]
The routine CPXnewrows can be used to add empty rows before adding new columns via CPXaddcols.

此外,只需确保当您添加变量时 colNum 实际上指的是您将要添加到新列中的非零值的数量。

This example有这样的实例,其中每次调用 CPXaddcols 都会将变量添加到两个约束。

具体仔细看这部分代码:

    /* Add flow variables */

for (j = 0; j < NUMEDGES; j++) {
ind[0] = orig[j]; /* Flow leaves origin */
val[0] = -1.0;
ind[1] = dest[j]; /* Flow arrives at destination */
val[1] = 1.0;

name[0] = buffer;
sprintf(buffer, "x%d%d", orig[j], dest[j]);

status = CPXaddcols (env, lp, 1, 2, &unitcost[j], &zero, ind, val,
NULL, NULL, name);

希望对您有所帮助。

关于按列公式 CPLEX - 在列中添加新的约束集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18082180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com