Vehicle cost
In the Vehicle Routing Problem (VRP), Vehicle Cost is a fixed, one-time cost that is added to the total solution cost for each vehicle that is used to serve one or more orders. Think of it as an "activation fee" for deploying a vehicle.
The primary purpose of vehicle_cost is to give the optimization engine a crucial tool to decide whether it's more economical to add a new vehicle to the route or to extend the route of an existing, already-active vehicle. The solver's main goal is to find the solution with the lowest possible total cost, which is a sum of travel costs, penalties, and the vehicle_cost for every vehicle used.
How It Impacts Planning
The vehicle_cost creates a fundamental trade-off for the solver:
- Cost to Add a New Vehicle: The fixed
vehicle_cost. - Cost to Extend an Existing Route: The additional travel time and distance cost incurred by adding more stops to a vehicle that is already in use.
The solver will always choose the cheaper option.
- High
vehicle_cost: If the cost to activate a vehicle is high, the solver will strongly prefer to fit as many orders as possible onto the vehicles that are already active. It will create longer, more complex routes to avoid paying the high price of deploying another vehicle. - Low
vehicle_cost: If the cost is low, the solver will be more willing to deploy additional vehicles if it results in more efficient individual routes (e.g., shorter travel times).
Use Case: Prioritizing Your Own Fleet
A common use case is managing a mixed fleet of owned vehicles and more expensive subcontracted vehicles.
- Your Fleet: Assign a low
vehicle_cost(e.g.,1000). - Subcontractor Fleet: Assign a high
vehicle_cost(e.g.,50000).
With this setup, the optimizer will always prioritize using your own vehicles. It will only "activate" a subcontractor's vehicle if it has exhausted all feasible options with your internal fleet, correctly modeling the real-world cost difference.
Setting the Right vehicle_cost
The value of vehicle_cost should be set in relation to your other operational costs, primarily travel costs.
- Guideline: The
vehicle_costshould represent the cost you are willing to pay to avoid a certain amount of extra travel. For example, if yourvehicle_costis10000, the solver will be willing to add up to for example,10000seconds (approx. 2.78 hours) of extra driving time to an existing route to avoid using a new vehicle. - Typical Range: A value between 0 and 50,000 is a common starting point. However, this can be much higher if your travel costs are significant due to long distances or times.
Special Considerations
CVRPTW Mode
When using prebook_cvrptw mode, you must use vehicle_cost with caution. In this mode, vehicles are often pre-configured with a partial_route to a depot for loading. This can cause the solver to assume all vehicles are already "in use," making the vehicle_cost ineffective for minimizing the fleet size.
To solve this, set the vehicle property zero_cost_if_only_partial_routes to true.
"vehicles": [
{
"agent_id": "some-vehicle-id",
"vehicle_cost": 10000,
"zero_cost_if_only_partial_routes": true,
"partial_route": ["depot_node_uid"],
...
}
]
This flag tells the solver not to apply the vehicle_cost if the vehicle only serves its pre-assigned partial route and is not assigned any new orders.
PDP Mode
In prebook (PDP) mode, vehicle_cost can also have side effects if not configured carefully. Since vehicle starting positions are also defined as nodes in a partial_route, the solver might incorrectly apply the cost. If you observe that the solver is not correctly minimizing the number of vehicles used, you may need to adjust the vehicle_cost value or review your partial_route setup to ensure it accurately reflects which vehicles are truly "inactive" at the start of the optimization.
Implementation in SWAT APIs
The vehicle_cost is a parameter on the vehicle object in the Stateless API. You can also set a default vehicle_costs in the model_parameters.
Vehicle-specific cost (overrides default cost for all vehicles):
"vehicles": [
{
"agent_id": "owned-vehicle-01",
"vehicle_cost": 1000,
...
},
{
"agent_id": "subcontractor-vehicle-01",
"vehicle_cost": 50000,
...
}
]
Default cost for all vehicles:
}
}
Playground
You can try out the Vehicle Cost concept using the playground below. The example defines two vehicles: one "Cheap" (cost 100) and one "Expensive" (cost 10000). Observe how the solver prioritizes the cheaper vehicle for the assigned jobs.