Reoptimize Route
This example demonstrates how to reoptimize an existing route to rearrange the orders in a better sequence of visits, if such a sequence exists. The reoptimization process uses the latest fuel prices to calculate the route's cost. For more details on retrieving fuel prices, refer to the Get Fuel Prices.
When you run the example application:
- The existing route is reoptimized to improve the order of visits.
- The updated route is returned, reflecting the new sequence and cost.
Retrieve the Existing Route
To reoptimize 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.
Reoptimize the Route
Once the route is retrieved, you can reoptimize it to improve the order of visits.
- Create a
std::shared_ptr<gem::vrp::Request>to hold the reoptimization request. - Call the
reoptimize()method from thevrp::Routeobject, passing theProgressListenerand the request. - Wait for the reoptimization process to complete.
Retrieve the Reoptimized Route
After the reoptimization 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.