User Tools

Site Tools


Using lazy constraints or user cuts

GAMS/CPLEX does currently not support lazy constraint or user cuts. We have not seen convincing examples where these Cplex features make a significant difference in performance. We understand that this might be a chicken and egg problem, therefore we introduced some time ago a way to experiment with these Cplex features. This is not for production models but to see if these features improve performance for your model.

If you (or other users) have good examples where lazy constraints or user cuts make a significant difference that cannot be accomplished by other Cplex features, we will quickly make these features available in GAMS/CPLEX.

Here is what you need to do:

  1. Enter the user cuts and or lazy constraints as normal equations to your model. Order the equations in a way that the lazy constraints and user curs are last in your model (instead of model m /all/ you can list the names and get the appropriate order of your equations).
  2. Solve your model with a cplex.opt option file containing: writelp mymodel.lp. You can interrupt the run when Cplex starts the presolve.
  3. Edit the file mymodel.lp. Just in front of the constraints that should be treated as lazy constraints add a line with Lazy Constraints. Before the constraints that should be used as user cuts, add a line with User Cuts.
  4. Rerun the GAMS model with the solve statement, but change cplex.opt to probread mymodel.lp. This instructs GAMS/CPLEX not to get the model from GAMS but read the model from the file mymodel.lp. If you have lazy constraint you need to turn off dual reductions by adding option reduce 1. If you have user cuts only you need to turn off non-linear reductions by adding prelinear 0. If you have both, reduce 1 will suffice. Since the model passed from GAMS to GAMS/CPLEX might have nothing to do with the model you supplied in mymodel.lp, no solution is returned to GAMS, so you can't do much with that other than experimenting with the performance improvements of the Cplex features Lazy Constraints and User Cuts.

We took the rotdk model from the GAMS model library and automated these steps using awk to add the the line lazy constraints to the LP file.

$title Robust Optimization (ROTDK,SEQ=185)

Robust Optimization

Laguna, M, Applying Robust Optimization to Capacity Expansion of
One Location in Telecommunications with Demand Uncertainty.
Management Science 44, 11 (1998), 101-110.


SETS s scenarios / 1*1000/
     t time periods / t1*t12 /
     j components / C001*C010 /


     di(s,t) increment
     D(t,s)  demand
     c(j)    capacity size
     p(j)    capacity cost
     mu      mean capacity parameter
     sigma   std capacity parameter;

mu = 100; sigma = 10;

c(j) = round(uniform(1,mu));
p(j) = round(mu + c(j) + uniform(-sigma,sigma));

di(s,t)$(ord(s) <= 0.25*card(s)) = round(normal( 50,10));
di(s,t)$(ord(s)  > 0.25*card(s) and ord(s) <= 0.75*card(s)) = round(normal(100,20));
di(s,t)$(ord(s)  > 0.75*card(s)) = round(normal(150,40));

d(t,s) = sum(tt$(ord(tt) <= ord(t)), di(s,tt));
*display c,p,di,d;

parameters dis(t) discount factor
           w      shortage penalty;

dis(t) = power(.86,ord(t)-1);
w      = 5;

variables x(j,t) expansion
          z(s) max capacity shortage
          cap(t) installed capacity

integer variable x; positive variable z;

equations capbal(t)   capacity balance
          dembal(t,s) demand balance

objdef.. obj =e= sum((j,t), dis(t)*p(j)*x(j,t))
               + w/card(s)*sum(s, z(s));

capbal(t).. cap(t) =e= cap(t-1) + sum(j, c(j)*x(j,t));

dembal(t,s).. cap(t) + z(s) =g= d(t,s);

*model rotdk / all /;
* We want dembal as lazy constraints, so let's order the constraints so dembal is last
model rotdk / objdef, capbal, dembal /;

$echo writelp rotdk.lp > cplex.opt
$onecho > cplex.op2
probread rotdkLC.lp
reduce 1

option optcr=0.0,limcol=0,limrow=0;

scalar DefaultResUsed, LazyConstraintsResUsed;
rotdk.optfile=1; solve rotdk min obj us mip; DefaultResUsed = rotdk.resusd;

* Insert the line 'Lazy Constraints' into rotdk.lp before the first occurance of dembal
$onecho > x.awk
!m && /dembal/ { print "Lazy Constraints"; m=1; } 
               { print $0 }
execute 'awk -f x.awk rotdk.lp > rotdkLC.lp';

* Solve the model defined by the Cplex LP file rotdkLC.lp. 
* The model passed to Cplex in the solve line below is irrelavant to the actual solve.
* We demonstrate this by chaing the model type to rmip and maximize instead of minimize.
rotdk.optfile=2; solve rotdk max obj us rmip; LazyConstraintsResUsed = rotdk.resusd;

display DefaultResUsed, LazyConstraintsResUsed;
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY solver/using_lazy_constraints_or_user_cuts.txt · Last modified: 2010/03/09 13:36 by support