Vehicle Routing Problem via REST - Problem with times

3991
7
05-08-2013 07:17 AM
NicolasCaspari
New Contributor
I am trying to get a Vehicle Routing Problem to work as a geoprocessing service on one of our servers.
http://arcgisserver01.cloud.alta4.com:6080/arcgis/rest/services/koop_uni_fh_trier/TrierApp/GPServer/...

If I call the geoprocessing service via REST url and submit depots, orders and routes WITHOUT time information, output stops are returned. As soon as I also submit time information (TimeWindowStart1 etc.), no output stops are returned.

I have tried different time formats: "10:00:00", "10:00 AM", Unix Timestamp (with and without the "), but no success.

Before I publish the service, the VRP works on my ArcGIS Desktop with times.

Our ArcGIS Server configuration: ArcGIS Server 10.1.1 with Security Patch 1, System: Red Hat Enterprise Linux 6.3, 64 bit

Here's one of the REST commands that I tried. Can anyone spot a mistake?

http://arcgisserver01.cloud.alta4.com:6080/arcgis/rest/services/koop_uni_fh_trier/TrierApp/GPServer/SolveVRP/submitJob?
orders={
 "displayFieldName": "POIs",
 "geometryType": "esriGeometryPoint",
 "spatialReference": {
  "wkid": 3857,
  "latestWkid": 3857
 },
 "features":[
 {
 "attributes":{
  "Name":"POI1", 
  "TimeWindowStart1": 1367820000,
  "TimeWindowEnd1": 1367848800,
  "MaxViolationTime1":0,
  "ServiceTime":10
 },
 "geometry":{"x":739116,"y":6404262.603}
 },
 {
 "attributes":{
  "Name":"POI2",
  "TimeWindowStart1": 1367820000,
  "TimeWindowEnd1": 1367848800,
  "MaxViolationTime1":0,
  "ServiceTime":10
 },
 "geometry":{"x":739216,"y":6404262.603}
 }
 ]
}
&routes={
 "displayFieldName": "Route",
 "features": [
 {
 "attributes":{
  "Name":"myRoute", 
  "StartDepotName":"myStartPoint", 
  "EndDepotName":"myEndPoint",
  "EarliestStartTime": 1367820000,
  "LatestStartTime": 1367820000,
  "MaxOrderCount": 30
 }
 }
 ],
 "exceededTransferLimit": false
}
&depots={
 "displayFieldName": "Start- and Endpoint",
 "geometryType": "esriGeometryPoint",
 "spatialReference": {
  "wkid": 3857,
  "latestWkid": 3857
 },
 "features": [
 {
 "attributes":{
  "Name":"myStartPoint"
 },
 "geometry":{"x":739612,"y":6404755}
 },
  {
 "attributes":{
  "Name":"myEndPoint"
 },
 "geometry":{"x":739612,"y":6404755}
 }
 ]
}
Tags (2)
0 Kudos
7 Replies
MattCrowder
Esri Contributor
That date/time doesn�??t look right.  For example, 1367820000 is Fri, 16 Jan 1970 19:57:00 UTC.  Why aren�??t you passing in the real date instead of one from 1970?

If you wanted to set the start time window for 10 AM, you should pass in 10 AM UTC.  We will them interpret that as 10 AM local time.

So for Fri May 17 10:00:00 UTC 2013, that would be TimeWindowStart1 of 1368784800000.

You�??d also need to specify the defaultDate.  For this, you can just pass in the same as EarliestStartTime from   the route.


Here�??s what I passed into my service that worked:
default_date: 1368784800000
orders: {
"displayFieldName": "POIs",
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 3857,
"latestWkid": 3857
},
"features":[
{
"attributes":{
"Name":"POI1",
"TimeWindowStart1": 1368784800000,
"TimeWindowEnd1": 1368784800000,
"MaxViolationTime1":0,
"ServiceTime":10
},
"geometry":{"x":739116,"y":6404262.603}
},
{
"attributes":{
"Name":"POI2",
"TimeWindowStart1": 1368784800000,
"TimeWindowEnd1": 1368813600000,
"MaxViolationTime1":0,
"ServiceTime":10
},
"geometry":{"x":739216,"y":6404262.603}
}
]
}

depots: {
"displayFieldName": "Start- and Endpoint",
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 3857,
"latestWkid": 3857
},
"features": [
{
"attributes":{
"Name":"myStartPoint"
},
"geometry":{"x":739612,"y":6404755}
},
{
"attributes":{
"Name":"myEndPoint"
},
"geometry":{"x":739612,"y":6404755}
}
]
}

routes: {
"displayFieldName": "Route",
"features": [
{
"attributes":{
"Name":"myRoute",
"StartDepotName":"myStartPoint",
"EndDepotName":"myEndPoint",
"EarliestStartTime": 1368777600000,
"LatestStartTime": 1368784800000,
"MaxOrderCount": 30
}
}
],
"exceededTransferLimit": false
}

By the way, change your GP service parameters to have Message Level = "Info".  That way, you can sometimes get good info as to what the problem may be.
For example, if I didn�??t set the DefaultDate, it didn�??t work.  Looking at the messages, I saw these that indicated a potential problem:
�?� esriJobMessageTypeInformative: Running script SolveVehicleRoutingProblem...
�?� esriJobMessageTypeWarning: Depots, Routes, Orders and Breaks contain time windows with dates but the DefaultDate value does not have a date.
�?� esriJobMessageTypeWarning: WARNING 030088: Solve returned an error, but errors were converted to warnings.
�?� esriJobMessageTypeWarning: WARNING 030092: VRP Solver failed due to invalid input.

I then went here: http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Vehicle_Routing_Problem_Service/02r3...  and read the doc on what to pass for Default Date.

Anyway, hope this helps.

matt
0 Kudos
NicolasCaspari
New Contributor
Thank you for your useful hints, Matt. Unfortunately, the addition of the default_date and the correction of the time format did not solve the problem. But I think it got me a bit closer to the real problem.

Now I used the default_date with with unix time stamp in miliseconds and set the times of orders and depot in the format of "10:00 AM UTC". Now I get a time constraint violation for the orders ("ViolatedConstraints": 32)

If I take out the line "MaxViolationTime1":0 from the orders in my REST url, a route is calculated with correct travel times and distances and I can see the results. Especially the following lines (attributes of output route) caught my eye:

...
"TotalCost": 42.5174562651664,
"RegularTimeCost": 42.5174562651664,
...
"TotalTime": 42.5174562651664,
"TotalOrderServiceTime": 20,
...
"TotalTravelTime": 22.517456265166402,
...
"StartTime": 1369180800000,
"EndTime": 1369183351047,
...
"TotalViolationTime": 30.35018770210445,
...

 
I can change the default date and the earliest/latest start time, but the route starts still on the current date, at 2 AM. Could it be that some date and time options are "hard coded" somewhere in the module that was used to create the geoprocessing service? I checked the module again and can't find any options to change default date and time settings.
0 Kudos
MattCrowder
Esri Contributor
Can you please include all the parameters that you're passing in to the REST request so I can reproduce locally and understand what's going on?

Thanks,

Matt
0 Kudos
NicolasCaspari
New Contributor
Hi Matt, thanks for looking into this again. Here's the REST request that I am using now:

http://koopunifhtrier.alta4cloud.com/arcgis/rest/services/koop_uni_fh_trier/TrierApp/GPServer/SolveVRP/submitJob?
default_date=1368784800000
&orders={
 "displayFieldName": "POIs",
 "geometryType": "esriGeometryPoint",
 "spatialReference": {
  "wkid": 3857,
  "latestWkid": 3857
 },
 "features":[
 {
 "attributes":{
  "Name":"POI1", 
  "TimeWindowStart1": "10:00:00 AM UTC",
  "TimeWindowEnd1": "10:00:00 PM UTC",
  "ServiceTime":10
 },
 "geometry":{"x":738459,"y":6403815}
 },
 {
 "attributes":{
  "Name":"POI2",
  "TimeWindowStart1": "10:00:00 AM UTC",
  "TimeWindowEnd1": "10:00:00 PM UTC",
  "ServiceTime":10
 },
 "geometry":{"x":738747,"y":6403143}
 }
 ]
}
&routes={
 "displayFieldName": "Route",
 "features": [
 {
 "attributes":{
  "Name":"myRoute", 
  "StartDepotName":"myStartPoint", 
  "EndDepotName":"myEndPoint",
  "EarliestStartTime": "10:00:00 AM UTC",
  "LatestStartTime": "10:00:00 AM UTC",
  "MaxOrderCount": 30
 }
 }
 ],
 "exceededTransferLimit": false
}
&depots={
 "displayFieldName": "Start- and Endpoint",
 "geometryType": "esriGeometryPoint",
 "spatialReference": {
  "wkid": 3857,
  "latestWkid": 3857
 },
 "features": [
 {
 "attributes":{
  "Name":"myStartPoint"
 },
 "geometry":{"x":739213,"y":6403433}
 },
  {
 "attributes":{
  "Name":"myEndPoint"
 },
 "geometry":{"x":739213,"y":6403433}
 }
 ]
}


