×
Add optimization with fixed stops sequences | Maps SDK for C++ | General Magic Add optimization with fixed stops sequences — Maps & Navigation SDKs documentation
Skip to content

Add optimization with fixed stops sequences

Add an optimization with fixed stops sequences set (the stops from a sequence will be visited in the fixed specified order) and display the solution on the map.

In this example there are 2 fixed stops sequences: [2,8,6] and [1,3].

Add optimization with fixed stops sequences - stops

Add optimization with fixed stops sequences - solution

Use case

Create an optimization where some stops must be visited in an exact order.

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 map. In the solution, you can see that stops 2,8,6 and 1,3 will be visited one after another exactly in this order.

How it works

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

  2. Create a vrp::ConfigurationParameters and set the fixed stops sequences to it.

  3. Set the vrp::StopList and the vrp::ConfigurationParameters to a vrp::Optimization object.

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

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

  6. Once the operation completes, the list from 4.) will contain the solution of the optimization.

To display the stops and route 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 and add the route’s shape to it.

  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