Add Orders to a Route
This example demonstrates how to add a list of orders into an existing route's order list at optimal positions determined by the algorithm. The orders will be inserted between existing route orders without rearranging them. If the route is reoptimized, the orders will be rearranged in the best order of visit, and you may not see them inserted at the original optimal positions.
The added orders will also be included in the optimization's order list.
When you run the example application:
- The existing route will be updated with new orders.
- The orders will be inserted at the best possible positions without altering the current order sequence.
- If reoptimization is enabled, the entire route will be rearranged for optimal efficiency.
Retrieve Customers
To create an order we can use an existing customer to assign the order to, or we can create a new one. In this example we will use two customers already existing in the database.
- Create a
ProgressListenerandvrp::Service. - Retrieve the customers using the
getCustomer()method from thevrp::Service.
Create Orders
- Create two
vrp::Orderobjects associated with the customers retrieved earlier. - Set necessary attributes such as the number of packages, service time, and order type.
- Use the
addOrder()method fromvrp::Serviceto add the orders.
Create orders for the retrieved customers.
Retrieve the existing Route
To add orders to an route, you have to retrieve that route by id.
- Retrieve the route using the
getRoute()method from thevrp::Service.
Add Orders to the Route
Once the orders are created, they need to be added to the route.
- Create a
std::shared_ptr<gem::vrp::Request>to hold the request. - Call the
addOrders()method fromvrp::Route. - Wait for the operation to complete.