itinero / routing

The routing core of itinero.
Apache License 2.0
222 stars 71 forks source link

Contracted Network has routing issues. #181

Open mikerussellnz opened 6 years ago

mikerussellnz commented 6 years ago

Hi

I am having some issues with routing when using a contracted network. When using a contracted network I am seeing issues where the route is very strange. See screenshots below with comparison of route section with contracted and non-contracted network.

The OSM data I am using is: "new-zealand-latest.osm.pbf"

Code:

using Itinero;
using Itinero.IO.Osm;
using Itinero.Osm.Vehicles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Itinero
{
    class Program
    {
        static void Main(string[] args)
        {
            var routerDb = new RouterDb();
            /*  using (var stream = new FileInfo(@"c:\tmp\new-zealand-latest.osm.pbf").OpenRead())
              {
                  routerDb.LoadOsmData(stream, Vehicle.Car); // create the network for cars only.
              }

              //routerDb.AddContracted(Vehicle.Car.Fastest());

              using (var stream = new FileInfo(@"c:\tmp\new-zealand-nc.routerdb").OpenWrite())
              {
                  routerDb.Serialize(stream);
              }
             */

            using (var stream = new FileInfo(@"c:\tmp\new-zealand-nc.routerdb").OpenRead())
            {
                routerDb = RouterDb.Deserialize(stream);
            }

            // create a router.
            var router = new Router(routerDb);

            // get a profile.
            var profile = Vehicle.Car.Fastest(); // the default OSM car profile.

            // create a routerpoint from a location.
            // snaps the given location to the nearest routable edge.
            var start = router.Resolve(profile, -43.5321f, 172.6362f);
            var end = router.Resolve(profile, -45.031162f, 168.662643f);

            // calculate a route.
            var route = router.Calculate(profile, start, end);

            using (var sw = new StreamWriter(@"c:\tmp\points-nc.txt"))
            {
                route.WriteGeoJson(sw);
            }
        }
    }
}

Contracted: contracted

Non contracted: non-contracted

xivk commented 6 years ago

Ouwch, that looks bad, I'll have a look at this.

xivk commented 6 years ago

I just tried this out, I can't seem to reproduce this, I get identical routes in both cases:

http://geojson.io/#id=gist:xivk/a952bb08244b9dc9254205880b1afbdf&map=8/-44.301/170.650 http://geojson.io/#id=gist:xivk/3a98c9f5e2f97a9ab18b882cf6179176&map=8/-44.301/170.650

Did you use the default profile? Perhaps it only works on the New Zealand file from yesterday? What version did you use to test? The latest prerelease or the stable?

mikerussellnz commented 6 years ago

I have just tried with the latest OSM file and the issue does not reproduce. Perhaps that is due to a difference in the ordering of the data in the file. The issue only happens when contraction is enabled so it appears to be something related to the way the nodes are being contracted.

This data file reproduces the issue: https://www.dropbox.com/s/x25mnsahogkop2g/new-zealand-latest.osm.pbf?dl=0

I am using version 1.4.0-pre44.

xivk commented 6 years ago

Ok, thanks, I'll have a look. It's definitely possible that this only happens with a specific file. It's going to take me some to figure this out.

xivk commented 6 years ago

Narrowed this down to an issue with the combination of turn-restrictions and edge-based contraction. The route is fine when using an uncontracted network and a contracted network without turn-restrictions. The route has the issue above when using a contracted network combined with turn-restrictions.

shkarface commented 4 years ago

Is there a fix for issues like this? I get issues like this on my routings all the time, especially with the Classifications profile, sometimes it does a turn from highway trunk to residential and then back to the highway trunk for no reason.. :/