CPLEX C++ 将列添加到 IloModel 的深层副本

问题描述 投票:0回答:1

我使用用户 m6rco 的代码创建了

IloModel
的深层副本。

IloEnv testenv;
IloModel testmodel(testenv);
IloCplex testcplex(testmodel);

IloNumVarArray x = CreateNumVarArray(testenv, 2, "x", 0, 1);
IloObjective testobj = IloMaximize(testenv, IloSum(x));
testmodel.add(testobj);
IloRangeArray cnstr = CreateRangeArray(testenv, 3, "c");
for (int i = 0; i < cnstr.getSize(); i++) {
    cnstr[i].setLinearCoef(x[0], (3 - i) + 2);
    cnstr[i].setLinearCoef(x[1], i * 3 + 1);
    cnstr[i].setUB(10 * (5 - i) - 2);
}
testmodel.add(cnstr);
IloModel testmodel1(testenv);
for (IloModel::Iterator it(testmodel); it.ok(); ++it)
    testmodel1.add(*it);

我的问题是如何向

testmodel1
添加新列。对于
testmodel
我将使用以下代码。我不知道要申请什么
testmodel1

IloNumColumn col(testenv);
col += testobj(22);
for (int i = 0; i < cnstr.getSize(); ++i) {
    col += cnstr[i](i * 3 + 5);
}
x.add(IloNumVar(col, 0, 1, ILOFLOAT));
c++ cplex
1个回答
0
投票

我想向 testmodel1 添加新列而不更改 testmodel。显然我可以通过创建一个新的 IloNumVar 并将其添加到 testmodel1 来做到这一点。

IloNumVar newVar(col, 0, 1, ILOFLOAT);
testmodel1.add(newVar);
© www.soinside.com 2019 - 2024. All rights reserved.