Generate an Optimized Route for an Autonomous Vehicle

You can generate optimized routes for autonomous vehicles in order to send the orders right to the clients' doorstep.

See files for this Use Case on GitHub here

Description

The Autonomous vehicles (AV) use a combination of sensors, including lidar (light detection and ranging), radar, cameras, ultrasonic, and infrared. For locationing, the AV can use a combination of the Global Positioning System (GPS) and inertial navigation systems (INS).

When using the AV fleet for the delivery, the role of vehicle to vehicle (V2V) and vehicle to infrastructure (V2I) communication is important. That can be done only through the reliable software and services.

You can use Route4Me API for routes optimization for the AV and adapt it to AV's internal and external software. For example, you can use custom data parameters for storing commands for different business cases. Particularly, for example, an AV will open the baggage compartment only if someone will enter or say specified password. And this password you can store in the custom data. Or an AV could be equipped with portative printer for printing information sheet for customer (delivery time, latest news from the supplier), The AV can send information to supplier's database about delivery or problem with triggering specified processes. The AV can be equipped with a terminal for entering new orders etc.

Also, in case of AV fleet it's important dynamically construct the avoidance zones and geofence, triggers, use latest environmental data (rain, snow) etc.

The latest big story in the autonomous vehicle industry is the development of shared autonomous vehicles (SAV) for public transportation. Preliminary results indicate that each SAV can replace around nine conventional vehicles.

Let's imagine, John, David, Mary, Liza and Peter live in the Akron city, OH. Each morning these folks have the schedule:

NameHome addressDepart timeOffice addressArrival timeMax wait time
John3634 W Market St, Fairlawn, OH 4433308:002705 N River Rd, Stow, OH 4422409:00000:01
David512 Florida Pl, Barberton, OH 4420308:252705 N River Rd, Stow, OH 4422409:0000:01
Mary512 Florida Pl, Barberton, OH 4420308:2510159 Bissell Dr, Twinsburg, OH 4408709:4500:01
Liza3634 W Market St, Fairlawn, OH 4433308:011659 Hibbard Dr, Stow, OH 4422409:3000:01
Peter3495 Purdue St, Cuyahoga Falls, OH 4422108:5517638 Chillicothe Rd Chagrin Falls, OH 44023, USA09:5700:02

Peter is at home and wants to go to his office but there is no SAV containing such route. Peter has to leave home with one SAV and move to another SAV at 10159 Bissell Dr, Twinsburg, OH 44087 to get to his office. Fleet management takes Peter's route into consideration and plans multiple routes such way that Peter could lose least time possible when waiting for another SAV.

Solution

Optimization Parameters and addresses

Let's to construct an optimized route with the time windows for John, David, Mary, Liza and Peter. As for Peter, he needs second route for transporting him to the address 17638 Chillicothe Rd Chagrin Falls, OH 44023, USA.

Let's choose a Single Driver Round Trip with Time Windows option for generating the first route. The parameters for the Optimization Problem are:

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

In Route Parameters you can define the vehicle_id field. Set it to FFFF72BF6E06DC3C746673279BDAAE05 (This is the ID of one of the vehicles used in Route4Me's test account database).

You can see the addresses on the map as:

Create an Optimization

The cURL example below shows you how to create new optimized routes for this Use Case:

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 Driver Round Trip
3 
4 ::See video tutorial here: http://support.route4me.com/route-planning-help.php?id=manual0:tutorial2:chapter1:subchapter1
5 
6 SET URL=https://www.route4me.com/api.v4/optimization_problem.php
7 SET apikey=11111111111111111111111111111111
8 
9 ECHO ON
10 
11 curl -o file1.txt -g -X POST -k -d "@single_driver_round_trip_data.json" "%url%?api_key=%apikey%"
12 
13 timeout /t 30

You can expect an Optimization problem (see link), which generated a route 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 
3 SET url=https://www.route4me.com/api.v4/optimization_problem.php
4 SET apikey=11111111111111111111111111111111
5 SET optprobid=CB2A7623469D421CCD08CC8F460BA977
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

The system will send a RESPONSE with an array of the addresses, which belongs to one round-trip route.

Details of the Optimized Route

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=27AF2455563AAB57650CE5696FBEC199
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
In the RESPONSE you can see the array of the fields path_to_next. Those will be used to draw routes on a map, exactly as they generated by Route4Me API.

You can draw generated round trip route as:

Add Custom Data to an Address

You can add custom fields with custom values to an address. Particularly, you can add a password as a custom data - autonomous vehicle will open the baggage compartment only if someone will enter or say specified password.

Let us add a password as custom data to the address 3495 Purdue St, Cuyahoga Falls, OH 44221 with route_destination_id=208797874.

HTTP Parameters (see JSON schema here)

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
route_destination_id intenger Route destination ID GET
custom_fields array Array of custom fields with string values POST


From the cUrl example bellow you can see that:

1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/address.php
4 
5 :: You should insert real test data and your API key for accurate testing
6 
7 SET apikey=11111111111111111111111111111111
8 SET routeid=27AF2455563AAB57650CE5696FBEC199
9 SET routedestinationid=208797874
10 
11 ECHO ON
12 
13 curl -o file1.txt -g -k -X PUT -H "Content-Type: application/json" -d "@update_address_custom_data.json" "%url%?api_key=%apikey%&route_id=%routeid%&route_destination_id=%routedestinationid%"
14 
15 timeout /t 30

See sample response data (see here).

Pay attention to the parameter custom_fields:

"custom_fields": {
"password": "open sesame"
}

You can once again do the step as it described above in the subtopic Details of the Optimized Route and draw the route on a map with the address and added password:

Now only a person who will enter or say to AV "open sesame" can get an item delivered by AV.

Add Latest Information to Address as a Note

Let us add a note that contain a pdf file with product catalog (national flags), which AV can print or share to passanger's device after the item is delivered. Let us add this kind of note to the address 512 Florida Pl, Barberton, OH 44203 with route_destination_id=208797872.

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

HTTP Parameters (see JSON schema here)

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
address_id intenger Route destination ID GET
dev_lat double The latitude location of where a mobile device was located when it made a request GET
dev_lng double The longitude location of where a mobile device was located when it made a request GET
device_type string The type of the device that is creating this route ENUM("web", "iphone", "ipad", "android_phone", "android_tablet") GET
strUpdateType string The type of the device that is creating this route ENUM("web", "iphone", "ipad", "android_phone", "android_tablet") GET
strFilename string Filename ID POST


Run this batch script with the cURL command:

1 @ECHO OFF
2 :: Add a note to the route using of file uploading
3 
4 SET url=https://www.route4me.com/actions/addRouteNotes.php
5 SET apikey=11111111111111111111111111111111
6 SET routeid=27AF2455563AAB57650CE5696FBEC199
7 SET addrid=208797872
8 SET dev_lat=41.003671512008
9 SET dev_lng=-81.598461046815
10 SET dev_type=web
11 SET "filename=flags.pdf"
12 
13 ECHO ON
14 
15 curl -o file1.txt -g -k -X POST -F "[email protected]%filename%" "%url%?api_key=%apikey%&route_id=%routeid%&address_id=%addrid%&dev_lat=%dev_lat%&dev_lng=%dev_lng%&device_type=%dev_type%&strUpdateType=ANY_FILE"
16 
17 timeout /t 30

You can expect this API response:

{
"status": true,
"note_id": "1161345",
"upload_id": "cfa2bdb9645963aef94a7090cb9a534a",
"note": {
"note_id": 1161345,
"route_id": "27AF2455563AAB57650CE5696FBEC199",
"route_destination_id": 208797872,
"ts_added": 1484660921,
"activity_type": "",
"upload_id": "cfa2bdb9645963aef94a7090cb9a534a",
"upload_extension": "pdf",
"upload_url": "http:\/\/adb6def9928467589ebb-f540d5a8d53c2e76ad581b6e5c346ad6.r74.cf1.rackcdn.com\/cfa2bdb9645963aef94a7090cb9a534a.pdf",
"upload_type": "ANY_FILE",
"contents": "",
"lat": 41.003672,
"lng": -81.598461,
"device_type": "web"
}
}

Pay attention to the parameter upload_url:

"upload_url": "http:\/\/adb6def9928467589ebb-f540d5a8d53c2e76ad581b6e5c346ad6.r74.cf1.rackcdn.com\/cfa2bdb9645963aef94a7090cb9a534a.pdf"

The passanger can find the product catalog at this address.

You can once again do the step as it described above in the subtopic Details of the Optimized Route with one more parameter notes=1 and draw the route on a map with information about uploaded note:

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

Create a Second Route Synchronized to the First Route

As you remember Peter needs second route in order to get to his office. You can generate this route as single drive route with time windows. You can do all the steps described above. See links for appropriate steps (click on the link to see file content):

You can draw the generated route, which will transport Peter to his office as:

Create New Order

Let's say central AI dispetcher got new order from passanger and it added new order to the database.

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

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API key of the user GET
order object Valid JSON string of an Order object. Click here to see the JSON Schema POST

See sample INPUT data (see here).

1 @ECHO OFF
2 SET url=https://www.route4me.com/api.v4/order.php
3 SET apikey=11111111111111111111111111111111
4 
5 ECHO ON
6 
7 :: The example refers to the process of creating an order by sending HTPP POST data
8 
9 curl -o file1.txt -k -g -X POST -H "Content-Type: application/json" -d "@add_order_data.json" "%url%?api_key=%apikey%"
10 
11 timeout /t 30

You can expect this API response:

{
"created_timestamp": 1484661223,
"order_id": 4134,
"order_status_id": 0,
"day_added_YYMMDD": "2017-01-17",
"day_scheduled_for_YYMMDD": null,
"address_alias": "North Randall",
"address_1": "4601 Northfield Rd North Randall, OH 44128, USA",
"address_2": "",
"member_id": 1,
"EXT_FIELD_first_name": "Igor",
"EXT_FIELD_last_name": "Progman",
"EXT_FIELD_email": "[email protected]",
"EXT_FIELD_phone": "380380380380",
"address_city": "Cleveland",
"address_state_id": null,
"address_country_id": "0",
"address_zip": "",
"cached_lat": 41.432795,
"cached_lng": -81.525631,
"curbside_lat": 41.432795,
"curbside_lng": -81.525631,
"EXT_FIELD_custom_data": [{
"Pickup_date": "2017-01-18 10:30",
"luggage": "suitcase"
}],
"in_route_count": 0,
"last_visited_timestamp": 0,
"last_routed_timestamp": 0,
"local_time_window_start": null,
"local_time_window_end": null,
"local_time_window_start_2": null,
"local_time_window_end_2": null,
"service_time": null,
"local_timezone_string": null,
"color": null,
"order_icon": null,
"is_validated": false,
"is_pending": true,
"is_accepted": false,
"is_started": false,
"is_completed": false
}

Insert the Existed Order into the Route

Now central AI dispetcher can decide which route is most optimal for already created order and insert it into this route.

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
addresses array Valid JSON array of Address objects. Click here to see the JSON Schema PUT
optimal_position boolean If true, an address will be inserted at optimal position of a route PUT

See sample INPUT data (see here).

Pay attention that you can put into the address object only order_id parameter.

1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET route_id=05A3F0C552A2CD50107DBD36D40FC8C5
6 
7 ECHO ON
8 
9 :: The example refers to the process of inserting an existed order into an existed route by sending HTPP POST data
10 
11 curl -o file1.txt -k -g -X PUT -H "Content-Type: application/json" -d "@add_order_to_route_data.json" "%url%?api_key=%apikey%&route_id=%route_id%"
12 
13 timeout /t 30

See sample RESPONSE JSON data here

The order for new passanger was inserted into the route.