Pegasus Logo
跳转到主体内容
PegasusDocs
OR-TOOLS ENGINE

CVRPSolver

Sovereign Physical Distribution Platform · Cluster Node

v4.2.0
·
Last updated September 2026
·
11 min read

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

<8s Solve

Google OR-Tools Core

Solves 1,500 delivery stops across 60 trucks in under 8 seconds using parallel Guided Local Search.

Dual Capacity

Multi-Capacity Constraints

Simultaneously balances gross payload weight (kg) and volumetric cube (m³) against vehicle capacity.

Strict Windows

Time-Window Windows

Guarantees deliveries occur within store delivery hours, penalizing late arrivals with soft/hard bounds.

CVRP Optimization Pipeline

Sequence Flow
1

1. Ingestion: Filter vetted orders for target warehouse and delivery shift

2

2. Distance Matrix: Compute OSRM travel durations and distances across all stop pairs

3

3. Model Formulation: Initialize Google OR-Tools RoutingModel with vehicle dimension constraints

4

4. Initial Solution: Parallel Cheapest Insertion heuristic generates seed solution

5

5. Metaheuristic Search: Guided Local Search (GLS) iteratively explores neighbor solutions

6

6. Assignment: Write optimal vehicle manifests to Spanner with route geo-polylines

Code & Configuration References

Go CVRP Optimizer Service Binding
cvrp_solver.go
go
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%.