itinero / routing

The routing core of itinero.
Apache License 2.0
221 stars 69 forks source link

Question: use of vehicle specific db #11

Closed alecava58 closed 8 years ago

alecava58 commented 8 years ago

I created a test (see below) for hazmat tag and it works as expected if I create 2 RouterDb, one regarding the new hazmat vehicle and another regarding the BigTruck vehicle (without hazmat restriction).

If I create only one RouterDb using both the vehicles using var routerDbHaz = Runner.GetTestBuildRouterDb(Download.LuxembourgLocal, false, false, new Vehicle[] { hazmatTruck, Vehicle.BigTruck }).TestPerf("Build Luxemburg router db for Hazmat BigTruck.");

it doesn't work as expected (both route results have the same distance).

Is that ok?

            // TEST4: create custom vehicle with hazmat route restrictions
            // create a custom vehicle
            Vehicle hazmatTruck = new HazmatTruck();

            // create a routeDb for hazmat BigTruck
            var routerDbHaz = Runner.GetTestBuildRouterDb(Download.LuxembourgLocal, false, false, hazmatTruck).TestPerf("Build Luxemburg router db for Hazmat BigTruck.");
            var routerHaz = new Router(routerDbHaz);
            var routerDbBig = Runner.GetTestBuildRouterDb(Download.LuxembourgLocal, false, false, Vehicle.BigTruck).TestPerf("Build Luxemburg router db for Hazmat BigTruck.");
            var routerBig = new Router(routerDbBig);

            // test use of hazmat tag ("Tunnel Renè Konen" Luxemburg, tunnell with hazmat restriction)
            var loc1 = new Coordinate(49.606503f, 6.133672f);
            var loc2 = new Coordinate(49.614077f, 6.131351f);
            Coordinate[] rp = { loc1, loc2 };
            var hazRoute = routerHaz.Calculate(hazmatTruck.Shortest(), rp);
            var carRoute = routerBig.Calculate(Vehicle.BigTruck.Shortest(), rp);

            // the distances must be different
            _logger.Log(TraceEventType.Information, string.Format("BigTruck distance {0}, BigTruck with Hazmat restriction distance {1}", carRoute.TotalDistance, hazRoute.TotalDistance));
xivk commented 8 years ago

Normally this should be possible without any issue by using the same RouterDb. Do the two profiles have different names?

alecava58 commented 8 years ago

The two profiles have the same name (shortest) but different vehicles.

xivk commented 8 years ago

All profiles much have unique names. What does hazmatTruck.Shortest().Name return?

alecava58 commented 8 years ago

Return Hazmat.Shortest

xivk commented 8 years ago

ok, I'll try and repeat this test and see what I can find...

alecava58 commented 8 years ago

Attached you can find my Hazmat class along with my MixedProfile class.

Tests.zip

alecava58 commented 8 years ago

Here there is the class Hazmat updated with vehicle dimensions check.

Hazmat.zip

xivk commented 8 years ago

@alecava58 Are you sure the dimension tags are present in the OSM-data?

alecava58 commented 8 years ago

I selected a short segment where there is the dimension tag but I'm not sure if the dimension tag is still there in the router db. If you are confident that the routing engine takes care of the dimension tag I'll check in debug.

I've created a custom vehicle where I override the IsReleventForProfile fuction as follow:

        // Dimensions relevant tags
        private static HashSet<string> _relevantProfileKeys = new HashSet<string> { "maxheight", "maxlength", "maxweight", "maxwidth" };

        /// <summary>
        /// Returns true if the given key is relevant for the given profile.
        /// </summary>
        public override bool IsRelevantForProfile(string key)
        {
            if (base.IsRelevantForProfile(key))
            {
                return true;
            }

            if (key.StartsWith("hazmat"))
            { // include hazmat tag.
                return true;
            }

            return _relevantProfileKeys.Contains(key);
        }

Is this ok?

regards

alecava58 commented 8 years ago

I made some tests and may be I did not understand how weight restriction works:

I have a custom vehicle that I can set the maxweight.

If I create a routerdb using a vehicle with maxweight = 40000 than the routing engine takes care of the maxweight restriction even if I set the vehicle maxweight property maxweight=0 (it doesn't matter the value of maxweight property of the vehicle)

If I create a routerdb using a vehicle with maxweight = 0 than the routing engine doesn't take care of the maxweight restriction even if I set the vehicle maxweight property maxweight = 40000

So I think that: Changing the vehicle properties (after you have created the routerdb) don't change the routing calculation what is important is how you have created the routingdb.

I'm wrong?

alecava58 commented 8 years ago

To complete the info I used Rue Pierre de Coubertin - Luxemburg calculating a route from 49.607852, 6.143440 to 49.605363, 6.142153

xivk commented 8 years ago

You also need to make sure that tags normalization is disabled:

https://github.com/itinero/routing/blob/develop/src/Itinero.IO.Osm/Streams/RouterDbStreamTarget.cs#L54 =>set normalizeTags to false.

alecava58 commented 8 years ago

Disabling tags normalization works very well.

Thanks.