w = [1, 2, 8, 3, 1, 1, 5] # incidents per area
driving(i) = sum(w[j] * abs(i - j) for j in 1:7) # department in area i
println(driving.(1:7))[66, 47, 32, 33, 40, 49, 60]
Applied Optimization with Julia
After this lecture, you can:
Question: What makes the work of emergency services complex?

Emergency services address the needs of three interest groups:
Question: What could be the objectives of these groups?
Aligning the objectives of the three interest groups is challenging.

Question: Why might current district layouts be suboptimal?
Question: What data can help improve emergency services?
Extensive data collected, but often lack of tools or knowledge to leverage it.
For an efficient and effective distribution of resources, police jurisdictions are divided into precincts or command districts with separate departments. These are further divided into patrol beats (D’Amico et al. 2002).
Part of the force patrols the streets, another part is stationed at the departments.
Question: Which car do you send?
Question: What could be the potential problem?
This is a common problem in many emergency services.
Question: What affects response time?
Aggregation of small geographic areas, called basic areas (BAs), into geographic clusters, called districts, so that these are acceptable according to pre-defined planning criteria1.
Territory design is a general framework applicable to many domains: emergency services, sales territories, political districts, school districts, etc.
Question: What are the key components?
In our police case: BAs are hexagonal cells, districts are service areas for police departments.
Balance Criteria:
Geographic Criteria:
These criteria often conflict with each other… Optimization helps find the best trade-off!
Question: Where else is this used?
Same mathematical structure, different objectives and constraints!
Question: What could be the objective?
Question: What could be further objectives?
Question: How can we model response time?
We focus on minimizing expected driving times between departments and incident locations.
Question: What could be our key model components?
Question: Which are sets, parameters, and variables?
Question: How do we model this mathematically?
This abstraction allows us to use optimization techniques from graph theory and location science!
Question: What sets do we need?
Department locations are a subset of all BAs as not every BA can host a department!
Question: Advantages of hexagons?
Question: What parameters do we need?
Parameters should be carefully calibrated with real-world data!
Minimize the expected response time of the emergency services by optimizing the assignment of BAs to departments.
Question: What decisions do we need to model?
Question: What is the domain of our decision variable?
Minimize the expected response time of the emergency services by optimizing the assignment of BAs to departments.
Question: How do we minimize response time?
Question: What could be our objective function?
\[ \text{Minimize} \quad \sum_{i \in \mathcal{I}}\sum_{j \in \mathcal{J}} w_j \times t_{i,j} \times X_{i,j} \]
Question: Constraints needed?
Question: Why do we need this constraint?
Question: What could the constraint look like?
\[ \sum_{i \in \mathcal{I}} X_{i,j} = 1 \quad \forall j \in \mathcal{J} \]
Each BA must be assigned to exactly one department.
Ensure that exactly \(p\) departments are opened.
Question: What does the variable \(X_{i,i}\) stand for?
Many textbooks use a separate variable \(Y_i\) to model opening a facility. Using the “diagonal” \(X_{i,i}\) instead saves these extra variables. Both formulations are equivalent here.
Question: What could the constraint look like?
\[ \sum_{i \in \mathcal{I}} X_{i,i} = p \]
Question: What happens if we have more departments than potential locations?
Ensure that each BA is assigned to an active department, e.g. a department that is opened and that could dispatch vehicles.
Question: How do we ensure assignments only to active departments?
\[ X_{i,j} \leq X_{i,i} \quad \forall i \in \mathcal{I}, j \in \mathcal{J} \]
This constraint creates a logical connection between department locations and BA assignments where BAs can only be assigned to opened departments.
\[\begin{align} \text{Minimize} \quad & \sum_{i \in \mathcal{I}}\sum_{j \in \mathcal{J}} w_j \times t_{i,j} \times X_{i,j} \\ \text{subject to:} \quad & \sum_{i \in \mathcal{I}} X_{i,j}= 1 && \forall j \in \mathcal{J} \\ & \sum_{i \in \mathcal{I}} X_{i,i} = p && \\ & X_{i,j} \leq X_{i,i} && \forall i \in \mathcal{I}, j \in \mathcal{J} \\ & X_{i,j} \in \{0,1\} && \forall i \in \mathcal{I}, j \in \mathcal{J} \end{align}\]
Seven areas along one road, one department, and the driving time between two areas is how many steps apart they are:
w = [1, 2, 8, 3, 1, 1, 5] # incidents per area
driving(i) = sum(w[j] * abs(i - j) for j in 1:7) # department in area i
println(driving.(1:7))[66, 47, 32, 33, 40, 49, 60]
Area 3 is the weighted median: no more than half of the incidents lie on either side of it.
Question: How does this relate to these problems?
p-Median Problem:
Similar problems:
Our police districting is a p-Median variant with additional geographic constraints (contiguity, compactness)!
Question: Why is contiguity important?
Compactness has no univocal definition; a district is commonly declared compact if it is ‘somehow round-shaped and undistorted’ (Kalcsics et al. 2005).
Question: Are our resulting districts based on the model contiguous and compact?
Question: Is this likely for police service districting?
Additional Set and Parameter
\[ \mathcal{N}_{i,j}=\{v \in \mathcal{A}_j | e_{i,v} < e_{i,j}\} \quad \forall i\in \mathcal{I}, j\in \mathcal{J} \]
BAs closer to department \(i\) than BA \(j\) in Euclidean distance and adjacent to \(j\)!
On a complete hexagonal grid, this cannot happen: one neighbor of \(j\) is always strictly closer to \(i\). But real-world maps with holes, concave boundaries, or irregular BAs can produce ties!
Department \(i\) and BA \(j\): which neighbors of \(j\) are closer to \(i\)?
All three highlighted BAs \(v\) are adjacent to \(j\) and closer to \(i\): \(|\mathcal{N}_{i,j}| = 3\).
Same department \(i\), but BA \(j\) now lies at the edge of the grid.
Here, only two neighbors of \(j\) are closer to \(i\): \(|\mathcal{N}_{i,j}| = 2\).
All districts have to be contiguous
\[ X_{i,j} \leq \sum_{v \in \mathcal{N}_{i,j}} X_{i,v} \quad \forall i \in \mathcal{I}, j \in \mathcal{J} \setminus \mathcal{A}_i: i \neq j \]
If BA \(j\) is assigned to department \(i\), then at least one BA that is adjacent to \(j\) and closer to \(i\) must also be assigned to department \(i\)!
All districts have to be contiguous and compact
\[\begin{align*} X_{i,j} &\leq \sum_{v \in \mathcal{N}_{i,j}}X_{i,v} && \forall i \in \mathcal{I}, j \in \mathcal{J} \setminus \mathcal{A}_i:|\mathcal{N}_{i,j}|= 1 \wedge i \neq j \\ 2X_{i,j} &\leq \sum_{v \in \mathcal{N}_{i,j}}X_{i,v} && \forall i \in \mathcal{I}, j \in \mathcal{J} \setminus \mathcal{A}_i:|\mathcal{N}_{i,j}|> 1 \wedge i \neq j \end{align*}\]
If BA \(j\) is assigned to department \(i\), then at least two BAs that are adjacent to \(j\) and closer to \(i\) must also be assigned to department \(i\), if \(|\mathcal{N}_{i,j}| > 1\)!
Due to the constraints, there is always a path back to the department if a BA is assigned to a department! Contiguity alone still allows the “snake” on the left; the compactness constraint cuts off such shapes (middle, right).
Question: Is the model formulation linear or non-linear?
Question: What kind of variable domains do we have?
Question: Can the model be solved quickly?
Question: Have we prevented isolated districts?
Questions: On model assumptions
Question: Where did we apply our model?
Goal: Redesign districts to improve response time.
Goal: Optimize coverage with limited resources.
How did we validate the results?
All improvements are without additional staff!
Question: Our model only minimizes driving time. Where does the better workload distribution come from?
Think about it: how could you add an explicit workload balancing constraint with our parameters \(w_j\) and \(t_{i,j}\)?
Success requires balancing theoretical optimization with practical constraints!
Question: Where else could this approach be useful?
The methodology is adaptable to various public service optimization scenarios.
We now have covered districting problems and are ready to start solving some tasks in the upcoming tutorial.
For more interesting literature to learn more about Julia, take a look at the literature list of this course.