σ = 0.3
U = [0.2, 0.9, 0.5, 1.0, 0.4, 0.2] # relative utilization per period
[abs(U[t] - U[t-1]) <= σ for t in 2:6] # change within σ? (1 = yes)5-element Vector{Bool}:
0
0
0
0
1
Applied Optimization with Julia
Question: Have you ever heard of the Hajj?
After this lecture, you will be able to:


Pilgrims throw pebbles against three pillars, which symbolize the temptations of the devil. They repeat this ritual with small variations on four consecutive days.
Question: What could become a problem?
Uncoordinated access within confined area can escalate into crowd disasters!
Question: Where on the way does a crowd become dangerous?
Question: What could we do to prevent this?



Question: What is the most dangerous type here?
Multi-directional and intersecting flows are the most dangerous type!

Adhere to one-way flow systems and define path options for each camp under consideration of a unidirectional flow system.
Question: What could be the objective?
Question: How can we try to model this?
Question: Where is the goal conflict?

Each camp has a set of feasible one-way paths that include the stoning ritual.
A path may contain one or more bottlenecks, regarded as resources subject to a capacity.
Pilgrims depart from a camp at a time \(t\) and pass through the bottleneck later.
Our model should assign one of the feasible paths to a camp on all four ritual days.
These bottlenecks should not be overcrowded at any time during the Hajj.

