Update Route
This example demonstrates how to update an existing route by making changes to its configuration, vehicle constraints, and other fields. The updated route can also be reoptimized to generate a new order of visits. If the route is not reoptimized, the changes will not affect the route's optimization. However, certain configuration changes (e.g., ignoring time windows, optimization criteria, etc.) automatically trigger reoptimization.
For updating orders, refer to the following examples:
When you run the example application:
- The existing route is updated with new configurations, vehicle constraints, and other fields.
- The route is reoptimized (if specified), and a new order of visits is returned.
Retrieve the Existing Route
To update a route, you first need to retrieve the existing route using its ID.
- Create a
ProgressListenerandvrp::Service. - Retrieve the route using the
getRoute()method from thevrp::Service.
Update the Route
Once the route is retrieved, you can update its fields, such as configuration parameters, vehicle constraints, and other properties.
Update Configuration Parameters
- Retrieve the existing configuration parameters from the route.
- Modify the desired fields, such as the name and route type.
Update Vehicle Constraints
- Retrieve the existing vehicle constraints from the route.
- Modify the desired fields, such as the maximum number of packages and maximum distance.
Apply the Updates to the Route
- Set the updated configuration parameters and vehicle constraints to the route.
Update the Route and Retrieve the New Solution
Once the route is updated, you can apply the changes and retrieve the new solution.
- Create a
std::shared_ptr<gem::vrp::Request>to hold the update request. - Call the
updateRoute()method from thevrp::Service, passing the updated route, the request, and theProgressListener. - Wait for the update process to complete.
Retrieve the Updated Route
After the update process is complete, you can retrieve the updated route.
- Create a new
vrp::Routeobject to hold the updated route. - Call the
getRoute()method from thevrp::Serviceto populate thevrp::Routeobject with the updated route.