Another idea just crossed my mind: When I initially created the road shapefile that I used to create the network dataset, I included a column for TimeZoneID and added a TimeZone table as described here: http://resources.arcgis.com/en/help/main/10.1/index.html#//0047000001r7000000. According to the ArcGIS Help this is necessary to get output directions. Because the output direcdtions didn't work, I removed the TimeZones table, but the roads shape file still had the field TimeZoneID when I built the network dataset. Maybe this could cause issues with the default time?
0 Kudos
MattCrowder
Esri Contributor
for your orders and route, you are passing in the times as strings, rather than the number of milliseconds since epoch (January 1, 1970) in UTC.   The string based representation of dates has been deprecated at 10 and is no longer supported.

I'm pretty sure when converting from REST, these values are not being converted into proper dates and are treated as 0 (which would equal 12 AM).

I have verified that if you pass in the correct numeric values corresponding to 10 AM UTC (passing in 1368784800000) and 10 PM UTC (passing in 1368828000000) and passing in the default_date = 1368784800000, then things work correctly.

Can you confirm?

matt
0 Kudos
NicolasCaspari
New Contributor
I can confirm that when I use the numeric values, no time constraints are violated and the status returned for the orders is 0 (according to the help page this means "OK (0)�??The network location was successfully evaluated."). Here's the parameters that I used: default_date, TimeWindowStart1, EarliestStartTime and LatestStartTime: 1368784800000 (Fri, 17 May 2013 10:00:00 GMT). TimeWindowEnd1: 1368820800000 (Fri, 17 May 2013 20:00:00 GMT).

Still, the orders are not assigned to the route.

I also tried to use the current date and a broad  time window range. The orderes are not assigend to a route.
default_date, TimeWindowStart1, EarliestStartTime and LatestStartTime: 1369353600000 (Fri, 24 May 2013 00:00:00 GMT). TimeWindowEnd1: 1369439940000 (Fri, 24 May 2013 23:59:00 GMT)

If I take out the time windows, and only pass the default_date, e.g. 1368784800000 (Fri, 17 May 2013 10:00:00 GMT), the output route still starts at 1369389600000 (current date, 10 AM). It seems that the default date is not accepted in the REST request.

When I use the service on the ArcGIS Server in my ArcGIS Desktop and enter orders, depots and routes interactively, the service works correctly, using the current date as default date and considering the EarliestStartTime.
0 Kudos
MattCrowder
Esri Contributor
I don't know what you're doing differently.  When I pass in the following, it works correctly for me (the 2 orders get added to the route):

orders:
{
"displayFieldName": "POIs",
"geometryType": "esriGeometryPoint",
"spatialReference": {
  "wkid": 3857,
  "latestWkid": 3857
},
"features":[
{
"attributes":{
"Name":"POI1", "TimeWindowStart1": 1368784800000,
"TimeWindowEnd1": 1368828000000,
"ServiceTime":10
},
"geometry":{"x":738459,"y":6403815}
},
{
"attributes":{
"Name":"POI2",
"TimeWindowStart1": 1368784800000,
"TimeWindowEnd1": 1368828000000,
"ServiceTime":10
},
"geometry":{"x":738747,"y":6403143}
}
]
}

depots:
{
"displayFieldName": "Start- and Endpoint",
"geometryType": "esriGeometryPoint",
"spatialReference": {
  "wkid": 3857,
  "latestWkid": 3857
},
"features": [
{
"attributes":{
"Name":"myStartPoint"
},
"geometry":{"x":739213,"y":6403433}
},
  {
"attributes":{
"Name":"myEndPoint"
},
"geometry":{"x":739213,"y":6403433}
}
]
}

