# A Middleware-Based Approach for Multi-Scale Mobility Simulation
## 4 Inter-Dependency between Simulations
### Cases 3 and 8  
In these cases, one simulation has a valid Demand function and the other has valid Assign and Move. Both simulations have to correct each others. This case can represent a situation where a local neighborhood simulation has a very detailed and validated modeling of the crowd dynamics, but its demand is coming from a wide-region simulation (e.g., in [38]). In this situation, the middleware needs to execute Algorithm 1 (called D-AM for Demand (first simulation)-Assign and Move (second simulation)).  
```
Require:\(\mathcal{S}_{d}=\langle\omega_{d},\sigma_{d},\theta_{d},\mathcal{P}_{d}\rangle\); \(\mathcal{S}_{am}=\langle\omega_{am},\sigma_{am},\theta_{am},\mathcal{P}_{am}\rangle\), Ensure:\(\mathcal{S}_{dam}=\mathcal{S}_{d}\otimes\mathcal{S}_{am}\) (1) \(\omega_{dam}\leftarrow\omega_{d}\circ\omega_{am}\) (2) \(\sigma_{dam}=\sigma_{d}\bullet\sigma_{am}\) (3) \(\theta_{dam}\leftarrow\theta_{d}\diamond\theta_{am}\) while\(\
eg End\)do (4) execute \(\mathcal{S}_{d}\) and save its demand \(M_{od,\mathcal{S}_{d}}\) in \(\mathcal{S}_{dam}\) (5) execute \(\mathcal{S}_{am}\) with the demand \(M_{od,\mathcal{S}_{d}}\) and save the resulting \(G_{Sam}\) in \(\mathcal{S}_{dam}\) (6) execute \(\mathcal{S}_{d}\) again with \(G_{Sam}\) and save its demand \(M_{od,\mathcal{S}_{d}}\) in \(\mathcal{S}_{dam}\) endwhile (7) Return \(\mathcal{S}_{dam}\)
```  
**Algorithm 1** D-AM algorithm.  
Instructions (1)-(3) allow for composing the scales of the involved simulations. To compose the processes, the middleware iteratively executes \(\mathcal{S}_{d}\rightarrow\mathcal{S}_{am}\rightarrow\mathcal{S}_{d}\), so that \(\mathcal{S}_{d}\) provides the right demand to \(\mathcal{S}_{am}\), which in turn provides the right valuations of the transportation graph (instructions (4)-(6)). Note that we use a simplified notation for the \"execute\" instruction: It actually means to execute as many time steps as necessary to cover a time step of the other simulation, as described in Section 3.3. The boolean \(End\) is set to true when the maximum time step is reached by one of the simulations.  
In all the algorithms of this section, instruction (6) is the one that might be impossible to execute for all mobility simulations. Indeed, it implies re-executing the same time step of a simulation (a kind of rollback), but with different data. Since it is not always possible, we test in the experiments the case where only instructions (4) and (5) are executed (a unidirectional correction).  
\begin{table}
\begin{tabular}{l c c c} \hline \hline \# & \(\mathcal{S}_{1}\)’s Valid Function (s) & \(\mathcal{S}_{2}\)’s Valid Function (s) & Inter-Dependency? \\ \hline
1 & Demand, Assign, Move & - & \(\times\) \\ \hline
2 & - & Demand, Assign, Move & \(\times\) \\ \hline
3 & Demand & Assign, Move & \(\surd\) \\ \hline
4 & Assign & Demand, Move & \(\surd\) \\ \hline
5 & Move & Demand, Assign & \(\surd\) \\ \hline
6 & Demand, Assign & Move & \(\surd\) \\ \hline
7 & Demand, Move & Assign & \(\surd\) \\ \hline
8 & Assign, Move & Demand & \(\surd\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: The different types of inter-dependency between multi-scale simulations.