Skip to main content

Depot Selection

The VRP solver can dynamically select the best depot for each trip based on proximity, cost, waste stream compatibility, and operating hours. Instead of pre-assigning fixed locations, the solver evaluates multiple candidate sites and picks the optimal one per trip.

Overview

Depot selection is essential for waste collection, logistics with intermediate stops, and any scenario where vehicles must visit a facility mid-route to unload. The solver supports:
  • Multiple depots with different locations, costs, and capacities
  • Operating hours as time windows on each depot
  • Per-dimension capacity for selective unloading (e.g., tip only one compartment)
  • Cost-based trade-offs between routing efficiency and cost
Depots are optional. When no depots are provided, the solver operates in standard routing mode. Adding depots enables the solver to automatically insert depot visits into routes where beneficial.

Basic Configuration

Define your depot in the depots array of the request. Each depot has a location, service duration, and capacity:
When you omit capacity, the depot defaults to unlimited capacity across all load dimensions — vehicles unload all compartments. To restrict which compartments are unloaded, provide an explicit capacity array where 0 means “do not unload this dimension”.

Depot Fields

Operating Hours

Restrict when depots accept visits by adding time windows. The solver treats depot time window violations as hard constraints — it avoids scheduling visits outside operating hours.
If all depots have restrictive time windows and vehicle shifts extend beyond those hours, late collections may not be able to visit any depot. Ensure at least one depot’s operating hours covers the full shift duration.

Cost-Based Depot Selection

Assign a per-visit cost to each depot to model disposal fees. The solver balances routing efficiency against disposal cost — it may choose a more distant but cheaper depot when the savings justify the extra travel.

Tuning the Cost Trade-Off

Control how aggressively the solver avoids expensive depots using the depotCostWeight in the weights configuration:

Multi-Compartment Unloading

Depots support per-dimension capacity, enabling selective unloading. When a vehicle visits a depot, only the load dimensions where the depot has capacity (> 0) are reset.
In this example:
  • general-waste-tip only accepts dimension 0 (general waste). When a vehicle visits, only the first compartment is unloaded.
  • recycling-center accepts dimensions 1 and 2 (recyclables). The vehicle keeps its general waste loaded.
A depot with capacity: [0, 0, 0] for a given dimension means that compartment is not unloaded at that depot. This enables independent compartment tipping.

Forcing a Depot Visit Before End of Shift

By default, the solver may finish a route by driving directly to the shift end location while the vehicle still carries load. For waste collection and similar workflows, this is rarely the desired behavior — the truck should drop its load at a depot before parking. Set unloadBeforeEndShift: true on a shift to require a depot stop after the shift’s last job whenever the vehicle still has non-zero load. The flag lives on the shift (not on the resource) so different shifts of the same resource can have different end-of-shift policies.
The constraint is load-aware: if the route’s last job leaves the vehicle empty (e.g., a balanced pickup-and-delivery route, or a route where every job carries load: [0]), no depot detour is forced. It is also gated on having depots configured — if the request contains no depots, the flag is dormant and produces no violation.

Constraints

The solver enforces four depot-related constraints: These appear in the violations section of the response when active.

Real-World Example: Waste Collection

A complete waste collection request with 3 waste streams, strict load compatibility, and geographically distributed depots:
Combine depots with load compatibility to enforce per-trip waste stream segregation. The solver ensures each trip collects only one waste type and visits an appropriate depot to unload.

Load Compatibility

Restrict which load types can coexist on a vehicle per trip

Capacity Management

Configure multi-dimensional vehicle capacity constraints

Cost Optimization

Set up cost-based optimization with financial trade-offs

Break Management

Configure driver breaks and rest periods