admin管理员组

文章数量:1406951

I am running a CPLEX OPL model for 10 entities. The objective is to optimize a certain objective for each entity. Step 1: The CPLEX model first runs for the first entity, optimizing the objective function. Step 2: After solving for the first entity, a non-decision variable or parameter is updated in the main function based on the optimization results obtained. Step 3: The updated data is then used to run the CPLEX model for the second entity. Step 4: This process continues iteratively for all 10 entities, where after each iteration, the necessary variables are updated before solving for the next entity. How to do this cplex opl using main function.

I am running a CPLEX OPL model for 10 entities. The objective is to optimize a certain objective for each entity. Step 1: The CPLEX model first runs for the first entity, optimizing the objective function. Step 2: After solving for the first entity, a non-decision variable or parameter is updated in the main function based on the optimization results obtained. Step 3: The updated data is then used to run the CPLEX model for the second entity. Step 4: This process continues iteratively for all 10 entities, where after each iteration, the necessary variables are updated before solving for the next entity. How to do this cplex opl using main function.

Share Improve this question asked Mar 9 at 6:45 SUBHADARSHINI PANDASUBHADARSHINI PANDA 433 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Let me share a small example I wrote :

 main {
      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());
      } else {
         writeln("No solution");
      }
     opl.end();
    }  
     
    }

which gives

x= 1
OBJ = 1
x= 2
OBJ = 2
x= 3
OBJ = 3
x= 4
OBJ = 4
x= 5
OBJ = 5
x= 6
OBJ = 6
x= 7
OBJ = 7
x= 8
OBJ = 8
x= 9
OBJ = 9
x= 10
OBJ = 10

with subvalue.mod

float maxOfx = ...;
dvar float x;

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

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

本文标签: