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.

David Nehme
  • 21,379
  • 8
  • 78
  • 117
Noah Watkins
  • 5,446
  • 3
  • 34
  • 47
  • 2
    You'll probably get better responses from the IBM discussion forums or from OR-Exchange, a sister site to Stack Overflow. – Greg Glockner Apr 13 '12 at 03:39

1 Answers1

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
Halil Sen
  • 259
  • 2
  • 11
David Nehme
  • 21,379
  • 8
  • 78
  • 117