CVRPSolver
Sovereign Physical Distribution Platform · Cluster Node
Mathematical Capacitated Vehicle Routing Problem (CVRP) solver powered by Google OR-Tools with time-windows, volumetric constraints, and road-network distance matrices.
Pegasus solves complex combinatorial vehicle routing problems every morning across thousands of retail stops. The engine models multi-compartment vehicle volumes, maximum shift durations, store operating time-windows, vehicle turning radius restrictions, and live traffic forecasts to minimize total fleet kilometers and fuel burn.
Architecture & Performance Highlights
Google OR-Tools Core
Solves 1,500 delivery stops across 60 trucks in under 8 seconds using parallel Guided Local Search.
Multi-Capacity Constraints
Simultaneously balances gross payload weight (kg) and volumetric cube (m³) against vehicle capacity.
Time-Window Windows
Guarantees deliveries occur within store delivery hours, penalizing late arrivals with soft/hard bounds.
CVRP Optimization Pipeline
Sequence Flow1. Ingestion: Filter vetted orders for target warehouse and delivery shift
2. Distance Matrix: Compute OSRM travel durations and distances across all stop pairs
3. Model Formulation: Initialize Google OR-Tools RoutingModel with vehicle dimension constraints
4. Initial Solution: Parallel Cheapest Insertion heuristic generates seed solution
5. Metaheuristic Search: Guided Local Search (GLS) iteratively explores neighbor solutions
6. Assignment: Write optimal vehicle manifests to Spanner with route geo-polylines
Code & Configuration References
Go CVRP Optimizer Service Binding
package routing
import (
"context"
"time"
"github.com/pegasus/engine/ortools"
)
type RouteRequest struct {
WarehouseID string `json:"warehouse_id"`
Stops []DeliveryStop `json:"stops"`
Vehicles []VehicleCapacity `json:"vehicles"`
}
func (s *Solver) SolveCVRP(ctx context.Context, req RouteRequest) (*RouteSolution, error) {
matrix, err := s.osrmClient.GetDistanceMatrix(ctx, req.Stops)
if err != nil {
return nil, err
}
params := ortools.DefaultParameters()
params.TimeLimit = 10 * time.Second
params.Metaheuristic = ortools.GuidedLocalSearch
return ortools.Solve(matrix, req.Vehicles, params)
}Pre-computed Distance Matrix Caching
Distance and duration pairs between frequently visited retail clusters are cached in Redis with a 24-hour TTL, reducing solver latency by up to 70%.
Keep Exploring Pegasus Architecture & Operations
Based on the invariants, physical actors, and data flows of this module, explore these recommended companion guides and operational playbooks.
Warehouse Hub Operations
Warehouse dispatchers view, adjust, and approve the CVRP solution on the interactive dispatch board.
Mid-Shift Breakdown & Swap
How the CVRP solver re-computes sub-routes when a vehicle breaks down mid-route.
Transactional Outbox & Bus
Route assignment results are published to Kafka to update driver and warehouse apps in real time.
