0

I am currently learning to use flow control in CPLEX. I wonder if I want to change the change interval for capflour to 100 at each time in the following case, how can I do that?

Thanks!

enter image description here

Blockquote

main {
 thisOplModel.generate();
var produce = thisOplModel;
 var capFlour = produce.Capacity["flour"];
 var best;
 var curr = Infinity;
 var ofile = new IloOplOutputFile("mulprod_main.txt");
 while ( 1 ) {
 best = curr;
 writeln("Solve with capFlour = ",capFlour);
 if ( cplex.solve() ) {
 curr = cplex.getObjValue();
 writeln();
 writeln("OBJECTIVE: ",curr);
 ofile.writeln("Objective with capFlour = ", capFlour, " is ", curr);
 } else {
 writeln("No solution!");
 break;
 }
 if ( best==curr ) break;
 **capFlour++;**
 for(var t in thisOplModel.Periods)
 thisOplModel.ctCapacity["flour"][t].UB = capFlour;
 }
if (best != Infinity) {
 writeln("plan = ",produce.Plan);
 }
 ofile.close();
}
Solving
iteratively
using while
loop
Modifying the upper bound (flour capacity)

Blockquote Blockquote

1 Answers1

0

Let me share an example from Making Decision Optimization Simple

incremental flow control

    int nbKids=300;
    float costBus40=500;
    float costBus30=400;
     
    dvar int+ nbBus40;
    dvar int+ nbBus30;
     
    minimize
     costBus40*nbBus40  +nbBus30*costBus30;
     
    subject to
    {
     ctKids:40*nbBus40+nbBus30*30>=nbKids;
    }

    execute
    {
    writeln("nbBus40 = ",nbBus40);
    writeln("nbBus30 = ",nbBus30);
    }

    main
    {
    thisOplModel.generate();

    cplex.solve();
    thisOplModel.postProcess();

    //now 350 kids instead of 300
    writeln("now 350 kids instead of 300");
        
    thisOplModel.ctKids.LB=350;

    cplex.solve();
    thisOplModel.postProcess();


    // no more than 4 buses 40 seats
    writeln("no more than 4 buses 40 seats");

    thisOplModel.nbBus40.UB=4;

    cplex.solve();
    thisOplModel.postProcess();

    // change the objective so that cost for 40 seats is 450
    // and remove the limit on the number of buses 40 seats

    writeln("change the objective so that cost for 40 seats is 450");
    writeln("and remove the limit on the number of buses 40 seats");    

    thisOplModel.nbBus40.UB=1000;
    cplex.setObjCoef(thisOplModel.nbBus40,450);
    cplex.setObjCoef(thisOplModel.nbBus30,400);

    cplex.solve();
    thisOplModel.postProcess();

     


    }


which gives
 
    nbBus40 = 6
    nbBus30 = 2
    now 350 kids instead of 300
    nbBus40 = 8
    nbBus30 = 1
    no more than 4 buses 40 seats
    nbBus40 = 2
    nbBus30 = 9
    change the objective so that cost for 40 seats is 450
    and remove the limit on the number of buses 40 seats
    nbBus40 = 8
    nbBus30 = 1
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15