10.1 Set Membership with the IN Operator

The IN operator in MPL allows you to select one of the domain indexes from a multidimensional index. For example, if you have a multidimensional index that specifies which machines are available in which plants, you can use the IN operator to sum over all the machines in each plant.

INDEX
   plant      := (Atlanta, Chicago, Dallas);
   machine    := (Grind, Drill, Press);
   product    := (p1,p2,p3,p4);

   PlantMach[plant,machine] :=

              := (Atlanta.Grind, Atlanta.Press,
                  Chicago.Drill, Chicago.Press,
                  Dallas.Grind);
      .
SUBJECT TO
   PlantCapacity[plant] :

      SUM(machine IN PlantMach: Prod[machine]) < MaxCapacity[plant];

In the above example, we sum together how much is produced with each machine and then make sure that the total production is limited to the maximum capacity at each plant.

We can also use the IN operator to join together two multi-dimensional indexes. For example, say that you also have an index that defines which products are produced by which machine. You can then use the IN operator, in conjunction with the WHERE command, to create a new index that contains which products can be produced in which plants.

INDEX
   MachProd[machine,product] :=
              := (Grind.p1, Grind.p4,
                  Drill.p2, Drill.p3, Drill.p4,
                  Press.p1, Press.p3);

   PlantProduct[plant,product] WHERE

      FORSOME(machine: machine IN PlantMach = machine IN MachProd);

!              := (Atlanta.p1, Atlanta.p3, Atlanta.p4,
!                  Chicago.p1, Chicago.p2, Chicago.p3, Chicago.p4,
!                  Dallas.p1,  Dallas.p4);

In the example on the previous page, we join the plants and the products together through the machine index. This is done by MPL going through each plant.machine pair in the PlantMach index and matching the machine to the machine.product pair in the MachProd index. This will give us a new index PlantProduct which contains, for each plant, the products that can be produced at that plant. If you are familiar with relational databases and view the indexes in MPL as columns, then you will notice that this operation is the same as the natural join operation in databases.

When formulating the model with a lot of sparsity, you can use the IN operator to let MPL quickly skip index elements that are not needed. For example, say you want to define a produce variable for each plant, machine, and product, but you only want to include those variables that are members of the two parent indexes PlantMach and MachProd. This can be accomplished in MPL by using the IN operator when you are listing the domain indexes for the variable. For example:

    DECISION VARIABLES
       Produce[plant, machine IN PlantMach, product IN MachProd];

MPL will now include a machine index element only in theProduce variable if the plant.machine pair is in the PlantMach index and then a product index element only if the machine.product index is in the MachProd index. This will result in the total number of variables defined to be much smaller and speed up the parsing time for the rest of the model considerably, especially for large, sparse models.


Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page