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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With