# ASP-Based Declarative Reasoning in Data-Intensive Enterprise and IoT Applications
## 2 The DLV-EE Framework
### Reasoning over Hive
The configuration is depicted in Figure 5: each traffic light is emulated with an _Arduino_[[https://www.arduino.cc/](https://www.arduino.cc/)]([https://www.arduino.cc/](https://www.arduino.cc/)) device and each crossing is equipped with a _Raspberry Pi_ device; moreover, a further central _Raspberry Pi_ device coordinates the traffic lights in green wave situations. ASP can be profitably used to model the functioning of the crossings using DLV-IoT as a reasoning engine, executed on the _Raspberry Pi_ devices. In particular, for each crossing, the corresponding _Raspberry Pi_ device executes DLV-IoT over an ASP program for defining how to control the local functioning of its traffic lights. The ASP program receives as input some facts modeling the topology of the corresponding crossing. For instance, for _c1_, the following facts, from _f1_ to _f5_, states that _c1_ is a crossing and that _s1_, _s2_, _s3_, _s4_ are traffic lights related to _c1_. Figure 5: A Smart City use case: crossroads with traffic lights. _f_i: traffic_light(s3,c1). \(f\)5: traffic_light(s4,c1). Similar facts, in which _c1_ is replaced by _c2_, are the input of the ASP program controlling the crossing _c2_. The ASP program, modeling the behavior of each crossing, is composed as follows:

\(r\)1: namePair(s1,s4,C) - crossing(C). \(r\)2: namePair(s2,s3,C) - crossing(C). \(r\)3: status(T,C,red) | status(T,C,green) - traffic_light(T,C). \(r\)4: - status(T1,C,Status1), status(T2,C,Status2),

samePair(T1,T2,C), Status1=Status2. \(r\)5: - status(T1,C,Status), status(T2,C,Status),

T1:=T2, not samePair(T1,T2,C). Rules \(r\)1 and \(r\)2 define the grouping in pairs of traffic lights on the same road. Rule \(r\)3 guesses the status of each traffic light. Rules \(r\)4 and \(r\)5 are strong constraints allowing to discard solutions in which two traffic lights of the same road have different statuses (i.e., \(r\)4) and two different traffic lights not part of the same pair have the same status (i.e., \(r\)5). The _Raspberry Pi_ of each crossing generates a first status assignment for each traffic light and every 10 seconds the statuses are automatically turned. In case a pedestrian requires to cross a road, e.g., at the traffic light _s1_ of _c1_, the _Raspberry Pi of c1_ is notified, and consequently, it re-executes DLV-IoT over the same ASP program above with the addition of the fact status(s1,c1,red). The statuses of the traffic lights are accordingly updated and then, continue to be turned every 10 seconds. The central _Raspberry Pi_ is in charge of synchronizing both crossings in case of a green wave. To this end, DLV-IoT is executed over the same program above with the addition of the strong constraint reported below (rule \(r\)6). \(r\)6 :- greenwave, state(s1,c,red). Hence, when a green wave is requested (i.e., a fact greenwave is given as input), the status of the traffic lights _s1_ of both _c1_ and _c2_ has to be green. The constraint \(r\)4 ensures that the traffic lights _s4_ of both _c1_ and _c2_ are green as well. The central _Raspberry Pi_ can thus directly update the statuses of all traffic lights overriding the default behavior. ## 5 Conclusion and Discussion

This paper presented DLV-EE, an ASP-based Framework for performing declarative-based reasoning tasks over Big Data, classical relational database systems, and NoSQL databases. Moreover, DLV-IoT, a variant of DLV2 geared towards IoT technologies, was proposed for easing the implementation of ASP-based mobile and distributed applications. The specific development tools, designed for DLV-EE and DLV-IoT, and based on _ASPIDE_ were also discussed. Finally, the potential of the proposals was highlighted with the help of some use cases. DLV-EE, DLV-IoT and the related development tools can be downloaded at [[https://www.mat.unical.it/ricca/aspide/dlvee](https://www.mat.unical.it/ricca/aspide/dlvee)]([https://www.mat.unical.it/ricca/aspide/dlvee](https://www.mat.unical.it/ricca/aspide/dlvee)).