## 7 Practical Extensions: Accommodating Incremental Observations  
In this and later parts of this paper, we focus on extensions of Algorithm _Incremental\({}^{h}\)_ (Algorithm 4) that are of practical interest. One may observe that Algorithm _Incremental\({}^{h}\)_ (Algorithm 4) leverages clingo's incremental infrastructure to improve performance for a given set of observations and queries. However, if further observations become available at a later time, the entire algorithm needs to be executed again. The refinement of _Incremental\({}^{h}\)_ shown below, called _Incremental\({}^{+}\)_, can incrementally integrate observations as well. _Incremental\({}^{+}\)_ requires the output module to be modified to include a directive:  
\[\#external\ output\_enabled. \tag{21}\]  
Additionally, every rule of the module must be expanded to include the condition \(output\_enabled\). This modification enables _Incremental\({}^{+}\)_ to enable and disable the output module as needed. Figure 4: Comparison of the execution times for all instances that did not time out, 0–10 s detail. Figure 3: Comparison of the execution times for all instances that did not time out. ```
1:\(p\): pre-determined time steps, e.g., from observations and queries, as facts of the form \(\mathit{time}(t)\)
2:\(\triangleright\) Expansion phase (\(\mathit{base}+\mathit{timedep}(0)\))
3:\(G\gets\mathit{ground}(\mathit{base}\cup\mathit{timedep}(0)\cup p)\)
4:For every external \(\mathit{enabled}(t)\) from G, assert \(\mathit{enabled}(t)\) true via clingo's \(\mathit{assign}_{\mathit{external}}()\)
5:\(A\leftarrow\mathit{solve}(G)\)
6:\(\triangleright\) end of expansion phase
7:if\(\{t\mid\mathit{newtime}(t^{\prime},t)\in A\text{ and }\mathit{time}(t)\
ot\in A\}=\emptyset\)then
8:\(m\leftarrow\bot\)
9:else
10:\(m\leftarrow\mathit{min}\{t\mid\mathit{newtime}(t^{\prime},t)\in A\text{ and }\mathit{time}(t)\
ot\in A\}\)
11:endif
12:\(O\leftarrow\emptyset\)
13:while true do
14:while\(m\
eq\bot\)do
15:\(\triangleright\) Retraction phase
16: For every external \(\mathit{enabled}(t)\) from G such that \(t\geq m\), assert \(\mathit{enabled}(t)\) false and release it via clingo's \(\mathit{release}_{\mathit{external}}()\)\(\triangleright\) i.e., it is no longer an external
17:\(\mathit{solve}(G)\)\(\triangleright\) preparatory step for cleanup()
18:\(\mathit{cleanup}(G)\)\(\triangleright\) clingo primitive for retracting previous conclusions
19:\(\triangleright\) end of retraction phase \(\triangleright\) Expansion phase
20:\(G\gets\mathit{ground}(\{time(t).\mid\mathit{newtime}(t^{\prime},t)\in A \text{ and }\mathit{time}(t)\
ot\in A\})\)\(\triangleright\) add new time steps to the ground program
21:\(G\gets\mathit{ground}(\mathit{timedep}(m)\cup O)\)\(\triangleright\) inject the observations
22: For every external \(\mathit{enabled}(t)\) from G such that \(t\geq m\), assert \(\mathit{enabled}(t)\) true
23:\(A\leftarrow\mathit{solve}(G)\)
24:\(\triangleright\) end of expansion phase
25:if\(\{t\mid\mathit{newtime}(t^{\prime},t)\in A\text{ and }\mathit{time}(t)\
ot\in A\}=\emptyset\)then
26:\(m\leftarrow\bot\)
27:else
28:\(m\leftarrow\mathit{min}\{t\mid\mathit{newtime}(t^{\prime},t)\in A\text{ and }\mathit{time}(t)\
ot\in A\}\)
29:endif
30:endwhile
31:\(\triangleright\) addition of the output module
32:\(G\leftarrow\mathit{ground}(\mathit{output})\)
33: assert \(\mathit{output}\_{\mathit{enabled}}\) true
34:output\(\mathit{solve}(G)\)
35:\(\triangleright\) end of addition of the output module
36:receive \(O\)\(\triangleright\) receive new observations. Assumption: \(O\
eq\emptyset\)
37: assert \(\mathit{output}\_{\mathit{enabled}}\) false
38:\(m=\mathit{min}\{\text{timestep-of}(o)\mid o\in O\}\)
39:endwhile
```  
**Algorithm 4** Algorithm \(\mathit{Incremental}^{+}\)  
Differently from \(\mathit{Incremental}^{\text{th}}\), \(\mathit{Incremental}^{+}\) does not terminate and thus does not return any value. Rather, it assumes a two-way communication with the caller via primitives \(\mathit{output}\) and \(\mathit{receive}\).