May be computed, i.e., down-sampled given a distribution of pilgrims over time.
Question: What could become a problem?
Question: Any idea how we can do that later?
Question: What could be the sets here?
A scheduling group is a group of pilgrims from one camp on one specific ritual day. One model thus covers all four days at once.
But we further need subsets!
Question: Why use subsets?
A smaller problem size reduces the solution space and helps the solver in finding the optimal solution faster!
Question: What could be possible parameters?
Satisfy time preferences of the pilgrims as much as possible under the consideration of infrastructure bottleneck flow capacities by assigning “something” to a time slot.
Question: What could be our decision variable?
Question: Do you get the idea here?
It’s a binary assignment of a group to a time slot and a path.
For the sake of simplicity and safety, pilgrims coming from one camp will always have to be assigned the same path.
Question: What could be our second variable?
Question: Does anyone remember the third part?
We need to keep track of the relative utilization of each resource to restrict the fluctuations between periods to ensure a safer event.
Question: What could be our third variable?
Question: What does relative utilization mean?
Satisfy time preferences of the pilgrims as much as possible under the consideration of infrastructure bottleneck flow capacities by assigning “something” to a time slot. Hint: We thus could aim to minimize the total dissatisfaction with the timetable.
Question: How could we minimize the total dissatisfaction?
Question: What could be our objective function?
\[ \text{Minimize} \quad \sum_{s \in \mathcal{S}}\sum_{t \in \mathcal{T}_s}\sum_{p \in \mathcal{P}_s} f_{s,t} \times X_{s,t,p} \]
Note how we use the subsets \(\mathcal{T}_s\) and \(\mathcal{P}_s\) to keep the model small.
Question: Is our objective function linear?
Question: Any idea why?
Question: Which constraints do we need?
Assign one path to each camp over the entire time horizon.
Question: What could be the constraint?
\[ \sum_{p \in \mathcal{P}_c} Y_{c,p} = 1 \quad \forall c \in \mathcal{C} \]
Assign one time slot to each group over the entire time horizon using the same path we have assigned to the camp in the previous constraint.
Question: What could be the constraint?
\[ \sum_{t \in \mathcal{T}_s} X_{s,t,p} = Y_{c,p} \quad \forall c \in \mathcal{C}, p \in \mathcal{P}_c, s \in \mathcal{S}_c \]
Each group can use all feasible paths of its camp: \(\mathcal{P}_s = \mathcal{P}_c\) for all \(s \in \mathcal{S}_c\).
Question: We wanted one path and one time slot per group. Where are these two constraints?
Sum the last constraint over all paths of a camp:
\[ \sum_{p \in \mathcal{P}_c} \sum_{t \in \mathcal{T}_s} X_{s,t,p} = \sum_{p \in \mathcal{P}_c} Y_{c,p} = 1 \quad \forall c \in \mathcal{C}, s \in \mathcal{S}_c \]
Compute the relative utilization of each resource while also ensuring that the utilization does not exceed the capacity limit. This one is very tricky!
Difficulties:
Question: What could be the constraint?
\[ \sum_{p \in \mathcal{P}_r}\sum_{s \in \mathcal{S}_p} n_s \times X_{s,t-a_{p,r},p} = b_{r,t}\times U_{r,t} \quad \forall r \in \mathcal{R}, t \in \mathcal{T} \]
Terms where the shifted period \(t - a_{p,r}\) lies outside of \(\mathcal{T}_s\) are simply dropped, as no group can be scheduled for stoning there.
Question: We promised a capacity limit, but there is no “\(\leq\) capacity” constraint. Why does it still hold?
A variable domain and a constraint can combine into a constraint that is never written down explicitly.
Keep the relative utilization of each resource within bounds to ensure a safer event.
Question: What could be the constraint?
\[ U_{r,t} - U_{r,t-1} \leq \sigma_r \quad \forall r \in \mathcal{R}, t \in \mathcal{T}: t > 1 \]
\[ U_{r,t-1} - U_{r,t} \leq \sigma_r \quad \forall r \in \mathcal{R}, t \in \mathcal{T}: t > 1 \]
Question: Can somebody explain why this works?
σ = 0.3
U = [0.2, 0.9, 0.5, 1.0, 0.4, 0.2] # relative utilization per period
[abs(U[t] - U[t-1]) <= σ for t in 2:6] # change within σ? (1 = yes)5-element Vector{Bool}:
0
0
0
0
1
\[\begin{align*} \text{Minimize} \quad \sum_{s\in \mathcal{S}}\sum_{t \in \mathcal{T}_s}\sum_{p \in \mathcal{P}_s} f_{s,t} \times X_{s,t,p} \end{align*}\]
subject to:
\[\begin{align*} & \sum_{p \in \mathcal{P}_c} Y_{c,p} = 1 && \forall c \in \mathcal{C} \\ & \sum_{t \in \mathcal{T}_s} X_{s,t,p} = Y_{c,p} && \forall c \in \mathcal{C}, p \in \mathcal{P}_c, s \in \mathcal{S}_c \end{align*}\]
\[\begin{align*} & \sum_{p \in \mathcal{P}_r}\sum_{s \in \mathcal{S}_p} n_s \times X_{s,t-a_{p,r},p} = b_{r,t}\times U_{r,t} && \forall r \in \mathcal{R}, t \in \mathcal{T} \\ & U_{r,t} - U_{r,t-1} \leq \sigma_r && \forall r \in \mathcal{R}, t \in \mathcal{T}: t > 1 \\ & U_{r,t-1} - U_{r,t} \leq \sigma_r && \forall r \in \mathcal{R}, t \in \mathcal{T}: t > 1 \end{align*}\]
Restricting the relative utilization of each resource to a certain bound.
\[\begin{align*} & X_{s,t,p} \in \{0,1\} && \forall s \in \mathcal{S}, t \in \mathcal{T}_s, p \in \mathcal{P}_s \\ & Y_{c,p} \in \{0,1\} && \forall c \in \mathcal{C}, p \in \mathcal{P}_c \\ & U_{r,t} \in [0,1] && \forall r \in \mathcal{R}, t \in \mathcal{T} \end{align*}\]
All variables, except for \(U_{r,t}\), are binary.
Questions: On model characteristics
Questions: On model assumptions
Capacities are hard limits: if demand exceeds them, the model becomes infeasible and refuses to produce an unsafe plan. This is a feature, not a bug!



Optimization was part of a project by Knut Haase and his team (Haase et al. 2016).

We now have covered a scheduling problem based on a real-world application and are ready to start solving some new tasks in the upcoming tutorial.
To learn more about the project and crowd management during the Hajj, take a look at Haase et al. (2016) and the literature list of this course.