Optimal use of CPLEX Java for high-throughput
Asked Answered
D

1

5

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.

Delftware answered 13/4, 2012 at 3:27 Comment(1)
You'll probably get better responses from the IBM discussion forums or from OR-Exchange, a sister site to Stack Overflow.Meningitis
D
7

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
Doubloon answered 13/4, 2012 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.