m, n = 5, 3 # 5 minutes per period, 3 periods
I = [((p - 1) * m + 1):(p * m) for p in 1:n]3-element Vector{UnitRange{Int64}}:
1:5
6:10
11:15
Applied Optimization with Julia
After this lecture, you will be able to:
Question: What could become an issue?
Question: Where could crowd disasters happen?
Question: What could be a potential bottleneck?
Question: What could be the issue?
This can lead to overcrowding and potential crowd disasters!
Question: What could also be an issue?
Question: What could be the objectives of the authorities?
But we can assist in the estimation of transport demands and the design of operational plans to ensure public safety and a smooth transportation through the city.
Question: Can we just start modeling?
This is a huge challenge, but we can use simulation to estimate the data.
The simulation was built in Julia. With 1,000,000 individuals walking, using cars, buses, and the metro, simulating a day took less than 5 minutes.

Question: What can we do to prevent crowd disasters?
Question: What could we try to model?
Question: What could be the sets for the graph?
These simply help us to represent the entire metro system as a graph with different nodes \(\mathcal{O}\) and arcs \(\mathcal{E}\) between connected stations.
Question: What could be the time sets?
We further define \(n\) as the number of periods in observed time horizon.
Question: Why do we add periods here?
We define the period length as the length of the period in minutes measured as \(m\) minutes, which is the same for all periods.
\[ I_p =\{t \in \mathcal{T}|(p-1) \times m + 1 \leq t \leq p \times m\} \quad \forall p \in \mathcal{P} \]
Question: Can anybody explain it?
With periods of \(m = 5\) minutes, \(I_p\) is a range of minutes for each period:
m, n = 5, 3 # 5 minutes per period, 3 periods
I = [((p - 1) * m + 1):(p * m) for p in 1:n]3-element Vector{UnitRange{Int64}}:
1:5
6:10
11:15
Question: What could be possible parameters?
Question: How do people move inside the metro?
This will help us to model the movement inside the metro.
The arc travel times \(\tau_e\) are only the input to Dijkstra’s algorithm. From the resulting paths we compute the travel time parameter the model actually uses:
Question: How do people spread?
\[\frac{q_{o,d,p}}{\sum_{f \in \mathcal{O}} q_{o,f,p}} \quad \forall o,d \in \mathcal{O}, p\in \mathcal{P}\]
Based on the ratio of the different destinations \(d\) to the total queue for each station \(o \in \mathcal{O}\) in each period \(p \in \mathcal{P}\). Note that the summation needs its own index \(f\) over all destinations, as \(d\) is already taken by the ratio’s destination.
Regulate the inflow at each individual station to minimize the queues outside the metro stations based on the allowed inflow while adhering to the capacity constraints.
There is one queue for all passenger flow directions, as managing multiple queues would be too complex for the planners!
Question: What could be our decision variable?
Regulate the inflow at each individual station to minimize the queues outside the metro stations based on the allowed inflow while adhering to the capacity constraints.
Question: How again are queues minimized?
Question: What could be our objective function?
\[ \text{Minimize} \quad \sum_{o \in \mathcal{O}} \sum_{p \in \mathcal{P}} (\sum_{d \in \mathcal{O}} q_{o,d,p} - m \times X_{o,p}) \]
Question: What does the solver really maximize here?
Minimizing the objective is exactly the same as maximizing the total admitted passengers \(\sum_{o \in \mathcal{O}} \sum_{p \in \mathcal{P}} m \times X_{o,p}\). This is also why the model gets away without explicit queue dynamics.
Question: What constraints do we need?
Question: When do people flowing into the metro system change the arcs?
We can add a new set \(\mathcal{R}_{e,t}\) to help us with this.
\[ \begin{align*} \mathcal{R}_{e,t} = \{(o,d,p) \mid \; & o,d \in \mathcal{O}, p \in \mathcal{P}, q_{o,d,p} > 0, \\ & e \in \mathcal{C}_{o,d}, t-\tau_{o,e} \in I_p\} \quad \forall e \in \mathcal{E}, t \in \mathcal{T} \end{align*} \]
Question: Who can explain this set?
The set \(\mathcal{R}_{e,t}\) contains all combinations \((o,d,p)\) which trigger a capacity utilization of arc \(e\) in minute \(t\).
The set contains all o-d pairs and periods that result in passengers entering arc \((C,D)\) at minute \(22\). With \(m=2\), it is \(\{(A,D,3),(B,D,5),(C,D,11),(E,D,9)\}\).
Check it yourself, e.g. from \(A\): \(\tau_{A,(C,D)} = 5 + 12 = 17\) and \(22-17 = 5 \in I_3 = \{5,6\}\).
Ensure that the capacity of each arc is not exceeded at any minute.
Question: What could be the constraint?
\[ \sum_{(o,d,p) \in \mathcal{R}_{e,t}} X_{o,p} \times \frac{q_{o,d,p}}{\sum_{f \in \mathcal{O}} q_{o,f,p}} \leq \alpha \times c_{e} \quad \forall e \in \mathcal{E}, t \in \mathcal{T} \]
Here, we combine the inflow at each station based on the o-d proportion and let the people spread through the network, checking that no arc is over-utilized at any minute.
Ensure that the inflow rate at each station stays within operational bounds.
Question: What could be the constraint?
\[ c_{o}^{min} \leq X_{o,p} \leq \alpha \times c_{o}^{max} \quad \forall o \in \mathcal{O}, p \in \mathcal{P} \]
This constraint bounds the inflow rate at each station between the minimum and maximum allowed entry rates, ensuring compliance with operational capacity limits.
Ensure that we do not dispatch more people than are queued.
Question: What could be the constraint?
\[ \sum_{d \in \mathcal{O}} q_{o,d,p} - m \times X_{o,p} \geq 0 \quad \forall o \in \mathcal{O}, p \in \mathcal{P} \]
This constraint ensures non-negative remaining queues, preventing the solver from dispatching more passengers than available in the queue.
\[\begin{align*} \text{Minimize} \quad \sum_{o \in \mathcal{O}} \sum_{p \in \mathcal{P}} (\sum_{d \in \mathcal{O}} q_{o,d,p} - m \times X_{o,p}) \end{align*}\] subject to: \[\begin{align*} & \sum_{(o,d,p) \in \mathcal{R}_{e,t}} X_{o,p} \times \frac{q_{o,d,p}}{\sum_{f \in \mathcal{O}} q_{o,f,p}} \leq \alpha \times c_{e} && \forall e \in \mathcal{E}, t \in \mathcal{T} \\ & c_{o}^{min} \leq X_{o,p} \leq \alpha \times c_{o}^{max} && \forall o \in \mathcal{O}, p \in \mathcal{P} \\ & \sum_{d \in \mathcal{O}} q_{o,d,p} - m \times X_{o,p} \geq 0 && \forall o \in \mathcal{O}, p \in \mathcal{P} \\ & X_{o,p} \geq 0 && \forall o \in \mathcal{O}, p \in \mathcal{P} \end{align*}\]
Questions: On model characteristics
It is a linear program, as objective and constraints are linear. The variable \(X_{o,p} \geq 0\) is continuous: fractional inflow rates per minute are perfectly acceptable here.
Questions: On model assumptions
Question: Can this be applied?
Question: Any ideas, how the current model could be improved or how it could be embedded into a heuristic?
The remaining 19% of passengers experience external queuing - this is the price for preventing dangerous overcrowding inside the system.
Question: Our constraint enforces \(\alpha \times c_e\) with \(\alpha < 1\). How can utilization still reach 109%?
Question: Does inflow control also work without a World Cup?
The method scales from event-driven demand (Qatar World Cup) to routine metropolitan operations (Shanghai rush hour).
Few dangerous situations, especially at the FIFA Fan Fest, were handled well by the authorities.
| Feature | Other Methods | Our Approach |
|---|---|---|
| FIFO Enforcement | Rarely | Yes |
| Single Queue | Often separate | Yes |
| Real-Time Capable | Some | Yes (seconds to minutes) |
| Network Scale | Up to 327 stations | Comparable (302 stations) |
First network-level approach combining FIFO enforcement, single-queue modeling, and real-time computational performance.
We now have covered a metro inflow control problem based on a real-world application and are ready to start solving some new tasks in the upcoming tutorial.
For more interesting literature to learn more about Julia, take a look at the literature list of this course.