### 3.7.144. Metro

A constraint that can be used for modelling the metro problem, i.e.,Β finding the shortest distance from a given metro station to all other stations of the network.

Given an undirected graph $G=\left(V,E\right)$, with a non -negative distance attached to each edge of $E$, a conjunction of $\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi }$ constraints was used by H.Β Simonis in order to illustrate how propagation for such a conjunction simulates a naΓ―ve version of Dijsktra algorithm for computing the shortest distance from a given vertex ${v}_{s}$ of $V$ to all other vertices. The potential source of inefficiency comes from the fact that, depending on the scheduling policy of the underlying constraint engine, an inequality constraint can be reconsidered several times before reaching the fixed point. The problem was modelled in the following way:

• To each vertex ${v}_{i}\beta V$ we associate a distance variable ${D}_{i}$, which represents the domain range of the distance between vertex ${v}_{i}$ and vertex ${v}_{s}$.

• To each edge $\left({v}_{i},{v}_{j}\right)\beta E$ we impose two inequality constraints ${D}_{i}\beta €{D}_{j}+{d}_{i,j}$ and ${D}_{j}\beta €{D}_{i}+{d}_{i,j}$, where ${d}_{i,j}$ corresponds to the distance attached to edge $\left({v}_{i},{v}_{j}\right)$. This restricts the maximum difference between the distances variables associated with the two extremities of edge $\left({v}_{i},{v}_{j}\right)$.

• Finally, we set the distance variable attached to vertex ${v}_{s}$ to 0. Propagating the inequalities constraints by using arc-consistency enforces the maximum value of each distance variable ${D}_{i}$ to be equal to the shortest distance from vertex ${v}_{i}$ to ${v}_{s}$ when the fixed point is reached.

FigureΒ 3.7.32 illustrates this problem on a metro map composed of four lines and 18 stations respectively labelled by a, b, $...$, r. Its assumes that the distance associated with each connection is equal to 1. The figure displays the status (i.e.,Β the minimum and maximum values) of the distance variables under the assumption that we want to compute the shortest path from station i. The inequalities constraints between the distance variables ${D}_{a},{D}_{b},...,{D}_{r}$ corresponding to this metro map are:

• (constraints attached to the connections of the blue metro line)

• Β Β ${D}_{a}\beta €{D}_{b}+1$,Β Β ${D}_{b}\beta €{D}_{a}+1$,

• Β Β ${D}_{b}\beta €{D}_{c}+1$,Β Β ${D}_{c}\beta €{D}_{b}+1$,

• Β Β ${D}_{c}\beta €{D}_{d}+1$,Β Β ${D}_{d}\beta €{D}_{c}+1$,

• Β Β ${D}_{d}\beta €{D}_{e}+1$,Β Β ${D}_{e}\beta €{D}_{d}+1$,

• Β Β ${D}_{e}\beta €{D}_{f}+1$,Β Β ${D}_{f}\beta €{D}_{e}+1$,

• Β Β ${D}_{f}\beta €{D}_{a}+1$,Β Β ${D}_{a}\beta €{D}_{f}+1$.

• (constraints attached to the connections of the pink metro line)

• Β Β ${D}_{g}\beta €{D}_{f}+1$,Β Β ${D}_{f}\beta €{D}_{g}+1$,

• Β Β ${D}_{f}\beta €{D}_{h}+1$,Β Β ${D}_{h}\beta €{D}_{f}+1$,

• Β Β ${D}_{h}\beta €{D}_{c}+1$,Β Β ${D}_{c}\beta €{D}_{h}+1$,

• Β Β ${D}_{c}\beta €{D}_{i}+1$,Β Β ${D}_{i}\beta €{D}_{c}+1$,

• Β Β ${D}_{i}\beta €{D}_{j}+1$,Β Β ${D}_{j}\beta €{D}_{i}+1$.

• (constraints attached to the connections of the green metro line)

• Β Β ${D}_{p}\beta €{D}_{q}+1$,Β Β ${D}_{q}\beta €{D}_{p}+1$,

• Β Β ${D}_{q}\beta €{D}_{r}+1$,Β Β ${D}_{r}\beta €{D}_{q}+1$,

• Β Β ${D}_{r}\beta €{D}_{a}+1$,Β Β ${D}_{a}\beta €{D}_{r}+1$,

• Β Β ${D}_{a}\beta €{D}_{h}+1$,Β Β ${D}_{h}\beta €{D}_{a}+1$,

• Β Β ${D}_{h}\beta €{D}_{d}+1$,Β Β ${D}_{d}\beta €{D}_{h}+1$.

• (constraints attached to the connections of the yellow metro line)

• Β Β ${D}_{k}\beta €{D}_{l}+1$,Β Β ${D}_{l}\beta €{D}_{k}+1$,

• Β Β ${D}_{l}\beta €{D}_{m}+1$,Β Β ${D}_{m}\beta €{D}_{l}+1$,

• Β Β ${D}_{m}\beta €{D}_{a}+1$,Β Β ${D}_{a}\beta €{D}_{m}+1$,

• Β Β ${D}_{a}\beta €{D}_{n}+1$,Β Β ${D}_{n}\beta €{D}_{a}+1$,

• Β Β ${D}_{n}\beta €{D}_{o}+1$,Β Β ${D}_{o}\beta €{D}_{n}+1$,

• Β Β ${D}_{o}\beta €{D}_{i}+1$,Β Β ${D}_{i}\beta €{D}_{o}+1$.