Re-Optimize and Rebalance an Existing Set of Addresses

See files for this Use Case on the GitHub here

You can re-optimize and rebalance an existing optimization problem.

Description

Route4Me allows you to rebalance and modify optimized routes in the Optimizations section. Here you can apply structural changes to your optimizations, such as changing stops from one route to another (for multiple-route optimizations), changing the optimization type, or changing the details for a specific address without re-uploading or re-typing your destinations list.

In this context, an "optimization"" is just a set of parameters and rules that is applied by a system for one or more routes.

Solution

Optimization Parameters and Addresses

Please pay attention to the following parameters, so you'll provide correct ones for the vehcile capacities:

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

Addresses are without time windows and you can see them on the 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 :: Single Depot, Multiple Driver, No Time Window
3 
4 ::See video tutorial here: http://support.route4me.com/route-planning-help.php?id=manual0:tutorial2:chapter2:subchapter1
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 "@single_depot_multi_driver_no_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), with several generated routes.

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 
3 SET url=https://www.route4me.com/api.v4/optimization_problem.php
4 SET apikey=11111111111111111111111111111111
5 SET optprobid=137BE9E0C1F69AA427F14F39B2A6515B
6 
7 ECHO ON
8 curl -o file1.txt -g -X GET -k "%URL%?api_key=%apikey%&optimization_problem_id=%optprobid%"
9 
10 timeout /t 30

See sample RESPONSE JSON data here

System will send a RESPONSE with an array of the addresses which belongs to 5 generated routes.

"optimization_problem_id": "137BE9E0C1F69AA427F14F39B2A6515B"
"route_id": "45C56DC218B627EDA5801AA541D2624E"
"route_id": "5BB7EA1E6E3E4633D1299505BDAEA953"
"route_id": "93B630865F33E442FA94CF52251651D3"
"route_id": "BAD35EEE32BFF8E20C2077AC53761BC7"
"route_id": "F4CAF7AE81867B66FCD206AA23973DDA"

Details of the Optimized Routes

You can get more details of these routes (see below the one route example, you can also get details of the other 4 routes using the same method by adjusting 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 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=F4CAF7AE81867B66FCD206AA23973DDA
6 SET rpo=Points
7 
8 ECHO ON
9 
10 curl -o file1.txt -g -k -X GET "%url%?route_id=%routeid%&api_key=%apikey%&route_path_output=%rpo%"
11 
12 timeout /t 30

See sample RESPONSE JSON data here

Note
System will send a RESPONSE with an array of the fields **. Those will be used to draw routes on a map, exactly as they generated by Route4Me API.

You can see a route drawn on the map by the Route4Me API:

You can draw all generated 5 routes as:

Move a Destination Into a Route

You can move a destination from a route to other route and then reoptimize the optimization problem.

The endpoint: https://www.route4me.com/actions/route/move_route_destination.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
to_route_id string Recipient Route ID POST
to_route_id string Recipient route ID POST
route_destination_id integer Route destination ID to be moved POST
after_destination_id integer Route destination ID in recipent route after which will be inserted moved destination POST


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/actions/route/move_route_destination.php
4 SET apikey=11111111111111111111111111111111
5 
6 :: address recipient route ID
7 SET trid=BAD35EEE32BFF8E20C2077AC53761BC7
8 
9 :: The destination to be moved - address "3524 WHEELER AVE, Louisville, KY, 40215" in the route "5BB7EA1E6E3E4633D1299505BDAEA953", sequence # = 8
10 SET rdi=184611093
11 
12 :: ID of the destination n recipient route, after which will be inserted moved destination. "2707 7TH ST, Louisville, KY, 40215"
13 SET adi=184611074
14 
15 ECHO ON
16 
17 curl -o file1.txt -g -X POST -k -H "Content-Type: multipart/form-data;" -F "to_route_id=%trid%" -F "route_destination_id=%rdi%" -F "after_destination_id=%adi%" "%url%?api_key=%apikey%"
18 
19 timeout /t 30

From the above script you can conclude that we are going to move this selected address from route on the map:

After this selected address of the drawn route:

You can expect this API response:

{"success":true}

Get the Reoptimized Routes

You can use described above in this topic procedure to get the changed routes (see link here)

The source route with route_id=5BB7EA1E6E3E4633D1299505BDAEA953

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

See sample RESPONSE JSON data here

You can see this route on a map as:

The recipient route with route_id=BAD35EEE32BFF8E20C2077AC53761BC7

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

See sample RESPONSE JSON data here

You can see this route on a map:

As you can notice, both routes are reoptimized.

Changing the Details of a Specific Destination

You can change the details of a specific address and reoptimize a route, for example, you can change sequence of a destination.

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
gas_price double Price of gas (used to compute route costs) POST


Let us choose an address of a route with route_id=93B630865F33E442FA94CF52251651D3

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=93B630865F33E442FA94CF52251651D3
5 SET routedestinationid=184611110
6 
7 ECHO ON
8 
9 curl -o file1.txt -g -k -X PUT -H "Content-Type: application/json" -d "@update_address_sequence_in_route_data.json" "%url%?api_key=%apikey%&route_id=%routeid%&route_destination_id=%routedestinationid%"
10 
11 timeout /t 30

See sample RESPONSE JSON data here

Reoptimiza a Route

You can reoptimize route. For example, you can change optimization type from Distance to "Time".

If you have a route with route_id=99C428A9106C118C3F908B445C7DEB76 with optimization type Distance,

You can change the optimization type to Time:

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

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
optimize string Optimization type ENUM["Distance", "Time", ...] GET
disable_optimization integer If equal to 1, optimization is disabled GET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v3/route/reoptimize_2.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=99C428A9106C118C3F908B445C7DEB76
6 SET opt_type=Time
7 SET disable_optimization=0
8 
9 ECHO ON
10 
11 curl -o file1.txt -k -g -X GET "%url%?api_key=%apikey%&route_id=%routeid%&disable_optimization=%disable_optimization%&optimize=%opt_type%;"
12 
13 timeout /t 30

You can expect this API response:

{
"status":true
}