## 5 Case-Study
### Pump-Orders Execution  
Figure 13(a) shows JADE interaction scenario between the OH and the ORHs (i.e., worker-1 agent, worker-2 agent, and robot agent). During this interaction, the manufacturing operations are assigned to the operational resources based on their status. As it can be seen in lines 1, 2, 3, and 4 of Figure 13(a), the orders agent sends two REQUEST-messages which are replied by two CONFIRM-messages. The first REQUEST-message assigns a Pump-Pick-And-Place-Operation to the robot agent (the content of this message can be seen in Figure 11(c) at the left). The second REQUEST-message assigns a Pump-Assembly-Operation to worker-1 agent (the content of this message can be seen in Figure 11(d) at the left). The reason that the pump-order has been processed first by the orders agent is that it is the first product order at the order list (refer to Figure 10(e)). In line 5 of Figure 13(a), the robot agent sends an INFORM-REF-message to worker-1 agent to tell that it placed the first pump unit. Then, the robot agent sends two INFORM-IF-messages to the orders agent and worker-1 agent to tell that it finished handling all the required pump amounts (i.e., three pump units by referring to Figure 10(c),d,f). The two INFORM-IF-messages can be seen in lines 6, and 7 of Figure 13(a). The same interaction mechanism can be seen in lines 9,10,11,12, and 13 to assign the second pump-manufacturing-order to the worker-2 agent and the robot agent. Lines 14, and 15 of Figure 13(a) shows the INFORM-messages to express done-signal which is generated from the worker-1 and worker-2 agents to the orders agent.  
Reasoning the interaction scenario between the OH and the ORHs is done by the algorithm shown in Figure 13(b). This algorithm has been writing in form of Drools rules, however it is much simpler to show it as a flow chart. The algorithm begins by checking that start production condition is true, and stop production is false. If so, the algorithm check if there are pump orders waiting for execution. If not, [PERSON] waits a new event to be received by the OH to start the algorithm again. After checking all the previously mentioned conditions, [PERSON] checks the status of the robot agent to assign the first order at the Pick-And-Place-Operation. If the robot agent is free, [PERSON] checks the status of both the workers. If worker-1 agent is free and worker-2 agent is busy, [PERSON] assigns the Assembly-Operation to worker-1 agent and starts the algorithm again. If worker-1 agent is busy and worker-2 agent is free, [PERSON] assigns the Assembly-Operation to worker-2 agent and starts the algorithm again. If both the workers are busy, [PERSON] waits a new event to be received by the OH to start the algorithm again. If both the workers are free, [PERSON] checks which worker has assembled more pumps than the other, then the Assembly-Operation will be assigned to the worker who assembled less pumps. This is because the algorithm tries to obtain the balance in distributing the assembly tasks between the two workers. In case both the workers are free and they have been equally assembled the same amount of pumps. [PERSON] assigns to one of them randomly only the first time this case happens. Then, the next time the case happens, [PERSON] assigns to the other worker. After that, [PERSON] keeps switching between the two workers every time this case happens.