Using indexed labels

Shows how to use indexed labels for your OPL constraints.

In some cases, it is more convenient to use indexed labels. Indexed labels enable you to control how a constraint is assigned to an array item.

The following example, Labeling constraints with indexed labels shows that the transp2.mod model identifies constraints using indexed labels following this syntax:

constraint ctDemand[Products];
...
ctDemand[p]:...

Indexed labels on constraints (transp2.mod)

  forall( p in Products , d in Dest[p] )
    ctDemand[p][d]:  
      sum( o in Orig[p] ) 
        Trans[< p,o,d >] == Demand[<p,d>];
  ctCapacity:  forall( o , d in Cities )
                 sum( <p,o,d> in Routes ) 
                   Trans[<p,o,d>] <= Capacity;

A case where you need indexed labels to reduce memory overhead is when you use forall iterations with variable sizes, as shown in the following code.

forall iterations with variable sizes

  forall( p in Products , o in Orig[p] ) 

In this forall example, the second formal parameter o iterates on sets of potentially different sizes, depending on the value of the formal parameter p.

To use indexed labels:

  1. Declare the constraint array that will receive the labeled constraints.
    constraint ctSupply[Products][Cities];
    
  2. Add the indexing expressions to the label.
    
    ctSupply[p][o]: