Reoptimize Optimization
This example demonstrates how to reoptimize an existing optimization to generate a new and potentially better solution. The reoptimization process uses the latest fuel prices to calculate the new solution (refer to the Get Fuel Prices example).
When you run the example application:
- The existing optimization is reoptimized.
- A new solution is generated and returned.
Retrieve the Existing Optimization
To reoptimize an optimization, you first need to retrieve the existing optimization using its ID.
- Create a
ProgressListenerandvrp::Service. - Retrieve the optimization using the
getOptimization()method from thevrp::Service.
Reoptimize the Optimization
Once the optimization is retrieved, you can reoptimize it to generate a new solution.
- Create a
std::shared_ptr<gem::vrp::Request>to hold the reoptimization request. - Call the
reoptimize()method from thevrp::Optimizationobject, passing theProgressListenerand the request. - Wait for the reoptimization process to complete.
Retrieve the Reoptimized Solution
After the reoptimization process is complete, you can retrieve the new solution.
- Create a
vrp::RouteListto hold the reoptimized routes. - Call the
getSolution()method from thevrp::Optimizationobject to populate thevrp::RouteList.