Understanding Dynamic Arrival and Departure Times

See files for this Use Case on the GitHub here

You can dynamically analyze drivers' progress on following the schedules, see on map the locations arrived and departed, identify any location sequence deviations for each driver.

Description

The driver's so called freestyling is common logistic problem. Many of the logistic companies have an ongoing problem where a driver claims to have visited an address but hasn't truly visited it, or hasn't visit it at the requested time. This is freestyling because the driver is not following the scheduled route and sequence and, as a result, is being highly inefficient. The driver may also be violating time constraints requested by the customers. To overcome this problem our system will capture geo-coordinates every time a driver check-ins (marks as visited) or departs (marks as departed) from a location.

You can implement auto check-in feature using the real-time dynamic geofencing. This feature dynamically updates estimated arrival times in the manifest. It also logs in instances when a driver deviates from a scheduled route, enabling businesses to detect if drivers are freestyling. Drivers can still manually enter their check-in and departure time, and both data sets are stored and available for analysis.

You can also use the check-in feature to implement the custom triggers.

Solution

As described above, the check-in feature was implemented in two ways: via driver's manually check-in and via auto check-in through geofencing. We'll be modeling both scenarios on the Single Driver Multiple Time Windows example.

Optimization Parameters and addresses

Let us choose a Single Driver Multiple Time Windows option for this use case. The parameters for an optimization problem are following:

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

See input sample JSON file here

You can see the addresses on the map as:

Pay attention to the time windows and service time.

Create an Optimization

You can create new optimization for this use case example.

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

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

As a response you can expect the following Optimization problem (see link), with generated route.

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

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
optimization_problem_id string Optimization problem ID GET


1 @ECHO OFF
2 
3 SET url=http://www.route4me.com/api.v4/optimization_problem.php
4 SET apikey=11111111111111111111111111111111
5 SET optprobid=06BF0EFE40FCCC24957686DFE2DE353A
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

Details of the Optimized Route

You can get more details of 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
route_path_output string If equal to 'Poitns', you'll get an array of the path points to next address GET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=DD376C7148E7FEE36CFABE2BD9978BDD
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 and use them to draw routes on a map, exactly as they generated by Route4Me API.

You can draw generated route as:

Details of the Optimized Route

Route4Me allows you to set geofences, which are virtual perimeters for real-world geographic areas, to automatically track and record when your drivers reach and depart each destination point on their route. Geofences are triggered automatically based on your preferred geofence settings.

To set up geofences on your Route4Me account, click My Account, then select Settings:

Scroll down to the geofencing section. Here you can adjust the geofence settings:

This way check-in event will be triggered as vehicle enters in the 200m radius circle area centered in the of destination point.

Set GPS position of a device

In the real world check-in notification will be created on pressing a button by a driver, or on a vehicle arrival into the geofenced area. For this case we do not use actual vehicle data, so we emulate it programmatically.

The endpoint: https://www.route4me.com/track/set.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
format string Response format GET
member_id integer Member ID GET
route_id string Route ID GET
course integer Vehicle movement course GET
speed double Vehicle movement speed GET
lat double Latitude GET
lng double Longitude GET
device_type string Device type GET
device_guid string Device ID GET
vehicle_id string Vehicle ID GET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/track/set.php
4 SET apikey=11111111111111111111111111111111
5 SET frm=XML
6 SET membid=1
7 SET route_id=DD376C7148E7FEE36CFABE2BD9978BDD
8 SET course=70
9 SET speed=60
10 :: bellow is position of the address: 1659 Hibbard Dr, Stow, OH 44224
11 SET lat=41.194505989552
12 SET lng=-81.443351581693
13 SET devtype=android_phone
14 SET devguid="HK5454H0K454564WWER445"
15 SET vehid=FFFF72BF6E06DC3C746673279BDAAE05
16 
17 ECHO ON
18 
19 :: There are also several optional parameters: tx_id, altitude, device_timestamp, app_version
20 
21 curl -o file1.txt -g -X GET -k "%url%?api_key=%apikey%&format=%frm%&member_id=%membid%&route_id=%route_id%&course=%course%&speed=%speed%&lat=%lat%&lng=%lng%&device_type=%devtype%&device_guid=%devguid%&vehicle_id=%vehid%"
22 
23 timeout /t 30

