Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router CalculateWeight outputs with lots of float.MaxValue between RouterPoints #310

Open
dmitrykudin opened this issue Apr 24, 2020 · 1 comment

Comments

@dmitrykudin
Copy link

Hello!
I'm currently trying to test some features from Itinero for my project, which is intended to optimize routes for delivery. My problem is that I'm getting too much float.MaxValue values after using CalculateWeight method.

I'm generating some random Coordinates on a map using the following code:

private static readonly Random Random = new Random(DateTime.Now.Millisecond);

private static Coordinate CoordinateFrom(RouterDb routerDb)
{
    var edgeId = Random.Next((int) routerDb.Network.EdgeCount);
    var vertexId = Random.Next((int) routerDb.Network.VertexCount);
    var vertex = routerDb.Network.GetVertex((uint) vertexId);
    var offset = Random.Next(ushort.MaxValue);

    var routerPoint = new RouterPoint(vertex.Latitude, vertex.Longitude, (uint) edgeId, (ushort) offset);
    return routerPoint.LocationOnNetwork(routerDb);
}

As a data sample I'm using one district of a city, which is bounded as from the following link: https://www.openstreetmap.org/relation/1114902#map=14/59.9337/30.3733.

For example, I can generate 5 points from this district:

59.93972,30.34416
59.94451,30.38116
59.92726,30.34568
59.94274,30.38885
59.92598,30.35297

With some generated points I'm trying to use .CalculateWeight method, but nearly always it returns matrix containing from 20 to 80 percent of float.MaxValue values. I tried to .CalculateWeight with default weight handler like in the following:

var withDefaultWeightHandler = router.CalculateWeight(Vehicle.Car.Fastest(), resolvedPoints, invalidCoordinates);

And the output is the following:

           2 3,402823E+38 3,402823E+38 3,402823E+38 3,402823E+38

3,402823E+38          8,8 3,402823E+38        110,2 3,402823E+38

3,402823E+38 3,402823E+38          1,8 3,402823E+38 3,402823E+38

3,402823E+38         78,9 3,402823E+38          0,6 3,402823E+38

3,402823E+38 3,402823E+38 3,402823E+38 3,402823E+38          0,8

Also, I tried to use .GetAugmentedWeightHandler like in the following:

var withAugmentedWeightHandler = router.CalculateWeight(
                    Vehicle.Car.Fastest(),
                    router.GetAugmentedWeightHandler(Vehicle.Car.Fastest()),
                    resolvedPoints,
                    invalidCoordinates)
                .Select(x => x.Select(y => y.Time).ToArray())
                .ToArray();

And the output is the following:

           0 3,402823E+38 3,402823E+38 3,402823E+38 3,402823E+38

3,402823E+38            0     277,9613     103,8593 3,402823E+38

3,402823E+38 3,402823E+38            0 3,402823E+38 3,402823E+38

3,402823E+38     74,70394     264,8334            0 3,402823E+38

3,402823E+38 3,402823E+38 3,402823E+38 3,402823E+38            0

For RouterDb generation I'm using the following code:

private static RouterDb GetRouterDb(string filePath)
{
    RouterDb routerDb;
    using (var stream = new FileInfo(filePath).OpenRead())
    {
        routerDb = RouterDb.Deserialize(stream);
    }
    routerDb.AddContracted(Vehicle.Car.Fastest());
    return routerDb;
}

I attached small demo project for this.
ItineroDemo.zip

How can I reduce amount of float.MaxValue values in output matrix? What I'm doing wrong? Please assist here.

@juliusfriedman
Copy link

I think this was due to the use of the incorrect Algorithm being used it should be fixed in #302 if not let me know and provide a repo and I will triple check, I think there is 1 more place a change needs to be made but @xivk has not reviewed the PR yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants