# An IoT-Based Framework for Smart Water Supply Systems Management
## 4 Background
### Declarative Process  
Unlike imperative processes, the concept declarative defines a set of restrictive rules. As long as users respect these rules, they are free to choose how to execute the process [19]. In the opposite direction, imperative processes specify how the users must execute the rules, stating all possible dependencies between tasks. This difference is fundamental for declarative processes in environments of uncertainty and constant change as in the field of water management. Scenario  
This paper uses a real water system from a Brazilian city. Figure 2a shows the map of the northeast region of Brazil. It indicates the location of the water system used in this study. Figure 2b highlights the area covered by the water system, using an image extracted from Google Earth. The scenario models a subsystem that consists of four pumps and a tank. The pumps draw water from a water treatment plant. The system adopts the following rules to control the real system:  
1. All pumps are off at the beginning of the process. 2. It checks the tank level after a given predefined period. 3. Turns all pumps on when the tank reaches the lower level. 4. Turns all pumps off when the tank reaches the higher level. 5. Turns off the pump running for the longest period whenever the volume of water flowing to the tank is greater than the volume of water flowing out of the tank. 6. Turns off the pump running for the longest period whenever the volume of water flowing to the tank is lower than the volume of water flowing out of the tank. For the sake of clarity, the scenario used in this paper does not include some of these rules. Examples include the treatment of defective pumps, pumps that need maintenance, lack of water at the source, excessive water turbidity, and problems in the tank. Figure 3 shows the process modeled in BPMN. Steps 1 to 6 are depicted in Figures 3 and 4. These figures show representations in BPMN and in Declare of the six steps. In Figure 3 we see some error treatments that lead to a System Emergency Shutdown in the case of any problems during BPMN activities like Check Tank Level, or Turn on or Turn off pumps. As described in the list, the first activity is Check Tank Level: based on the result of this activity the system will turn on or turn off all pumps. Figure 2: (a) Map of Brazil where scenario is localized; (b) area covered by the water system. After some time, a second activity will check the difference between input and output water flow and make another decision based on the result: eliminate one pump (turning it off) or turn on another pump (if it is some other pump to be turned on). This is an infinite loop that will stop only if another action outside of the model is performed. During the modeling phase, we noticed a significant impact on the complexity of the imperative process (Figure 3) when any of the simplifications mentioned above are not assumed. For instance, the addition of a maintenance subprocess, which stops pumps for preventive maintenance or closes the tank for cleaning, duplicates the number of connections in the BPMN model. On the other hand, including the same rules in the declarative process (Figure 4) has a negligible impact on the process complexity. In this case, to add an action to stop a pump and execute the preventive maintenance or to close and clean the tank would be enough. The simplicity of the BPMN model is also its weakness when trying to when trying to devise a stop process for one or more pumps for preventive maintenance, or even a stop for tank cleaning or maintenance. On must rewrite the entire process to meet the need for unforeseen events. Figure 4 depicts the same process that was described before: the difference is the notation. As it is a declarative notation, there is no definition of the sequence of activities, only the constraints. The activities on this notation are the rectangles. There is just one kind of rule, which is an obligation of immediate execution, called a chain response.