Fuel Prices
Overview
The Fuel Prices class allows users to manage fuel prices for different fuel types within the VRP system. This API is essential for calculating accurate fuel costs for vehicles, especially when optimizing routes. The API provides endpoints to:
- Set fuel prices for different fuel types.
- Retrieve fuel prices along with the time they were last updated.
Fuel Price Structure
The fuel price structure consists of the following components:
FuelPricePair
Each FuelPricePair represents a fuel type and its corresponding price.
| Name | Type | Description |
|---|---|---|
| fuel | EFuelType | The type of fuel. |
| price | float | The price of one liter of fuel or one kWh (for electric vehicles). |
FuelPrices
The FuelPrices structure contains a list of FuelPricePair elements and the time when the prices were added.
| Name | Type | Description |
|---|---|---|
| fuelPrices | FuelPricePairList | A list of fuel prices, one for each fuel type. |
| additionTime | Time | The time when the fuel prices were added. |
Managing Fuel Prices
1. Setting Fuel Prices
Set the desired prices for each fuel type. The time will be automatically updated if the operation is successful.
How it works
- Create a
FuelPricesobject and populate thefuelPriceslist withFuelPricePairelements for each fuel type. - Create a
ProgressListenerandvrp::Service. - Call the
addFuelPrices()method from thevrp::Serviceusing theFuelPricesobject andProgressListener. - Wait for the operation to complete.
Example
2. Retrieving Fuel Prices
Get all the changes of the fuel prices and when they were made.
The first one in the list is the most recent change. All the routes created after this change will use these prices to calculate the cost.
How it works
- Create a
ProgressListener, avrp::Service, and aFuelPricesList. - Call the
getFuelPrices()method from thevrp::Serviceusing theFuelPricesListandProgressListener. - Once the operation completes, the
FuelPricesListwill be populated with all fuel prices that was added.
Example
Error Handling
This API returns specific error codes to indicate potential issues. Below is a summary of common errors and how to resolve them:
| Error Code | Description | Solution |
|---|---|---|
KInvalidInput | Missing required fields or invalid fuel price data. | Ensure all mandatory fields are properly filled. |
KInternalAbort | Server-side issue or unexpected parsing error. | Retry the request or check API status. |