Add Orders to an Optimization
This example demonstrates how to add a list of orders to an existing optimization. The newly added orders will be assigned to the optimization’s routes if the optimization is reoptimized. If reoptimization is not enabled, the added orders will be stored but not assigned to routes.
When you run the example application:
- The specified orders are added to the existing optimization.
- If reoptimization is enabled, the optimization will be updated, and a new solution will be generated.
Retrieve the existing Optimization
To add orders to an optimization, you have to retrieve that optimization by id.
- Create a
ProgressListenerandvrp::Service. - Retrieve the optimization using the
getOptimization()method from thevrp::Service.
Create Customers and Orders
Prepare customers and their associated orders, which will then be added in optimization.
Creating Customers
- Create
vrp::Customerobjects and set the necessary fields such as coordinates, alias, phone number, and email. - Use the
addCustomer()method fromvrp::Serviceto add customers.
Creating and Adding Orders
- Create
vrp::Orderobjects associated with the customers. - Set necessary attributes such as the number of packages, service time, and order type.
- Use the
addOrder()method fromvrp::Serviceto add the orders.
Add Orders to Optimization and Reoptimize
Once the orders are created, they need to be added to the optimization.
- Create a
std::shared_ptr<gem::vrp::Request>to hold the request. - Call the
addOrders()method fromvrp::Optimization. - Wait for the operation to complete.