Creating Shadow Routes

See files for this Use Case on GitHub here

Description

Splitting up the workload between drivers is a great way to get the most out of the Route4Me service. You may have a situation when several drivers have to drive through the same destinations in the same sequence. In this case you can duplicate a route and assign a second or a third version of the same route to another driver. Such routes called "shadow routes", because the drivers are shadowing each other's work.

Solution

Optimization Parameters and addresses

Please pay attention to the following parameters, so you can provide correct ones for this use case:

ParameterTypeDescriptionHTTP method
api_keystringAPI KEY of the userGET
redirectintegerif equal to 1, will be redirected, if 0 - notGET
addressesarrayValid JSON array of Address objects. Click here to see the JSON SchemaPOST
parametersRoute ParametersValid JSON string of RouteParameters object. Click here to see the JSON SchemaPOST

You can see the addresses on a map as:

Create an Optimization

You can create new optimization for this use case. From the cUrl example bellow you can see that:

ParameterTypeDescription
api_keystringAPI KEY of the user
input dataPOST dataValid JSON object string. Click here to see the JSON Schema
1 @ECHO OFF
2 :: Multiple Depot, Multiple Driver with 24 Stops, Time Window
3 
4 ::See video tutorial here: http://support.route4me.com/route-planning-help.php?id=manual0:tutorial2:chapter2:subchapter2
5 
6 SET URL=https://www.route4me.com/api.v4/optimization_problem.php
7 SET apikey=11111111111111111111111111111111
8 SET route_path_output=Points
9 
10 ECHO ON
11 
12 curl -o file1.txt -g -X POST -k -d "@multi_depot_multi_driver_24stops_tw_data.json" "%URL%?api_key=%apikey%&route_path_output=%route_path_output%"
13 
14 timeout /t 30

You can expect an Optimization problem (see link), which generated 5 routes already.

View the Optimization details

You can get more details from the newly created optimization problem:

The endpoint: https://www.route4me.com/api.v4/optimization_problem.php

HTTP Parameters

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
optimization_problem_idstringOptimization problem IDGET


1 @ECHO OFF
2 SET url=https://www.route4me.com/api.v4/optimization_problem.php
3 SET apikey=11111111111111111111111111111111
4 SET optprobid=73B233E03AD059F96A4DD35D8B1B182A
5 
6 ECHO ON
7 curl -o file1.txt -g -X GET -k "%URL%?api_key=%apikey%&optimization_problem_id=%optprobid%"
8 
9 timeout /t 30

See sample RESPONSE JSON data here

In the RESPONSE you can see an array of addresses, which belong to 5 generated routes:

"route_id": "12048312D8B8A15C941EE4AE4005D592" - 5 addresses;
"route_id": "754102B132D59AF502869797760A4E4E" - 5 addresses;
"route_id": "9154712DCDC62A1BFE934F0B4363599C" - 5 addresses;
"route_id": "9CFFDBA2649BE793D20EEFAD69434E39" - 11 addresses;
"route_id": "ED45966AED01B3925D2CD905A6A16534" - 5 addresses.

Details of the Optimized Routes

See below an example for one route. You can get the details of the remaining routes by using the same method and changing the parameter route_id.

The endpoint: https://www.route4me.com/api.v4/route.php

HTTP Parameters

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
route_idstringRoute IDGET
route_path_outputstringIf equal to 'Poitns', you'll get an array of the path points to next addressGET


1 @ECHO OFF
2 SET url=https://www.route4me.com/api.v4/route.php
3 SET apikey=11111111111111111111111111111111
4 SET routeid=12048312D8B8A15C941EE4AE4005D592
5 SET rpo=Points
6 
7 ECHO ON
8 
9 curl -o file1.txt -g -k -X GET "%url%?route_id=%routeid%&api_key=%apikey%&route_path_output=%rpo%"
10 
11 timeout /t 30

See sample RESPONSE JSON data here

Note
System will send a RESPONSE with the array of fields path_to_next. You can use those to draw routes on a map, exactly as they are generated by the Route4Me API.

On the map you can see a route drawn by the Route4Me API as:

You can see all 5 routes drawn by the Route4Me API as:

Duplicate a Route in a New Optimization Problem

Let's duplicate the route with route_id=754102B132D59AF502869797760A4E4E.

Note
Accepts a unique route_id which exists in the Route4Me database and duplicates the route. The duplicated route has all the same metadata and account ownership information as the original one. However, notes and visited status flags from the original route are not copied into the new route. The name of the new route is automatically appended with the string "(Duplicate)" to indicate that the route was duplicated. Currently, there is no special designation in the database to indicate that a route is originated from another route.

The endpoint: https://www.route4me.com/actions/duplicate_route.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET


1 @ECHO OFF
2 SET url=https://www.route4me.com/actions/duplicate_route.php
3 SET apikey=11111111111111111111111111111111
4 SET routeid=754102B132D59AF502869797760A4E4E
5 
6 ECHO ON
7 curl -o file1.txt -g -k -X GET "%url%?api_key=%apikey%&route_id=%routeid%&to=none"
8 
9 timeout /t 30

You can expect this API response:

{
"optimization_problem_id":"61709C8C317134EC7F2AE2F370B41549",
"success":true
}

As you can notice, duplication of the route created new optimization problem with a route. You can apply process described above (see link here) and get new route with route_id=9B61D1FC0E3943BEE7FF0948513CAD08.

Duplicate a Route in the Same Optimization Problem

You can duplicate a route in the same optimization problem.

The endpoint: https://www.route4me.com/api.v4/route.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
POST data route Valid JSON string of a Route object POST


See sample INPUT JSON data here

1 @ECHO OFF
2 SET url=https://www.route4me.com/api.v4/route.php
3 SET apikey=11111111111111111111111111111111
4 SET routeid="9154712DCDC62A1BFE934F0B4363599C",
5 
6 ECHO ON
7 
8 curl -o file1.txt -g -k -X PUT -H "Content-Type: application/json" -d "@duplicate_route_same_optimization_data.json" "%url%?api_key=%apikey%&route_id=%routeid%"
9 
10 timeout /t 30

See sample RESPONSE JSON data here

Attention
This method of a route duplication can be revised in the future.

Duplicate a Route in the Same Optimization Problem

You can assign the duplicated route (route_id=9B61D1FC0E3943BEE7FF0948513CAD08) to a driver.

The endpoint: http://www.route4me.com/api.v4/route.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
driver_id integer Driver ID POST


See sample INPUT JSON data here

1 @ECHO OFF
2 SET url=http://www.route4me.com/api.v4/route.php
3 SET apikey=11111111111111111111111111111111
4 SET routeid=9B61D1FC0E3943BEE7FF0948513CAD08
5 
6 ECHO ON
7 
8 curl -o file1.txt -g -X PUT -H "Content-Type: application/json" -d "@assign_driver_to_route_data.json" "%url%?route_id=%routeid%&api_key=%apikey%"
9 
10 timeout /t 30

See sample RESPONSE JSON data here

Pay attention to this parameter in the RESPONSE JSON file:

"driver_id": "315948"