Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimal use of CPLEX Java for high-throughput

I am solving large optimization problems with CPLEX Java API. Currently I just

IloCplex cplex = new IloCplex();
... add lots of variables and constraints ...
cplex.solve();
cplex.end();

This works great, but I repeat the process frequently where I am just changing co-efficients. Each time I repeat I create a new cplex object and re-create all the variables.

Is there a more efficient way to do this? The IBM documentation has language like 'adding the model to the instance of the model', which sounds weird, but I thought it was hinting at being able to re-use things.

Any suggestions from more experienced users would be great. Thanks.

like image 805
Noah Watkins Avatar asked Apr 13 '12 03:04

Noah Watkins


1 Answers

If you just want to change coefficients of constraints (or those of the objective function), you can modify the coefficients on the existing IloCplex object. You shouldn't create a model from scratch.

retval = cplex.solve();
// verify that the solve was successful

// change coeficients on constraints (or in the objective)
cplex.setLinearCoef(constraint, newCoef, variable);
cplex.setLinearCoef(objective, newObjCoef, variable);

// change right bounds on constraints
constraint.setBounds(newLB, newUB);

// change variable bounds
var.setBounds(newLB, newUB);

retval = cplex.solve();
// verify the solve
like image 53
David Nehme Avatar answered Sep 20 '22 04:09

David Nehme