Add optimization with set matrices¶
Add an optimization with custom matrices and display the solution on the map.
Use case¶
Create an optimization where the time and distance matrice values are set by the user.
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 WindowsWhen you run the sample, an optimization will be saved, the solution will be returned and shown on the map.
How it works¶
Create a
vrp::StopList
and add the stops to it.Create a
vrp::ConfigurationParameters
and set the distnace unit, the matrices build type toMBT_Set
and the matrices to it.Create a
vrp::Optimization
and set the objects created at 1.) and 2.) to it.Create a
ProgressListener
,vrp::Service
andvrp::RouteList
, in which the solution will be returned.Call the
addOptimization()
method fromvrp::Service
using the list from 4.), the`vrp::Optimization
from 3.) and the progress listener.Once the operation completes, the list from 4.) will contain the solution of the optimization.
To display the locations and territories on the map¶
Create a
MapServiceListener
,OpenGLContext
andMapView
.Create a
LandmarkList
,CoordinatesList
andPolygonGeographicArea
.Instruct the
MapView
to highlight theLandmarkList
from 2.) to print the stops.Instruct the
MapView
to center on thePolygonGeographicArea
.Create a
MarkerCollection
of typePolyline
and add the route’s shape to it.Set the newly created
MarkerCollection
in the markers collections of the map view preferences.Allow the application to run until the map view is fully loaded.