## 4 Variable Deployment Models
### Algorithms for Resolving Variability
#### 4.2.3 Consistency Check Algorithm  
Inconsistencies might occur in the derived Variability-Resolved Deployment Model. If, for example, a component has multiple conditional hosting relations to several components but their conditions do not exclude each other, i.e., more than one of these hosting relations have all their assigned conditions fulfilled, the component must be hosted on multiple components at the same time which is not possible. Of course, such _overlapping conditions_ are a clear modeling mistake and must be avoided during modeling. However, if the variability is high, such modeling errors might occur. Therefore, we introduce the algorithm _checkConsistency_ in Algorithm 3 that executes four checks regarding the consistency of the derived model. The first two checks verify that the source component and target component of each relation in the derived model is also present in the derived model (see Lines 2-4 and 7-9). It is possible that, for example, a relation is present while the target component is not if all conditions of the relation evaluate to true but the ones assigned to the target component do not. The third check verifies that each component in the derived model has at maximum one hosting relation in the derived model (see Lines 12-14). Multiple hosting relations can occur, for example, when their assigned conditions do not exclude each other. Thereby, the check allows components without hosting relations, such as a basic infrastructure virtualization layer as OpenStack, since these are typically not managed by the deployment model. The last and fourth check verifies that each component in the derived model has a hosting relation if the component has at least one hosting relation in the Variable Deployment Model (see Lines 17-19). Thereby, we assume that if a component has a hosting relation in any variant then a hosting relation is always required. Considering our motivating scenario, the component \"Web Component\", for example, always requires a hosting relation while having two conditional hosting relations in the Variable Deployment Model. If none of these relations are present in the derived model, then the deployment model cannot be executed.  
```
1:// Ensure that each relation source exists
2:if\(\left(\exists r_{i}=(s,t)\in R_{d}:s\
otin C_{d}\right)\)then
3:returnfalse
4:endif
5:
6:// Ensure that each relation target exists
7:if\(\left(\exists r_{i}=(s,t)\in R_{d}:t\
otin C_{d}\right)\)then
8:returnfalse
9:endif
10:
11:// Ensure that every component has at maximum one hosting relation
12:if\(\left(\exists c_{i}\in C_{d}\;\exists r_{j}=(c_{i},a)\in R_{d}\;\exists r_{k}=(c_{i},b) \in R_{d}:\right.\)
13:\(r_{j}\
eq r_{k}\wedge\textit{type}_{d}(r_{j})=\textit{type}_{d}(r_{k})= \textit{hostedOn}\)) then
14:returnfalse
15:
16:// Ensure that every component that had a hosting relation previously still has one
17:if\(\left(\exists c_{i}\in C_{d}\;\exists r_{j}=(c_{i},a)\in R_{\textit{ndm}}\; \exists r_{k}=(c_{i},b)\in R_{d}:\right.\)
18:\(\textit{type}_{\textit{ndm}}(r_{j})=\textit{type}_{d}(r_{k})=\textit{hostedOn}\)) then
19:returnfalse
20:
21:endif
22:// All checks passed
23:returntrue
```  
**Algorithm 3** checkConsistency(\(d\in D_{\textit{ndm}}\), \(\textit{vdm}\in\mathcal{VDM}\)): \(b\in\left\{\textit{true,false}\right\}\)