我正在用CPLEX Java API解决大型优化问题。目前我只是
IloCplex cplex = new IloCplex();
... add lots of variables and constraints ...
cplex.solve();
cplex.end();这很有效,但我经常重复这个过程,我只是在改变系数。每重复一次,我就创建一个新的cplex对象并重新创建所有变量。
有没有更有效的方法来做到这一点?IBM文档中有类似于“将模型添加到模型的实例中”的语言,这听起来很奇怪,但我认为它是在暗示能够重用某些东西。
更有经验的用户的任何建议都是很棒的。谢谢。
发布于 2012-04-13 13:06:57
如果只想更改约束的系数(或目标函数的系数),则可以修改现有IloCplex对象上的系数。你不应该从头开始创建模型。
retval = cplex.solve();
// verify that the solve was successful
// change coeficients on constraints (or in the objective)
cplex.setLinearCoef(constraint, newCoef, variable);
cplex.setLinearCoef(objective, newObjCoef, variable);
// change right bounds on constraints
constraint.setBounds(newLB, newUB);
// change variable bounds
var.setBounds(newLB, newUB);
retval = cplex.solve();
// verify the solvehttps://stackoverflow.com/questions/10134846
复制相似问题