In this second exercise we are going to explore the cost of a given production plan. Suppose we want to manufacture 7 different products. We have 4 identical factories where 5 different machines are installed. 20 different raw products are used to assemble a product. Hence, we have a set of products P = {A,B,C,D,E,F,G}, a set of factories F = {F1,F2,F3,F4}, a set of machines M = {M1,M2,M3,M4,M5}, and a set of raw materials R = {1…20}. Additionally, various tables are given with p ∈ P, f ∈ F, m ∈ M, r ∈ R: A table q_{p,m} defines which product can be manufactured on which machine. The table R_{r,p} says how many units of raw materials r are used to manufacture a unit of product p. The table H_{p,m∣q(p,m)} says how many hours of machine m it takes to manufacture one unit of product p. The table Rc_{r} gives the cost of a unit of raw materials, the table Mc_{m} gives the cost of machine m per hour, and the table S_{p} is the selling price of product p. Finally, the table Q_{f,p,m∣q(p,m)} is a given production plan. It says how many units products to manufacture on which machine and in which factory. (We do not discuss here whether this production plan is good or not.) We suppose that all products can be sold, and that a machine can only process one product at the same time. We do not consider any other costs. A concrete data set is given in the LPL code and at the end of this paper (see exercise2).
We now wanted to calculate various amounts:
(1) The total selling value TS is:
(2) The total cost of raw material RC is:
(3) The total machine costs MC is:
(4) The total profit TS is:
(5) The total quantity TQ_{p} produced for each product p is:

(6a) How long (in hours) does the production take on each machine m ∈ M and in each factory f ∈ F?

(6b) How long (in hours) does the production take maximally until the last product leaves a factory f ∈ F?

(7a) How big is the loss (gain) of each product (Lo_{p∈P })?

(7b) Which products generate a loss (set LO_{p∈P })?

(8) Which machines in which factories work more than 500 hours (set MO_{f∈F, m∈M})?

(9) Which machine and in which factory works more than any other machine (set MA_{f∈F, m∈M})?

(10) Which machine and in which factory has the least work to do (in hours) (set MI_{f∈F, m∈M})?

It is straightforward to implement this examples in the language LPL. First we declare the given index sets and the tables as follows (the concrete data for the parameter tables can be found in the LPL model):
set
p := [A B C D E F G]; r := [1..20];
m := [M1 M2 M3 M4 M5]; f := [F1 F2 F3 F4];
q{p,m};
parameter
Q{f,q}; S{p}; R{r,p}; H{q}; Rc{r}; Mc{m};
Based on these given data, we can then calculate the various expressions as follows:
parameter
TS := sum{f,q[p,m]} Q*S;
RC := sum{f,p,m,r} R*Rc * Q;
MC := sum{f,p,m} H*Mc * Q;
TP := TS  RC  MC;
Ti{f,m}:= sum{p} H*Q;
TI{f}:= max{m} sum{p} Mc*Q;
Lo{p} := sum{f,m} S*Q  sum{f,m}(sum{r} R*Rc + H*Mc)* Q;
set
LO{p} := sum{f,m} S*Q  sum{f,m}(sum{r} R*Rc + H*Mc)* Q < 0;
MO{f,m}:= sum{p} H*Q > 300;
MA{f,m}:= f=argmax{f}(sum{p} Mc*Q) and m=argmax{m}(sum{p} Mc*Q);
MI{f,m}:= f=argmin{f}(sum{p} Mc*Q) and m=argmin{m}(sum{p} Mc*Q);