Skip to main content

Unlink Route from Optimization

|

This example demonstrates how to unlink a route from its optimization. When a route is unlinked, it will no longer be part of the optimization's solution. The orders visited in this route will be removed from the optimization, and a new optimization will be created for the unlinked route. The new optimization will retain the same configuration parameters, vehicle constraints, and other fields as the unlinked route.

Info

A route cannot be unlinked if it is the only route in the optimization's solution.

When you run the example application:

  • The specified route is unlinked from its optimization.
  • A new optimization is created for the unlinked route.
  • The unlinked route can still be retrieved using its original ID.

To unlink a route, you first need to retrieve the existing route using its ID.

  1. Create a ProgressListener and vrp::Service.
  2. Retrieve the route using the getRoute() method from the vrp::Service.
ProgressListener listener;
gem::vrp::Service serv;

gem::vrp::Route route;
gem::LargeInteger routeId = -1; // Set your route ID here
int res = serv.getRoute(&listener, route, routeId);
WAIT_UNTIL(std::bind(&ProgressListener::IsFinished, &listener), 10000);

Once the route is retrieved, you can unlink it from its optimization.

  1. Call the unlink() method from the vrp::Route object, passing the ProgressListener.
  2. Wait for the unlinking process to complete.
res = route.unlink(&listener);
WAIT_UNTIL(std::bind(&ProgressListener::IsFinished, &listener), 20000);

Verify the Unlinking Process

After the unlinking process is complete, verify the result and retrieve the updated route.

  1. Check if the unlinking process was successful.
  2. Retrieve the updated route using its original ID.
if (listener.IsFinished() && listener.GetError() == gem::KNoError && res == gem::KNoError)
std::cout << "Route unlinked successfully" << std::endl;
else
std::cout << "Route couldn't be unlinked" << std::endl;