问题描述
我目前正在尝试解决Benders分离问题。我使用已安装文件中现有示例中的示例。我不明白的是如何或在哪里显示决策变量的解决方案。我正在使用以下代码。我的问题是关于最后一部分的,我希望程序显示三个决策变量的解:x [] [] []是float +,y [] []是二进制,theta []是二进制。在其他方法中,我还发现getobjCoef()是使用printSolution的正确决定吗?使用getobjCoef方法时,我该如何制定?
我将不胜感激。 问候
main{
thisOplModel.generate();
var masterDef = thisOplModel.modelDeFinition;
var masterCplex =cplex;
var masterData= thisOplModel.dataElements;
var subCplex = new IloCplex ();
var subOpl = new IloOplModel(masterDef,subCplex);
subOpl.addDataSource(masterData);
subOpl.generate();
subCplex.bendeRSStrategy = 1;
subCplex.newLongAnnotation("cpxBendersPartition");
for (var s in thisOplModel.other_scenarios){
for (var d in thisOplModel.demands){
for (var a in thisOplModel.arcs){
subCplex.setLongAnnotation("cpxBendersPartition",subOpl.x[s][d][a],subOpl.bendersPartitions[s]);
}
}
}
**if (subCplex.solve()) {
writeln("Total Cost = " + subCplex.getobjValue());
writeln("solution:" + subOpl.printSolution());
} else {
writeln("No solution");}**
cplex.exportModel("bendersv2.lp");
subCplex.writeBendersAnnotation("bendersv2.ann");
subCplex.delLongAnnotation("cpxBendersPartition");
subOpl.end();//clean up of memory
subCplex.end();//clean up of memory
}
解决方法
printSolution将为您提供完整的解决方案,但是在编写脚本时,您也可以简单地编写
writeln(x);
将显示x
例如https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/
int nbKids=300;
float costBus40=500;
float costBus30=400;
dvar int+ nbBus40;
dvar int+ nbBus30;
minimize
costBus40*nbBus40 +nbBus30*costBus30;
subject to
{
40*nbBus40+nbBus30*30>=nbKids;
}
main
{
thisOplModel.generate();
cplex.solve();
writeln(thisOplModel.printSolution());
writeln(thisOplModel.nbBus40);
}
给予
nbBus40 = 6;
nbBus30 = 2;
6