Update Optimization
This example demonstrates how to update an existing optimization by making changes to its configuration, vehicles, constraints, and other fields. The updated optimization can also be reoptimized to generate a new solution. If the optimization is not reoptimized, the changes will not be applied to the optimization's routes.
For updating orders, refer to the following examples:
When you run the example application:
- The existing optimization is updated with new configurations, vehicles, and constraints.
- A new solution is generated and returned (if reoptimization is enabled).
Retrieve the Existing Optimization
To update 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.
Update the Optimization
Once the optimization is retrieved, you can update its fields, such as configuration parameters, vehicles, and constraints.
Update Configuration Parameters
- Retrieve the existing configuration parameters from the optimization.
- Modify the desired fields, such as the name, route type, and distance unit.
Update Vehicles
- Create a
vrp::VehicleListand add new or updated vehicles to it. - Call the
addVehicle()method from thevrp::Serviceto add the vehicles to the database.
Update Vehicle Constraints
- Retrieve the existing vehicle constraints from the optimization.
- Modify the desired fields, such as the maximum number of packages and maximum distance.
Update Departures
- Create a
vrp::Departureobject and set the desired fields.
Apply the Updates to the Optimization
- Set the updated configuration parameters, vehicles, constraints, and departures to the optimization.
Update the Optimization and Retrieve the New Solution
Once the optimization 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
updateOptimization()method from thevrp::Service, passing the updated optimization, the request, and theProgressListener. - Wait for the update process to complete.
Retrieve the Updated Solution
After the optimization is updated, you can retrieve the new solution.
- Create a
vrp::RouteListto hold the updated routes. - Call the
getSolution()method from thevrp::Optimizationobject to populate thevrp::RouteList.