IBM ILOG CPLEX Optimization Studio 中的问题浏览器

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

我有一个带有流程控制的 main() 模块,并使用“new IloOplModel()”显式创建模型实例。在 IBM ILOG CPLEX Optimization Studio (12.7) 中运行该程序,结果未显示在“问题浏览器”中。有没有办法让 IDE 在问题浏览器中显示某个模型实例的结果?

在切换到显式创建模型实例之前,我依赖于隐式模型实例(可通过 thisOplModel 获得)。使用隐式模型实例,结果始终显示在“问题浏览器”中。

感谢您的帮助!

cplex opl
1个回答
0
投票

这很正常。

所以你可以做的是

依靠脚本来显示您需要的内容:

https://github.com/AlexFleischerParis/zooopl/blob/master/zooprepostprocessing.mod

int nbKids=300;
float costBus40=500;
float costBus30=400;

// Preprocessing

execute DISPLAY_BEFORE_SOLVE
{
writeln("The challenge is to bring ",nbKids," kids to the zoo.");
writeln("We can use 40 and 30 seats buses and the costs are ",costBus40," and ",costBus30);
writeln("So average cost per kid are ",costBus40/40, " and ",costBus30/30);
}

// Decision variables , the unknown

dvar int+ nbBus40;
dvar int+ nbBus30;

// Objective
 
minimize
 costBus40*nbBus40  +nbBus30*costBus30;
 
// Constraints
 
subject to
{
 40*nbBus40+nbBus30*30>=nbKids;
}

// Postprocessing

execute DISPLAY_After_SOLVE
{
writeln("The minimum cost is ",costBus40*nbBus40  +nbBus30*costBus30);
writeln("We will use ",nbBus40," 40 seats buses and ",nbBus30," 30 seats buses ");
}

或在文件中写入 .dat ,以便您可以在没有主块的情况下使用带有 .mod 和 .dat 的问题浏览器

示例:

子值.mod

float maxOfx = ...;
dvar float x;

maximize x;
subject to {
  x<=maxOfx;
}

execute
{
writeln("x= ",x);
}

然后

主要{

  var source = new IloOplModelSource("subvalue.mod");
  var cplex = new IloCplex();
  var def = new IloOplModelDefinition(source);
 
 
 
  for(var k=1;k<=10;k++)
  {;
  var opl = new IloOplModel(def,cplex);
    
  var data2= new IloOplDataElements();
  data2.maxOfx=k;
  opl.addDataSource(data2);
  opl.generate();

  if (cplex.solve()) {  
     opl.postProcess();
     writeln("OBJ = " + cplex.getObjValue());
     writeln(".dat");
     writeln(opl.printExternalData());
    
  } else {
     writeln("No solution");
  }
 opl.end();
}  


}

这给了

x= 1
OBJ = 1
.dat
maxOfx = 1;

x= 2
OBJ = 2
.dat
maxOfx = 2;

x= 3
OBJ = 3
.dat
maxOfx = 3;

x= 4
OBJ = 4
.dat
maxOfx = 4;

x= 5
OBJ = 5
.dat
maxOfx = 5;

x= 6
OBJ = 6
.dat
maxOfx = 6;

x= 7
OBJ = 7
.dat
maxOfx = 7;

x= 8
OBJ = 8
.dat
maxOfx = 8;

x= 9
OBJ = 9
.dat
maxOfx = 9;

x= 10
OBJ = 10
.dat
maxOfx = 10;
© www.soinside.com 2019 - 2024. All rights reserved.