Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.42k stars 3.4k forks source link

OSRM Wrong Way_point Index on trip #4987

Closed malizahid closed 6 years ago

malizahid commented 6 years ago

Hello ,

First of all i would like to thank the entire osrm community for such an amazing utility . I have done a local installation of OSRM and trying to use Trip Service . When i try to create a sequence of customers that needs to be visited from Waypoint indexes , its coming all wrong . Can someone guide if its a bug or I am missing something ? I used the same waypoints on google direction service and i am getting the correct result . Interestingly when i look at leg distance and duration it makes sense to me .

This is my rest api http://192.168.30.212:5000/trip/v1/driving/74.250539,31.391017;74.299433,31.5370146666667;74.3118733333334,31.5393675;74.293136,31.5362431666667;74.2978316666667,31.5393746666667?source=first&roundtrip=true

Please help.

Thanks, ALi

malizahid commented 6 years ago

Here is my output

{ "code":"Ok", "waypoints":[ { "waypoint_index":0, "trips_index":0, "hint":"RvAIgPRqDoCeAAAAwAAAAAAAAABzAQAAngAAAMAAAAAAAAAAcwEAAAQAAAAW-2wEYQTfASv5bAQp_d4BAABvBv3TL_8=", "location":[ 74.25103, 31.392865 ], "name":"Defense Road" }, { "waypoint_index":2, "trips_index":0, "hint":"mtcJgCvuD4ATAAAANwAAAAAAAAAAAAAAEwAAADcAAAAAAAAAAAAAAAQAAAAquG0EezfhASm4bQR3N-EBAACvBv3TL_8=", "location":[ 74.299434, 31.537019 ], "name":"" }, { "waypoint_index":1, "trips_index":0, "hint":"gsUAgCiUCIApAQAADwAAAAAAAAAAAAAAKQEAAA8AAAAAAAAAAAAAAAQAAADD6G0EwkDhAcHobQSoQOEBAAAvEf3TL_8=", "location":[ 74.311875, 31.539394 ], "name":"" }, { "waypoint_index":4, "trips_index":0, "hint":"scUAgLPFAIBVAAAAHgAAAAAAAAAAAAAAVQAAAB4AAAAAAAAAAAAAAAQAAAB7n20EODThAZCfbQRzNOEBAAD_Ef3TL_8=", "location":[ 74.293115, 31.536184 ], "name":"Bastami Road" }, { "waypoint_index":3, "trips_index":0, "hint":"L5YIgDPuD4BOAAAAKwAAAAAAAAAAAAAATgAAACsAAAAAAAAAAAAAAAQAAADzsW0ErEDhAeixbQSvQOEBAABfDP3TL_8=", "location":[ 74.297843, 31.539372 ], "name":"Rahmat Ali Road" } ], "trips":[ { "legs":[ { "steps":[

           ],
           "weight":5044.2,
           "distance":20530.2,
           "summary":"",
           "duration":5044.2
        },
        {
           "steps":[

           ],
           "weight":439.8,
           "distance":1657.8,
           "summary":"",
           "duration":439.8
        },
        {
           "steps":[

           ],
           "weight":118,
           "distance":468.4,
           "summary":"",
           "duration":118
        },
        {
           "steps":[

           ],
           "weight":170.8,
           "distance":692.4,
           "summary":"",
           "duration":170.8
        },
        {
           "steps":[

           ],
           "weight":4880.4,
           "distance":19958.2,
           "summary":"",
           "duration":4880.4
        }
     ],
     "weight_name":"duration",
     "geometry":"mlr~D}cedM}p@oB^cZoRkAqcBk~AFsn@ml@oh@e_HktCetAn^_pAoiAmZ|^mt@kq@oSxWoc@nO}@pMk_@~@uD}H_a@wKsFtGuZbCdEqAjH|^mM`e@tLjIeDpOoHsEfW`UiClFmEjJ`JpG~jA`k@`jBxoA~tBbz@rX~o@jh@xu@v[xN`KmPzCfKljBmTjN~O~NuCjO}`@beAqoAbYrW~x@oAGnNh_@x@OnJpJ~Ev{BjI",
     "weight":10653.2,
     "distance":43307,
     "duration":10653.2
  }

] }

danpat commented 6 years ago

@malizahid The /trip service will specifically re-order your waypoints in order to produce the shortest possible route between all points..

If you want to follow the waypoints in the order you supply, you should use the /route service.

malizahid commented 6 years ago

@danpat Thanks for your quick response . I do understand that the waypoints sequence will be different from my supplied ordered and the result of the waypoint index order would be according to TSP (Travelling Salesman Problem ) algorithm . So let me explain what i did . I used the table matrix and from that i manually applied TSP algorithm from my c# code and i got a sequence (which is somehow close to what i get from google distance api using optimization ) . But the sequence and waypoint index sequence that is generated from trip service is incorrect .

malizahid commented 6 years ago

Below 2 tables will provide the summary . One is from Google maps and other one is from OSRM

Google

Total Distance | Total Duration 54.58 KMs | 104.47 MINs

