"The Vehicle Routing Problem isn't just about efficiency—it's about saving lives by putting the right resources in the right places at the right times."
Operations research transforms predictions into action. Given a set of high-risk locations identified by our machine learning model, how should we deploy limited patrol resources? This is the Vehicle Routing Problem (VRP)—one of the most studied problems in combinatorial optimization.
The VRP Solution
Our OR-Tools solver found an optimal solution assigning 33 high-risk locations to three patrol vehicles with a total distance of 311 units. This represents the mathematically proven minimum travel distance for complete coverage.
Problem Formulation
The Capacitated VRP adds constraints to ensure no single patrol unit is overloaded. Each location has a "demand" (based on risk score), and each vehicle has limited capacity.
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
# Create routing index manager
manager = pywrapcp.RoutingIndexManager(
len(distance_matrix),
num_vehicles,
depot_index
)
# Create routing model
routing = pywrapcp.RoutingModel(manager)
# Define distance callback
def distance_callback(from_index, to_index):
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
return distance_matrix[from_node][to_node]
transit_callback_index = routing.RegisterTransitCallback(distance_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
# Add capacity constraint
demand_callback_index = routing.RegisterUnaryTransitCallback(
lambda index: demands[manager.IndexToNode(index)]
)
routing.AddDimensionWithVehicleCapacity(
demand_callback_index,
0, # null slack
vehicle_capacities,
True, # start cumul to zero
'Capacity'
)
Route Assignments
The solver assigned locations to vehicles based on geographic proximity and risk balancing:
| Vehicle | Locations | Distance | Coverage Area |
|---|---|---|---|
| Unit 1 | 12 | 108 | Roxbury / Mattapan |
| Unit 2 | 11 | 97 | Downtown / South End |
| Unit 3 | 10 | 106 | Dorchester / South Boston |
Notice how the solver balanced workload across vehicles. Unit 1 covers more locations but with shorter distances between them; Unit 2 covers fewer locations spread over a wider area. This balance prevents fatigue and ensures equitable coverage.
Solution Quality
OR-Tools uses metaheuristics to explore the solution space efficiently. We employed Guided Local Search with simulated annealing to escape local optima.
# Search parameters
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
search_parameters.first_solution_strategy = (
routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC
)
search_parameters.local_search_metaheuristic = (
routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH
)
search_parameters.time_limit.seconds = 30
# Solve
solution = routing.SolveWithParameters(search_parameters)
# Status: ROUTING_SUCCESS (optimal found)
Real-World Considerations
Our model optimizes for distance, but real patrol routing must consider:
- Time windows: Some locations need coverage at specific hours
- Traffic patterns: Distance ≠ travel time
- Dynamic re-routing: Responding to incidents in progress
- Shift changes: Handoff logistics between crews
- Break times: Legal requirements for officer rest
This demonstration uses simplified assumptions. Production deployment would require integration with real-time traffic data, CAD (Computer-Aided Dispatch) systems, and continuous model retraining as crime patterns shift.
The Complete Pipeline
Bringing it all together, our system flows from raw data to actionable routes:
- Data ingestion: 848,051 historical incidents
- Spatial analysis: iGraph network modeling
- Temporal encoding: Cyclical time features
- ML prediction: LightGBM DART violence risk scores
- Location selection: Top 33 high-risk areas
- Route optimization: OR-Tools VRP solver
- Deployment: Patrol assignments by vehicle
Conclusion
This investigation demonstrates that modern data science can meaningfully improve public safety resource allocation. By combining machine learning prediction with operations research optimization, we created a system that is both analytically rigorous and practically deployable.
The geography of fear is not destiny. With the right tools and transparent methods, we can respond smarter, deploy fairer, and ultimately build safer communities.