0

I'm trying to solve MIP problem with IBM ILOG CPLEX Optimization studio. All the parameters have been defined. I want to save the output from the first iteration and use this output as input for the next iteration and change some data too. I have 14 iterations and the mod file is fixed in each iteration. could you help me? Regards

I expect them to answer

VLAZ
  • 26,331
  • 9
  • 49
  • 67
yalan
  • 17
  • 4

2 Answers2

0

See How to take some information from a first model and use that as input for a second model

in IBMCommunity forum

sub.mod

float maxOfx = ...;
dvar float x;
dvar float y;

maximize y;
subject to {
  ct:x<=maxOfx;
  y==2*x;
}

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

sub2.mod

float maxOfx = ...;
dvar float x;
dvar float y;

maximize y;
subject to {
  ct:x<=maxOfx;
  y==3*x;
}

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

and then the following model

main {
  var source1 = new IloOplModelSource("sub.mod");
  var cplex = new IloCplex();
  var def1 = new IloOplModelDefinition(source1);
  var opl1 = new IloOplModel(def1,cplex);
  var data1= new IloOplDataElements();
  data1.maxOfx=5;
  opl1.addDataSource(data1);
  opl1.generate();
  if (cplex.solve()) {
     writeln("OBJ = " + cplex.getObjValue());
     opl1.postProcess();

  } else {
     writeln("No solution");
  }
   var source2 = new IloOplModelSource("sub2.mod");
  var cplex = new IloCplex();
  var def2 = new IloOplModelDefinition(source2);
  var opl2 = new IloOplModel(def2,cplex);
  var data2= new IloOplDataElements();
  data2.maxOfx=opl1.y.solutionValue; // transfer solution of model1 to input for model2
  opl2.addDataSource(data2);
  opl2.generate();

  if (cplex.solve()) {
     opl2.postProcess();
  } else {
     writeln("No solution");
  }

  opl1.end();
  opl2.end();
 
} 

gives

x= 5
y= 10
x= 10
y= 30

sub.mod multiplies 5 by 2 and gives 10 which is the input for sub2.mod that will multiply 10 by 3

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thanks for answering, but I have some boolean variables and I have to freeze this variable for the next iteration, add the next passenger, run again, and take another solution. how can I freeze some variables for the next iteration?? – yalan Nov 15 '22 at 05:59
  • For freezing see fixed Start https://github.com/AlexFleischerParis/zooopl/blob/master/zoofixedstart.mod – Alex Fleischer Nov 15 '22 at 06:40
0

Thank you for your reply, Alex.

but Let me ask my question more precisely.. I have this data string

{string} N = {"a", "b", "c", "d", "e", "f", "g"};

and I have to get one of the arrays from N in each iteration in cplex loop, for example, in iter 1 I have to get N = {"a"} and for the next step I have to get N = {"a", "b"} and I must continue in the same way; The rest of the data is constant in all iteration. And in each iteration, I have to save the solution of this iteration for the next step.

my data:

{string} N = {"a", "b", "c", "d", "e", "f", "g"};

{string} M = {"aa","bb","cc","dd","ee"};

range nods = 0..10;

tuple edge{

int o;

int d;

float C;

float D;

};

{edge} edges = ...;

int Tr = ...;

int cd = ...; . . .

my variables:

dvar boolean x[M][N];

dvar boolean y[M,edges];

dvar boolean w[M,N,edges];

dvar float+ T[M][nods];

I apologize for the frequent and long questions.

yalan
  • 17
  • 4