routes:
{
"displayFieldName": "Route",
"features": [
{
"attributes":{
"Name":"myRoute", "StartDepotName":"myStartPoint", "EndDepotName":"myEndPoint",
"EarliestStartTime": 1368784800000,
"LatestStartTime": 1368784800000,
"MaxOrderCount": 30
}
}
],
"exceededTransferLimit": false
}

default date: 1368784800000

-----

output:
info from routes:
"features": [{
   "attributes": {
    "ObjectID": 1,
    "Name": "myRoute",
    "ViolatedConstraints": null,
    "OrderCount": 2,
    "TotalCost": 28.204576460644603,
    "RegularTimeCost": 28.204576460644603,
    "OvertimeCost": 0,
    "DistanceCost": 0,
    "TotalTime": 28.204576460644603,
    "TotalOrderServiceTime": 20,
    "TotalBreakServiceTime": 0,
    "TotalTravelTime": 8.204576460644603,
    "TotalDistance": 2.1846002201207435,
    "StartTime": 1368784800000,
    "EndTime": 1368786492275,
    "TotalWaitTime": 0,
    "TotalViolationTime": 0,
    "RenewalCount": 0,
    "TotalRenewalServiceTime": 0,
    "Shape_Length": 0.03965315719801789
   },


from out_stops:
  "features": [
   {"attributes": {
    "ObjectID": 1,
    "Name": "POI1",
    "PickupQuantities": "",
    "DeliveryQuantities": "",
    "StopType": 0,
    "RouteName": "myRoute",
    "Sequence": 3,
    "FromPrevTravelTime": 1.9393302872776985,
    "FromPrevDistance": 0.4956385305662407,
    "ArriveCurbApproach": 0,
    "DepartCurbApproach": 0,
    "ArriveTime": 1368785587343,
    "DepartTime": 1368786187343,
    "WaitTime": 0,
    "ViolationTime": 0,
    "ArriveTimeUTC": 1368778387343,
    "DepartTimeUTC": 1368778987343
   }},
   {"attributes": {
    "ObjectID": 2,
    "Name": "POI2",
    "PickupQuantities": "",
    "DeliveryQuantities": "",
    "StopType": 0,
    "RouteName": "myRoute",
    "Sequence": 2,
    "FromPrevTravelTime": 1.1830458752810955,
    "FromPrevDistance": 0.35046338018190065,
    "ArriveCurbApproach": 0,
    "DepartCurbApproach": 0,
    "ArriveTime": 1368784870983,
    "DepartTime": 1368785470983,
    "WaitTime": 0,
    "ViolationTime": 0,
    "ArriveTimeUTC": 1368777670983,
    "DepartTimeUTC": 1368778270983
   }},
   {"attributes": {
    "ObjectID": 3,
    "Name": "myStartPoint",
    "PickupQuantities": "0.000000",
    "DeliveryQuantities": "0.000000",
    "StopType": 1,
    "RouteName": "myRoute",
    "Sequence": 1,
    "FromPrevTravelTime": 0,
    "FromPrevDistance": 0,
    "ArriveCurbApproach": 0,
    "DepartCurbApproach": 0,
    "ArriveTime": 1368784800000,
    "DepartTime": 1368784800000,
    "WaitTime": 0,
    "ViolationTime": 0,
    "ArriveTimeUTC": 1368777600000,
    "DepartTimeUTC": 1368777600000
   }},
   {"attributes": {
    "ObjectID": 4,
    "Name": "myEndPoint",
    "PickupQuantities": "0.000000",
    "DeliveryQuantities": "0.000000",
    "StopType": 1,
    "RouteName": "myRoute",
    "Sequence": 4,
    "FromPrevTravelTime": 5.082200298085809,
    "FromPrevDistance": 1.338498309372602,
    "ArriveCurbApproach": 0,
    "DepartCurbApproach": 0,
    "ArriveTime": 1368786492275,
    "DepartTime": 1368786492275,
    "WaitTime": 0,
    "ViolationTime": 0,
    "ArriveTimeUTC": 1368779292275,
    "DepartTimeUTC": 1368779292275
   }}
  ],
  "exceededTransferLimit": false
}
}
0 Kudos