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:
The full code extract is shown here.
Labeling constraints with indexed labels
constraint ctSupply[Products][Cities];
constraint ctDemand[Products][Cities];
minimize
sum(l in Routes) Cost[l] * Trans[l];
subject to {
forall( p in Products , o in Orig[p] )
ctSupply[p][o]:
sum( d in Dest[p] )
Trans[< p,o,d >] == Supply[<p,o>];
forall( p in Products , d in Dest[p] )
ctDemand[p][d]:
sum( o in Orig[p] )
Trans[< p,o,d >] == Demand[<p,d>];