itinero / routing

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

Considerable difference between contracted and non-contracted routes #311

Open tmdorum opened 4 years ago

tmdorum commented 4 years ago

I have two routes in Norway, same coordinates and "car.classifications" profile. The first is calculated with a router database with a contracted profile and the second is calculated with a router database without a contracted profile.

Both routes should be identical but they are not, and the route with the contracted profile has some strange choices. The non-contracted route is similar to what Google maps shows, but the contracted route is very different.

I'm using Itinero 1.5. I've also tried the latest pre-release with the same result.

Start position: 68 51 40.86N 18 20 54.30E End position: 69 23 28.09N 20 16 02.13E

Non-contracted route (correct route): image

Contracted route (incorrect route): image

I want to have a contracted route that looks like the non-contracted image. Both routes should also be identical regardless of contracted and non-contracted profiles.

Any help would be much appreciated!

airbreather commented 4 years ago

Possible duplicate of #267?

tmdorum commented 4 years ago

To be able to use this routing library, routing with contracted profiles must generate the correct route. Is anyone looking into this issue for a possible fix?

juliusfriedman commented 4 years ago

this requires the newest develop instance of Reminisce, the problem is that locking was not occurring for reading on Index's. after the latest develop is built you can link that to the build I reference below and should not experience this.

See also

https://github.com/itinero/routing/pull/302

Be weary I had some issues with contractions with the Change on MaxDistanceSplitter

So if you have issue contracting see:

https://github.com/itinero/routing/issues/306

tmdorum commented 4 years ago

I've tried with the latest develop instance of Reminiscence with the same result. I've also tried with the latest develop instance of OsmSharp, Itinero.IO.Osm and Itinero as well, but still the same result.

I've attached two routerdb databases which can be used to reproduce the issue.

Using the "car.classifications" profile, the routerdb "norway-extract.osm.routerdb" and "norway-extract-contracted.osm.routerdb" with the following coordinates will reproduce the issue:

Start latitude: 68.86135 Start longitude: 18.3484173

Stop latitude: 69.3911362 Stop longitude: 20.2672577

RouterDB.zip

juliusfriedman commented 4 years ago

Can you try on https://github.com/itinero/routing/pull/302 and by linking Reminiscence with it locally?

Let me know if you still have issues and I will take a look

tmdorum commented 4 years ago

I've tried your branch in #302 and linked develop of Reminiscence, but the result is the same. If you try the router databases attached above you can easily reproduce the issue.

tmdorum commented 4 years ago

When contracting the profile after loading the OSM data without restrictions and using the AugmentedWeightHandler, the route is correctly calculated.

So it seems that contracted profiles with restrictions is the problem here.

tmdorum commented 4 years ago

Is there any progress on this issue?

juliusfriedman commented 4 years ago

I d k, @xivk hasn't been around here for some time, he was active in OsmSharp where my PR was merged and the version was increased https://github.com/OsmSharp/core/pull/101.

Is there anyway I can be of assistance? Are you using Turn based routing?

juliusfriedman commented 4 years ago

P.s.

I think you can also fix this in WeightMatrixAlgorithm:

There's definitely improvement as the Weight class offers more than I am using here.

//295
//Todo hope this is correct but tis seems the GetAugmentedWeightHandler is not really used afaik
            //Allocations may be heavy here
            if (_router.Db.HasContractedFor(_profile.Profile))
            {
                var weightsResult = _router.TryCalculateWeight(_profile, _router.GetAugmentedWeightHandler(_profile), locations);
                var v = weightsResult.Value;
                _weights = new float[v.Length][];
                for (int i = 0, e = v.Length; i < e; ++i)
                {
                    int j = v[i].Length;
                    _weights[i] = new float[j];
                    for (; j >= 0; --j)
                    {
                        _weights[i][j] = v[i][j].Value;
                    }
                }
            }
            else
            {
                var weightsResult = _router.TryCalculateWeight(_profile, _weightHandler, locations, locations,
               nonNullInvalids, nonNullInvalids, _settings);
                _weights = weightsResult.Value;
            }
xivk commented 4 years ago

Hey, sorry all, very busy with my day job. I still follow here but fixing this (and first figuring out what the root cause is) will take me a few days (at least) and I still haven't found the spare time.

tmdorum commented 4 years ago

I'm not sure how to use the "TryCalculateWeight" code above.

I generate a contracted database once and save it, and load it later using deserialization for performance reasons.

Most of the issues occur when contracting the profile after loading the OSM data with restrictions (I guess this is what you call "turn based routing"), but there are a few issues that occur without restrictions as well as shown bellow.

So there are issues as the ones bellow as well as the ones at the top of this issue related to contracted databases.

image image

I don't think there is a workaround for all of these issues as I have tried for a while now without any luck.

tmdorum commented 4 years ago

Is there any progress on this issue?

tmdorum commented 3 years ago

Is there any feedback or progress for a solution for this issue?