Sno | Name | Distance(KMs) | Duration(Mins) 1 | 2101379 - Al Makkah General Store | 29.05 KM | 50.92 Mn 2 | 2234722 - Sheraz General Store | 0.10 KM | 0.60 Mn 3 | 2031070 - Medicine Medical Store | 1.15 KM | 6.38 Mn 4 | 2137439 - ABDULLAH STORE | 0.39 KM | 2.47 Mn 5 | WareHouse | 23.90 KM | 44.10 Mins

OSRM

Total Distance(KM) : 45.52 Total Duration(Mins) : 186.57

no | Name | Distance | Duration | Summary | Steps 0 | 2137439 - ABDULLAH STORE | 21.78 | 90.21 | Defense Road |   1 | 2031070 - Medicine Medical Store | 0.1 | 0.41 | Shamnagar Road |   2 | 2234722 - Sheraz General Store | 1.15 | 4.58 | Khawaja Fareed Road |   3 | 2101379 - Al Makkah General Store | 0.37 | 1.51 |   |   4 | WareHouse | 22.13 | 89.86 | Khawaja Fareed Road |  

http://192.168.30.212:5001/trip/v1/driving/74.250539,31.391017;74.3016163333333,31.5542738333333;74.2886025,31.5538888333333;74.3053131666667,31.5542386666667;74.2896245,31.5541608333333;74.250539,31.391017?source=first&destination=last

danpat commented 6 years ago

It's not reasonable to expect identical results when comparing to a different service. Off the top of my head, the following things could be problems:

  1. The geometry of the road network will be different (Google vs OSM):
    1. The coordinates you supply might get snapped to a different start/end point
    2. Not all roads will be identical for route-finding on two different maps, leading to different paths being chosen for some coordinate pairs
  2. Google has traffic data for much of their map - OSRM does not (unless you have loaded in your own traffic data). This will affect calculated traffic times, and will change the result matrix that is used as input to the optimization engine.

For optimization problems when you supply fewer than 10 coordinates, OSRM's /trip plugin uses a brute-force search, so it should return optimal results. Any difference will come down to what data it has to work with.

malizahid commented 6 years ago

@danpat . Thanks again for the explanation . I think probably i was not able to explain the issue correctly . Let me explain by an example .

Below is the table and the sequence of which Long & Lat were supplied in the API image

TRIP SERVICE http://192.168.30.212:5000/trip/v1/driving/74.250539,31.391017;74.2470973333333,31.4506866666667;74.2411878333333,31.4722476666667;74.255245,31.3948445;74.2147775,31.4316043333333;74.2057603333333,31.4317878333333;74.21027,31.4278811666667;74.2155973333333,31.435827;74.2156036666667,31.4344656666667;74.2147201666667,31.4314903333333;74.2131683333333,31.437859;74.21851,31.4524076666667;74.2086126666667,31.4371266666667;74.1848413333333,31.4213243333333?source=first&roundtrip=true

TABLE SERVICE http://192.168.30.212:5000/table/v1/driving/74.250539,31.391017;74.2470973333333,31.4506866666667;74.2411878333333,31.4722476666667;74.255245,31.3948445;74.2147775,31.4316043333333;74.2057603333333,31.4317878333333;74.21027,31.4278811666667;74.2155973333333,31.435827;74.2156036666667,31.4344656666667;74.2147201666667,31.4314903333333;74.2131683333333,31.437859;74.21851,31.4524076666667;74.2086126666667,31.4371266666667;74.1848413333333,31.4213243333333

Way Point Index Generated from Trip Service

image

Below is the Table Generated from Trip Service

image

Table Generated from Table Service

image

Now the Issue over here is that if you compare the Trip Service distance with Table service distance one by one and if you map the names of the customer from Trip and Table service , it wont match . The customer names from the Trip Service table is generated by looking up names from first table according to waypoint index order .

Lets take an example of second row in Trip Service which is "Asim Store" and its distance is 2002.4 . If you look at Asim Store in Table service its distance is 2980.5 . I am not sure if i missing something or if this is the correct way to verify .

Please help .

malizahid commented 6 years ago

I am also attaching the Json from Trip and Table service

Table.txt Trip.txt

Anyaoha commented 5 years ago

I have a question about working with osrmTrip.

I run a localhost in my computer for osrm. But I can calculate the osrmTable for 553 coordinate points using the osrm-routed --max-table-size=100000000 map.xml.osrm But when I tried usint the osrmTrip function I get this response The OSRM server returned an error: Error: TooBig Too many trip coordinates.

How do I remove the restriction here.

When I work with 100 coodinate points, it works fine.
But when I work with anything above 100, even 101, Then I get the error message.

danpat commented 5 years ago

@Anyaoha Try doing osrm-routed --help - there are several different parameters you can set - there's a different one for the /trip plugin.

Anyaoha commented 5 years ago

@danpat I think it managed to work. Thanks for your help. You have indeed been helpful.

I am currently working to dynamize route for certain locations so that's the reason I want to get the normal plots to visualize before trying to find another package that will help dynamize the route.