Skip to content

Distance matrix ( Origin / Destination ) #131

Closed

Description

@matsjg

It would be nice to use Graphhopper to calulate a distance matrix (or Origin / Destination) matrix from a list of nodes.
This is useful for route optimization.

Either by repetitive use of one-to-all shortest path algorithms like Dijkstra's or maybe use an all-to-all shortest path algorithms such as the Floyd-Warshall algorithm.

Activity

  1. PhilHa commented on Dec 11, 2013

    @PhilHa

    Do you really intend to calculate an all-to-all shortest path or just a distance matrix from some selected nodes?

  2. matsjg commented on Dec 11, 2013

    @matsjg
    Author

    Ah, I should have been more explicit.
    The latter, send in a list of nodes and get a matrix with distances (all to all) between the selected nodes.

    /M

    11 dec 2013 kl. 17:21 skrev PhilHa [email protected]:

    Do you really intend to calculate an all-to-all shortest path or just a distance matrix from some selected nodes?

    Von: Mats Norén [mailto:[email protected]]
    Gesendet: Mittwoch, 11. Dezember 2013 15:34
    An: graphhopper/graphhopper
    Betreff: [graphhopper] Distance matrix ( Origin / Destination ) (#131)

    It would be nice to use Graphhopper to calulate a distance matrix (or Origin / Destination) matrix from a list of nodes.
    This is useful for route optimization.

    Either by repetitive use of one-to-all shortest path algorithms like Dijkstra's or maybe use an all-to-all shortest path algorithms such as the Floyd-Warshall algorithm.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/131.
    —
    Reply to this email directly or view it on GitHub.

  3. PhilHa commented on Dec 11, 2013

    @PhilHa

    so you can use the DijkstraOneToMany-Algorithm (which is already in use for precalculating for contraction hierarchies) to calculate a row.

    Floyd-Warshall is an all-to-all-algorithm, so its actually routing from EVERY node of the graph to every other node. besides its complexity (O(N^3)) is higher than n one-to-many dijsktra's (or even N one-to-all dijkstra's)

  4. karussell commented on Oct 27, 2014

    @karussell
    Member

    You can always run two for loops like here

    The optimized code for these matrix calculation can be hundred times faster and even more. After long internal pro and contra discussions we have decided to keep this code closed source. This Matrix add-on is used in our API, see documentation here.

  5. matsjg commented on Oct 27, 2014

    @matsjg
    Author

    Hi,
    I understand that it may be business reasons for not opening up the code
    for an optimized NxM calculation.
    But since the OSRM-project already provides the same functionality in open
    code I don't really see the advantage of keeping it closed source? My fear
    is that customers using graphhopper for optimization problems will look
    elsewhere instead.

    Best regards,
    Mats

    On Mon, Oct 27, 2014 at 1:27 PM, Peter [email protected] wrote:

    You can run two for loops like here
    https://github.com/karussell/optaplanner-graphhopper-example/blob/master/src/main/java/com/graphhopper/optaplanner/Main.java#L45

    The optimized code for these matrix calculation can be 50 times faster and
    even more. After long internal pro and contra discussions we have decided
    to keep this code closed source (for now). This Matrix add-on is used in
    our API, see documentation here
    https://github.com/graphhopper/web-api/blob/master/docs-matrix.md.

    —
    Reply to this email directly or view it on GitHub
    #131 (comment)
    .

  6. karussell commented on Oct 27, 2014

    @karussell
    Member

    Sure, let me explain.

    We think that we provide huge value with GraphHopper itself, being fast, well tested, customizable, written in Java, well designed etc. We have no multi million VCs behind GraphHopper and so we have to take care that GraphHopper can go forward even in a year. And we are very confident to reach this goal with different strategies.

    Now if someone wants to use other systems for matrix calculations then some of them will do, and some of them will use the hosted Directions API. It is not expensive and offers fast calculations with the possibility of customized vehicles, with and without CH and is always updated to the latest version.

    And probably more importantly you can always use the two for-loops, the add-on 'only' makes usage for matrices easier and faster.

    BTW: I do NOT close this issue, things can and will change ;)
    Update 2017: see this decision regarding the Isochrone API

  7. matsjg commented on Oct 27, 2014

    @matsjg
    Author

    Hi,
    I totally understand. I have to say it is a fantastic product you've
    developed and really hope that more people out there realize it.
    I try to tell people about it when I have the chance.

    Keep up the good work!

    /M

    On Mon, Oct 27, 2014 at 1:59 PM, Peter [email protected] wrote:

    Sure, let me explain.

    We think that we provide huge value with GraphHopper itself, being fast,
    well tested, customizable, written in Java, well designed etc. We have no
    (multi million) VC behind GraphHopper and so we have to take care that
    GraphHopper can go forward even in a year. And we are very confident to
    reach this goal with different ideas, and one of them is the Matrix Add-on.

    Now if someone wants to use other systems for matrix calculations then
    some of them will do, and some of them will buy our Matrix Add-on. It is
    not expensive we think, but more importantly it does not block the usage in
    that scenarios (as you can use the two for-loops), it 'only' makes usage
    easy and even faster.

    BTW: I do NOT close this issue ;)

    —
    Reply to this email directly or view it on GitHub
    #131 (comment)
    .

  8. karussell commented on Oct 27, 2014

    @karussell
    Member

    Thanks for understanding & spreading the word :) !

  9. IsNull commented on Apr 21, 2016

    @IsNull

    I need the distance matrix feature for a mean of 100x100 (all-to-all) queries. The matrix will then be further processed by genetic algorithms for a complex delivery planning and routing problem.

    Now before I'm going to implement this in my Fork I wanted to investigate into the current situation of this matter here.

    • Wouldn't it make sense that GraphHopper provides a (non-optimised) default implementation of the Matrix API? (For the sake of a common API...)
    • Since you already have implemented an optimised version of this and holding it back for a reason, what would happen if I send you a pull-request with matrix functionality? 😄

    This leads to an interesting situation for an (semi) open source project - how to deal with contributions which partially cover closed source features which where intended to be paid for?

    That being said, I can somehow understand that you want to keep portions back of your code. On the other hand, this will always lead to such problems, especially if your community grows. Thank you for providing GraphHopper Open Source anyway 👍

  10. karussell commented on Apr 21, 2016

    @karussell
    Member

    Wouldn't it make sense that GraphHopper provides a (non-optimised) default
    implementation of the Matrix API? (For the sake of a common API...)

    That is a good idea, yes.

    Since you already have implemented an optimised version of this and holding it back for a reason

    We do not 'holding it back' - you can easily buy it :) !

    what would happen if I send you a pull-request with matrix functionality? 😄

    That is a very good question and for the last >2 years there was no need to answer this ;)

    We will of course not reject it and integrate it if our standards like CLA and unit&integration tests are in place. Commercially it could temporarily make sense to reject this, but our aim is to push our open source projects with the help of our business/company and not the other way around (easier said than done!). Furthermore the 'danger' of a fork would then be higher and we really want to avoid this mess for the sake of our community & quality etc.

    That being said, I can somehow understand that you want to keep portions back of your code. On the other hand, this will always lead to such problems, especially if your community grows.

    We do not see this as a real problem. In fact we will have to think about closed vs. open features from time to time but our business model is not founded on closed source although it makes it a bit easier at the start with some closed source features. BTW: see here for a current comparison.

    Thank you for providing GraphHopper Open Source anyway 👍

    Thanks for this kind words!

  11. IsNull commented on Apr 21, 2016

    @IsNull

    Ok that sounds great.

    I give it a try an implement a matrix method in the lines of

    class GraphHopper 
    {
    
        [...]
    
        public GHMatrixResponse matrix(GHMatrixRequest request) { ... }
    }

    I will make it extensible so its possible to create your own MatrixAlgorithm provider. In the beginning there will be a simplistic two-for loop implementation and after that the one-to-many Dijkstra.

    Depending on the performance of the latter, I will either go with the one-to-many Dijkstra or dive deeper to use a more optimised algorithm which actually can reuse data-structures for the whole matrix calculation.

  12. karussell commented on Apr 21, 2016

    @karussell
    Member

    I would prefer this to be in a separate class like MatrixModule and pass the GraphHopper class in the constructor. As currently the GraphHopper class is really big and needs some separation :)

    Or another way would be to have it the way you described and try to separate all the functionality into MatrixAlgorithm or something to reduce the LOC in GraphHopper.java :)

  13. IsNull commented on Apr 21, 2016

    @IsNull

    The way I see it GraphHopper acts as a Facade and should give simple access to all parts.

    As currently the GraphHopper class is really big and needs some separation

    Thats what I just thought as well. There are a lot of things in this class which could be refactored out. Specifically, I'd say it would make sense to separate the construction of a GraphHopper into a GraphHopperFactory. This would remove a lot of boilerplate, all the argument parsing etc. As a side effect, it would also remove the OSM dependencies and make it truly generic.

    Also, Storage handling and routing (calcPath) could be moved in separate classes.

    GraphHopper would then just compose the separated modules and provide a easy to use API for users as it does now.

    So yes, the last thing I'll do is going to bloat GraphHopper class, it will probably get this matrix method just delegate it to a MatrixAlgorithm. All the matrix stuff will land in a separate package anyway.

  14. karussell commented on Apr 21, 2016

    @karussell
    Member

    Perfect & I 100% agree!

    Also, Storage handling and routing (calcPath) could be moved in separate classes.

    Yes, this will happen in #450

  15. IsNull commented on Apr 21, 2016

    @IsNull

    See Pull-Request (WIP) #705

  16. FeNoMeNa commented on Jan 6, 2020

    @FeNoMeNa

    Any progress? :)

  17. deleted a comment from vitalif on Jan 6, 2020
  18. mehrdad3301 commented on Oct 15, 2026

    @mehrdad3301

    @karussell I would be happy to pick this up. Given that forks already include this, like RPHAST in openrouteservice, it doesn't make sense not to have a matrix API for graphhopper. If you agree, I would like to implement RPHAST or a minimal matrix API as suggested in this issue. What do you think ?

  19. karussell commented on Oct 19, 2026

    @karussell
    Member

    Over the years we have learned a lot and have decided to not open source the Matrix component for now and also not include a worse and slower or "minimal" Matrix alternative as once suggested.

    Just for clarity: GraphHopper's A-to-B routing functionality is and will remain 100% open and we will further invest into it. Including GraphHopper Maps and our support for photon and OpenStreetMap.

    btw: @mehrdad3301 if your employer uses GraphHopper please do us a favour and ask them if we can include them at https://www.graphhopper.com/open-source/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions