Skip to content

Add optimization with multiple vehicles and multiple end stops

Add an optimization with multiple vehicles which end their routes at different stops and display the solution on the map.

Add optimization with multiple vehicles and multiple end stops - stops

Add optimization with multiple vehicles and multiple end stops - solution

Use case

Create an optimization where the vehicles end their routes at different stops.

How to use the sample

First, get an API key token, see the Getting Started guide.

Download the Maps & Navigation SDK for C++ archive file for Linux or Windows

When you run the sample, an optimization will be saved, the solution will be returned and showed on the map.

How it works

  1. Create a vrp::StopList and add the stops to it.

  2. Create a vrp::ConfigurationParameters and set the route type to be RT_SpecifiedEndStops.

  3. Create a vrp::VehicleConstraints with the desired fields and add it to a vrp::VehicleConstraintsList. The vrp::VehicleContraints will be applied to all the vehicles.

  4. Create a vrp::Optimization and set the objects created at 1.), 2.), 3.) to it. Also set the number of vehicles to be at least 2 and set the end stop index for each vehicle.

  5. Create a ProgressListener, vrp::Service and vrp::RouteList, in which the solution will be returned.

  6. Call the addOptimization() method from vrp::Service using the list from 5.), the vrp::Optimization from 4.) and the progress listener.

  7. Once the operation completes, the list from 5.) will contain the solution of the optimization.

To display the stops and routes on the map

  1. Create a MapServiceListener, OpenGLContext and MapView.

  2. Create a LandmarkList, CoordinatesList and PolygonGeographicArea.

  3. Instruct the MapView to highlight the LandmarkList from 2.) to print the stops.

  4. Instruct the MapView to center on the PolygonGeographicArea.

  5. Create a MarkerCollection of type Polyline for each route and add the routes shapes to them.

  6. Set the newly created MarkerCollection in the markers collections of the map view preferences.

  7. Allow the application to run until the map view is fully loaded.

C++ Examples

Maps SDK for C++ Examples can be downloaded or cloned with Git