You can expect this API response:

{"status":true}

Get Inserted GPS Data from a Route

You can retrieve inserted GPS data from the route and use it for different purposes: draw vehicle track on a map, analyze vehicle arrival and departure from a destination etc.

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
device_tracking_history integer If equal to 1, GPS tracking history will be shown in the response GET


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

See sample RESPONSE JSON data here

Pay attention to this block of the response file:

"tracking_history": [
{
"s": "60",
"lt": "41.194505989552",
"m": 1,
"lg": "-81.443351581693",
"d": 70,
"ts": "1472718788",
"ts_friendly": "2016-09-01 04:33:08",
"src": "R4M"
},
{
"s": "60",
"lt": "41.194505989552",
"m": 1,
"lg": "-81.443351581693",
"d": 70,
"ts": "1472718620",
"ts_friendly": "2016-09-01 04:30:20",
"src": "R4M"
},
{
"s": "60",
"lt": "41.315116882324",
"m": 1,
"lg": "-81.558746337891",
"d": 70,
"ts": "1472716976",
"ts_friendly": "2016-09-01 04:02:56",
"src": "R4M"
}
]
Note
If an inserted GPS position happend to locate within a destination's geofense area, check-in event should be triggered.
Attention
Route4Me has special tool for vehicle tracking - please, see this link. You can enter there value of route_id (DD376C7148E7FEE36CFABE2BD9978BDD in this case) and see vehcile tracking path.

Mark a Destination as Detected as Visited

You can mark a destination as "visited" programmatically (similar to pressing on a button "Visited" by driver).

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

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
route_destination_id integer Route destination ID (Address ID) GET
is_visited integer If equal to 1, the destination will be marked as visited POST


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/address.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=DD376C7148E7FEE36CFABE2BD9978BDD
6 SET routedestinationid=183045808
7 
8 ECHO ON
9 
10 :: is_visited=1 means address was visited, is_visited=0 --- not visited
11 
12 curl -o file1.txt -k -g -X PUT -H "Content-Type: application/json" -d "@mark_address_as_detected_as_visited_data.json" "%url%?api_key=%apikey%&route_id=%routeid%&route_destination_id=%routedestinationid%"
13 
14 timeout /t 30

See sample RESPONSE JSON data here

Pay attention to this block of the resposnse file:

"is_visited": true,
"timestamp_last_visited": 1472831090,

Mark a Destination as Detected as Departed

You can mark a destination as departed programmatically (this meets to pressing on a button "Departed" by driver ).

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

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
route_id string Route ID GET
route_destination_id integer Route destination ID (Address ID) GET
is_departed integer If equal to 1, the destination will be marked as departed POST


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/address.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=DD376C7148E7FEE36CFABE2BD9978BDD
6 SET routedestinationid=183045808
7 
8 ECHO ON
9 
10 :: is_departed=1 means address was departed, is_departed=0 --- not departed
11 
12 curl -o file1.txt -k -g -X PUT -H "Content-Type: application/json" -d "@mark_address_as_detected_as_departed_data.json" "%url%?api_key=%apikey%&route_id=%routeid%&route_destination_id=%routedestinationid%"
13 
14 timeout /t 30

See sample RESPONSE JSON data here

Pay attention to this block of the response file:

"is_departed": true,
"timestamp_last_departed": 1472831623,

You can compare time windows and check-in times:

time_window_start = (1472831090 - int(1472831090/(24*3600)*(24*3600))) = 56690sec = 15:44
timestamp_last_visited = 27000 sec = 7:30
time_window_end = (1472831623 - int(1472831623/(24*3600)*(24*3600))) = 57223sec = 15:54
timestamp_last_departed = 27600 sec = 7:35