Modeling constraints

Shows how to define modeling constraints in OPL.

Constraints passed to the algorithm, and which as such define the optimization problem, usually apply to decision variables; that is, they are Boolean expressions of some decision variables. To be taken into account by the solving algorithm, constraints must be stated using the optimization instruction:



subject to

as shown in the following example.

Stating constraints by means of an optimization instruction

   sum(p in Products) (insideCost[p]*inside[p] + outsideCost[p]*outside[p]);
subject to { 
   forall(r in Resources) 
      sum(p in Products) consumption[p,r] * inside[p] <= capacity[r]; 
   forall(p in Products) 
      inside[p] + outside[p] >= demand[p]; 
  1. Optimization instructions require an objective function of type integer or float.

  2. That objective function must be defined before the constraints. Otherwise, a warning message is displayed.