Skip to content

Add optimization where the stops have all fields set

Add an optimization with stops that have all fields set and display the solution on the map.

Add optimization where the stops have the all fields set - stops

Add optimization where the stops have the all fields set - solution

Use case

Create an optimization where for each stop can be set:
  • the descriptive fields:
    • name

    • address

    • email

    • phone number

  • the restrictive fields:
    • the type: pick up or delivery

    • the number of pieces, weight, and cube that have to be picked-up from it or delivered to it

    • the service time: how much time does the vehicle stay at this stop to do its job (ex: to unload the pieces)

    • the time window within which the stop must be visited

    • the revenue which has to be received from this stop

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.

How it works

  1. Create a vrp::Stop for each stop that has to be visited, set its fields and then add it into a vrp::StopList.

  2. Create a vrp::Optimization and set the list created at 1.) to it.

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

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

  5. Once the operation completes, the list from 3.) 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