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](../_images/example_cpp_vrp_opt_multi_veh_multi_end_stops_stops.png)
![Add optimization with multiple vehicles and multiple end stops - solution](../_images/example_cpp_vrp_opt_multi_veh_multi_end_stops_sol.png)
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 WindowsWhen you run the sample, an optimization will be saved, the solution will be returned and showed on the map.
How it works ¶
-
Create a
vrp::StopList
and add the stops to it. -
Create a
vrp::ConfigurationParameters
and set the route type to beRT_SpecifiedEndStops
. -
Create a
vrp::VehicleConstraints
with the desired fields and add it to avrp::VehicleConstraintsList
. Thevrp::VehicleContraints
will be applied to all the vehicles. -
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. -
Create a
ProgressListener
,vrp::Service
andvrp::RouteList
, in which the solution will be returned. -
Call the
addOptimization()
method fromvrp::Service
using the list from 5.), thevrp::Optimization
from 4.) and the progress listener. -
Once the operation completes, the list from 5.) will contain the solution of the optimization.
To display the stops and routes 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
for each route and add the routes shapes to them. -
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.