{
  "resources": [
    {
      "name": "employee-driver",
      "hourlyCost": 25,  // $25/hour
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    },
    {
      "name": "contractor-driver",
      "hourlyCost": 45,  // $45/hour
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ],
  "jobs": [
    {
      "name": "delivery-1",
      "duration": 1800
    }
  ]
}
{
  "solution": {
    "routes": [...],
    "summary": {
      "totalCost": 1250.50,
      "costBreakdown": {
        "fixedCosts": 300,      // Activation costs
        "variableCosts": 850.50, // Hourly costs
        "penaltyCosts": 100     // Constraint violations
      },
      "resourceCosts": {
        "driver-1": {
          "activationCost": 100,
          "hourlyCost": 240,
          "overtimeCost": 30,
          "totalCost": 370
        },
        "driver-2": {
          "activationCost": 100,
          "hourlyCost": 200,
          "overtimeCost": 0,
          "totalCost": 300
        }
      }
    }
  }
}

Cost Optimization

The VRP solver provides comprehensive cost modeling to optimize your routing operations based on real business constraints. This guide covers various cost types, urgency handling, and optimization strategies.

Cost Types Overview

The solver considers multiple cost components when optimizing routes:
Total Cost = Fixed Costs + Variable Costs + Penalty Costs
  • Fixed Costs: Activation costs for using resources
  • Variable Costs: Time-based costs (hourly rates, overtime)
  • Penalty Costs: Violations of soft constraints

Resource Cost Configuration

Hourly Costs

Configure time-based costs for resources:
{
  "resources": [
    {
      "name": "employee-driver",
      "hourlyCost": 25,  // $25/hour
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    },
    {
      "name": "contractor-driver",
      "hourlyCost": 45,  // $45/hour
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ],
  "jobs": [
    {
      "name": "delivery-1",
      "duration": 1800
    }
  ]
}
Hourly costs apply to the entire shift duration, not just driving time. Consider using activation costs if you only want to charge for actual usage.

Activation Costs

Fixed costs incurred when a resource is used:
{
  "resources": [
    {
      "name": "rental-truck",
      "activationCost": 150,  // $150 fixed cost if used
      "hourlyCost": 0,      // No hourly charge
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    },
    {
      "name": "owned-vehicle",
      "activationCost": 50,   // $50 daily operating cost
      "hourlyCost": 15,      // $15/hour driver cost
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ],
  "jobs": [
    {
      "name": "job-1",
      "duration": 1800
    }
  ]
}

Cost Calculation Examples

{
  "name": "full-time-driver",
  "hourlyCost": 30,
  "activationCost": 0
}
8-hour shift cost: 8 × 30=30 = 240 Used or not: Same cost (salaried)

Travel Cost Optimization

Travel Time Weights

Control the importance of minimizing travel time:
{
  "options": {
    "weights": {
      "travelTimeWeight": 1.0,  // Standard weight
      "travelDistanceWeight": 0  // Ignored by default
    }
  }
}
travelTimeWeight
number
default:"1.0"
Multiplier for travel time in the objective function. Higher values prioritize shorter travel times.
travelDistanceWeight
number
default:"0"
Multiplier for travel distance. Set > 0 to optimize for distance instead of time.

Balancing Travel vs Other Objectives

{
  "weights": {
    "travelTimeWeight": 10.0,
    "waitTimeWeight": 1.0,
    "urgencyWeight": 1.0
  }
}

Urgency-Based Optimization

Basic Urgency Scoring

Prioritize time-sensitive jobs:
{
  "jobs": [
    {
      "name": "critical-repair",
      "urgency": 100,  // Highest priority
      "location": {"latitude": 52.520, "longitude": 13.405},
      "duration": 3600
    },
    {
      "name": "routine-maintenance",
      "urgency": 10,   // Lower priority
      "location": {"latitude": 52.520, "longitude": 13.405},
      "duration": 1800
    }
  ],
  "resources": [
    {
      "name": "technician-1",
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ],
  "weights": {
    "urgencyWeight": 50  // Strong urgency preference
  }
}
urgency
integer
default:"0"
Priority score from 0-100. Higher values are scheduled earlier.

Urgency Calculation Formula

Urgency Impact = urgency × urgencyWeight × time_until_scheduledThis creates increasing pressure to schedule urgent jobs sooner.

ASAP Scheduling

Schedule jobs as soon as possible across multiple days:
{
  "jobs": [
    {
      "name": "flexible-task-1",
      "dayIndex": 0,  // Available from day 1
      "windows": [
        {"from": "2024-03-15T08:00:00Z", "to": "2024-03-15T17:00:00Z"},
        {"from": "2024-03-16T08:00:00Z", "to": "2024-03-16T17:00:00Z"},
        {"from": "2024-03-17T08:00:00Z", "to": "2024-03-17T17:00:00Z"}
      ]
    },
    {
      "name": "flexible-task-2",
      "dayIndex": 1,  // Available from day 2
      "windows": [
        {"from": "2024-03-16T08:00:00Z", "to": "2024-03-16T17:00:00Z"},
        {"from": "2024-03-17T08:00:00Z", "to": "2024-03-17T17:00:00Z"}
      ]
    }
  ],
  "resources": [
    {
      "name": "driver-1",
      "shifts": [
        {
          "from": "2024-03-15T08:00:00Z",
          "to": "2024-03-15T17:00:00Z"
        },
        {
          "from": "2024-03-16T08:00:00Z",
          "to": "2024-03-16T17:00:00Z"
        },
        {
          "from": "2024-03-17T08:00:00Z",
          "to": "2024-03-17T17:00:00Z"
        }
      ]
    }
  ],
  "weights": {
    "asapWeight": 100  // Strong ASAP preference
  }
}

DayIndex Strategy

1

Set dayIndex

dayIndex: 0 = available immediately dayIndex: 1 = available from day 2 dayIndex: 2 = available from day 3
2

Configure Weight

Higher asapWeight = stronger preference for early scheduling
3

Combine with Urgency

{
  "urgency": 80,
  "dayIndex": 0
}

Optimization Strategies

Strategy 1: Cost Minimization

Focus on reducing operational costs:
{
  "resources": [
    {
      "name": "efficient-vehicle",
      "hourlyCost": 20,
      "activationCost": 100,
      "capacity": [1000],
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    },
    {
      "name": "large-vehicle",
      "hourlyCost": 35,
      "activationCost": 150,
      "capacity": [2000],
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ],
  "jobs": [
    {
      "name": "delivery-1",
      "load": [800]
    }
  ],
  "weights": {
    "travelTimeWeight": 0.5,  // Less important
    "activationWeight": 2.0   // Minimize vehicle use
  }
}

Strategy 2: Service Level Optimization

Prioritize customer satisfaction:
{
  "resources": [
    {
      "name": "technician-1",
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ],
  "jobs": [
    {
      "name": "service-1",
      "urgency": 90,
      "duration": 3600
    }
  ],
  "weights": {
    "urgencyWeight": 100,        // Honor priorities
    "windowWeight": 50,          // Meet time preferences
    "waitTimeWeight": 20,        // Minimize customer waiting
    "preferredResourceWeight": 30 // Use preferred technicians
  }
}

Strategy 3: Balanced Optimization

{
  "resources": [
    {
      "name": "driver-1",
      "shifts": [{
        "from": "2024-03-15T08:00:00Z",
        "to": "2024-03-15T17:00:00Z"
      }]
    }
  ],
  "jobs": [
    {
      "name": "job-1",
      "duration": 1800
    }
  ],
  "weights": {
    // Cost factors
    "travelTimeWeight": 1.0,
    "activationWeight": 1.0,
    "overtimeWeight": 50,
    
    // Service factors
    "urgencyWeight": 10,
    "windowWeight": 10,
    
    // Fairness factors
    "fairWorkloadPerResource": 5,
    "fairWorkloadPerTrip": 5
  }
}

Cost Analysis in Results

The solution provides detailed cost breakdowns:
{
  "solution": {
    "routes": [...],
    "summary": {
      "totalCost": 1250.50,
      "costBreakdown": {
        "fixedCosts": 300,      // Activation costs
        "variableCosts": 850.50, // Hourly costs
        "penaltyCosts": 100     // Constraint violations
      },
      "resourceCosts": {
        "driver-1": {
          "activationCost": 100,
          "hourlyCost": 240,
          "overtimeCost": 30,
          "totalCost": 370
        },
        "driver-2": {
          "activationCost": 100,
          "hourlyCost": 200,
          "overtimeCost": 0,
          "totalCost": 300
        }
      }
    }
  }
}

Understanding Cost Components

Advanced Cost Scenarios

Peak Hour Pricing

Different costs for different times:
{
  "resources": [
    {
      "name": "peak-driver",
      "shifts": [
        {
          "from": "2024-03-15T06:00:00Z",
          "to": "2024-03-15T10:00:00Z",
          "hourlyCost": 35  // Morning peak rate
        },
        {
          "from": "2024-03-15T10:00:00Z",
          "to": "2024-03-15T15:00:00Z",
          "hourlyCost": 25  // Standard rate
        },
        {
          "from": "2024-03-15T15:00:00Z",
          "to": "2024-03-15T19:00:00Z",
          "hourlyCost": 35  // Evening peak rate
        }
      ]
    }
  ],
  "jobs": [
    {
      "name": "delivery-1", 
      "duration": 1800
    }
  ]
}

Multi-Objective Optimization

Balance competing objectives:
{
  "options": {
    "objectives": [
      {
        "name": "minimize_cost",
        "weights": {
          "travelTimeWeight": 1.0,
          "activationWeight": 2.0
        }
      },
      {
        "name": "maximize_service",
        "weights": {
          "urgencyWeight": 100,
          "windowWeight": 50
        }
      }
    ],
    "objectiveBalance": 0.6  // 60% cost, 40% service
  }
}

Performance Tips

Cost Calculation Performance:
  • Complex cost models increase computation time
  • Many soft constraints require more iterations
  • Large weight differences can cause instability
Recommendations:
  • Keep weights in reasonable ratios (1:100 max)
  • Use hard constraints where possible
  • Profile different weight combinations

Best Practices

1

Start with Defaults

Begin with default weights and adjust based on results
2

Measure Impact

Track these metrics:
  • Total operational cost
  • Cost per delivery/service
  • Resource utilization rates
  • Customer satisfaction scores
3

Iterate and Refine

  • Adjust weights based on business priorities
  • Monitor unintended consequences
  • Document weight configurations
4

Consider Trade-offs

  • Lower costs vs better service
  • Fewer vehicles vs more overtime
  • Urgency vs efficiency

Troubleshooting