## 4 Solving the Warehouse Delivery Problem
### Task Assignment and Sequencing  
We present in Listing 2 an encoding for assigning and sequencing tasks. ```
11{assign(R,T):robot(R)}1:-task(T,_),notdepends(deliver,_,T). 2 assign(R,T'):-assign(R,T),depends(deliver,T,T'). 40{task_sequence(T,T'):task(T',_),T=T',notdepends(deliver,_,T')}1
5:-task(T,_),notdepends(deliver,T,_). 6 task_sequence(T,T'):-depends(deliver,T,T'). 8 same_robot(T,T'):-assign(R,T),assign(R,T'),T<T',
9 notdepends(deliver,T,T'). 10 same_robot(T,T'):-depends(deliver,T,T'). 12:-task_sequence(T,T'),notdepends(deliver,T,T'),
13 notsame_robot(T,T'),notsame_robot(T',T). 14:-task(T,_),2#count{T':task_sequence(T',T)}. 15:-assign(R,_),not#count{T:assign(R,T),nottask_sequence(_,T)}=1. ```  
More precisely, a complete and non-overlapping task sequence assignment to robots is established. This part is common to both the step- and path-based approach introduced in the following two sections. In what follows, we draw on the components of a fixed warehouse (\(V\),\(E\),\(f_{E}\),\(C\),\(R\),\(f_{H}\),\(f_{S}\)) and a task execution graph (\(T\),\(D\),\(f_{D}\),\(f_{V}\)). A task sequence assignment \(f_{T}\) allots each robot a sequence of tasks; it is represented by atoms over predicatesassign/2 andtask_sequence/2. An atomassign(\(r\),\(t\)) represents that \(t\in f_{T}(r)\) for robot \(r\) and task \(t\). Furthermore, an atomtask_sequence(\(t\),\(t^{\prime}\)) signifies that there is a task assignment \(f_{T}(r)=\langle\dots,t,t^{\prime},\dots\rangle\) with two consecutive tasks \(t,t^{\prime}\in T\) for some robot \(r\in R\). Lines 1-2 deal with task assignments and enforce that the task sequence assignment is complete and non-overlapping, as spelled out in Condition 6 and 7. In Line 1, we assign each task \(t\) without any delivery dependency, or formally, where there is no \((t,t^{\prime})\in D\) such that \(f_{D}((t,t^{\prime}))=deliver\), to exactly one robot in \(R\). Line 2 ensures that tasks that are in a delivery dependency are assigned to the same robot. That is, once a robot \(r\) is assigned a task \(t\) that is part of a delivery dependency \((t,t^{\prime})\), then \(r\) must also be assigned task \(t^{\prime}\). The remainder of Listing 2 is dedicated to sequencing the assigned tasks. In Line 4, a task \(t^{\prime}\) can be chosen as succeeding a task \(t\), by means oftask_sequence(\(t\),\(t^{\prime}\)), so long as \(t^{\prime}\) has no other task as a delivery dependency and \(t\) is not a delivery dependent of some other task. That is, for any task \(t\) without a subsequent delivery dependency, we may choose a succeeding task \(t^{\prime}\) having no preceding delivery dependency. On the other hand, whenever two tasks \(t,t^{\prime}\in T\) are in a delivery dependency, viz. \((t,t^{\prime})\in D\) and \(f_{D}((t,t^{\prime}))=deliver\), we enforce their succession by derivingtask_sequence(\(t\),\(t^{\prime}\)) in Line 6. Lines 8-10 identify tasks assigned to the same robot. We separate this into two cases. Line 8 deals with tasks that are not in a delivery dependency but happen to be assigned to the same robot. This information is dynamic and can only be determined at solving time from the identity of the assigned robots. Note, _clingo_'s grounderantees a total ordering over terms; and we rely on this ordering by using the conditionT<T' to avoid the generation of redundant ground rules resulting from the symmetry between the tasksT andT'. In contrast, Line 10 directly asserts the static fact that a pair of tasks in a delivery dependency is necessarily assigned to the same robot. This static information is independent of the identity of the assigned robots and can be determined at grounding time. Consequently, separating the two cases results in a (slight) reduction of the size of the resulting grounding and results in fewer choices that need to be made by the solver. The resulting information is then used in Line 12 to ensure that all pairs of ordered tasks, expressed bytask_sequence(\(t\),\(t^{\prime}\)), are assigned to the same robot.