## 5 Running Scenario  
The scenario regards supporting real-time supply chain decisions based on RFID streams. Consider the stock management of an online shop. RFID sensors are used to count the items entering the warehouse from two locations. The items leave the warehouse from exit points, corresponding to three output streams. Monitoring an item like _Milk_ implies monitoring several subcategories as _WholeMilk_ and _LowFatMilk_. The retailer sells a specific item \(fm_{1}\) of whole milk, and two types of low fat milk \(sm_{1}\) and \(sm_{2}\). Some peak periods are associated to each commercialised item. This background knowledge is formalised in Figure 6. The corresponding strict rules are depicted in the upper part of the Figure 7. During peak periods for an item, the usual supply action is blocked by the defeater \(r_{11}\). The plausible rule \(r_{10}\) says that if the milk stock \(Y\) is below the alert threshold \(c_{1}\), the _NormalSupply_ action should be executed. _NormalSupply_ assures a stock value of \(c_{2}\). Instead, the _PeakSupply_ action is derived by the rule \(r_{11}\). If there is an alternative itemZ for the _Milk_ product and the stock of the alternative is larger than the threshold \(c_{4}\), this implies not to supply the higher quantity \(c_{2}\) (the rule \(r_{12}\)). Whether the action is executed or not depends on the priority relation between the rules \(r_{12}\) and \(r_{13}\),  
The sensor related information can be integrated when reasoning. If the sensor \(S\) seems not to function according to the specifications in the ontology, it is plausible to be broken (the rule \(r_{14}\)). A broken sensor defeats the stock information asserted in the knowledge base related to the measured item (the defeater \(r_{15}\)). The merchandise flow is simulated by generating infinite input and output streams. Assuming that the function \(randomItem::[Item]->Item\) based on the list of available items returns a random item. The infinite output stream for the payment point \(out_{1}\) would be:  
\[out_{1}=(randomItem\ l):out_{1}\]  
where \(l\) is a list with the available items in the simulation. Consider the following RDF stream \(s_{1}\) of sold items _(item sold price)_ and the associated time of measurement, where the predicate _sold_ and the _price_ value are removed for clarity reasons:  
Figure 6: Domain knowledge sample for milk monitoring. Figure 7: Plausible knowledge base. \[[(sm_{1},\_,\_,),1),((m_{1},\_,\_,),2),((fm_{1},\_,\_,),3),((m_{2},\_, \_,),4),((m_{3},\_,\_),5),\] \[((sm_{2},\_,\_),6),((m_{4},\_,\_,),7),....]\]  
The _updateStock_ function continuously computes the current stocks based on the \(s_{1}\) stream. Based on the fact \(f_{1}\) and the rule \(r_{3}\), one can conclude that \(fm_{1}\) is a milk item. Similarly, based on the facts \(f_{2}\) and \(f_{3}\), the rule \(r_{4}\) categorises the instances \(sm_{1}\) and \(sm_{2}\) as milk items. The filter function is used to monitor each milk item, either low fat or not:  
\[milkItems=filter\ milk\ (map\ first\circ first\ s_{1})\]  
Here, the predicate _milk_ returns true if the input is of type _Milk_ according to the rules \(r_{3}\) or \(r_{4}\). The _map_ function is used to select only the element _item_ from the tuples \(((item,\_,\_),time)\) from the stream \(s_{1}\): the composition \(first\circ first\) is used to extract the first element in the first tuple. The stream _milkItems_ collects all the items of type milk every time an item occurs. Based on \(s_{1}\), the _milkItems_ is:  
\[[(sm_{1},\_,\_),1),((fm_{1},\_,\_),3),((sm_{2},\_,\_),6),....]\]  
The \(updateStock::Item->Stream->Int\) function is activated to compute the available stock for a specific category of products. Consider the current stock for milk is 102 and the threshold \(c_{1}\) for triggering the alarm is 100. Assume the function _updateStock_ is called with the first input parameter _milk_ and the second parameter _milkItems_. At time 1, \(sm_{1}\) being low fat milk, identified as a subtype of milk, the stock is updated at the value 101.