Skip to content

creating graph for android #9

Closed

Description

@martinschaller

I used the OSMReader (osmreader.graph=sg-sh osmreader.osm=malaysia_singapore_brunei.osm osmreader.size=5000000 osmreader.dataaccess=mmap) to create a graph for android.
But if I want to use this graph with GraphHopper I'm getting following error:
"D/RouteCalculation(2119): An error happend while creating graph: Cannot load the graph - it wasn't create via com.graphhopper.storage.LevelGraphStorage! sdcard/graphhopper/singapore-gh/"

Activity

  1. karussell commented on Jan 11, 2013

    @karussell
    Member

    This is not an android issue. A levelgraph is used on android to make everything faster via Contraction Hierarchies

    So, either specify
    osmreader.levelgraph=true
    osmreader.chShortcuts=true
    when creating the graph. Or use the normal GraphStorage on android (a bit slower but more powerful).

  2. martinschaller commented on Jan 11, 2013

    @martinschaller
    Author

    Thanks for the fast reply.
    I managed it to calculate routes on an Android device. But I still have one issue. The route distance is around 30x bigger than the real route length if getting it with the distance() function of GHResponse. Do you have an explanation for this? I took the same request as in the Android example.

    By the way: I looked long time for an appropriate routing algorithm for android and this is the first one I really like! Thx!

    Martin

    Von: Peter <[email protected]mailto:[email protected]>
    Antworten an: graphhopper/graphhopper <[email protected]mailto:[email protected]>
    Datum: Freitag, 11. Januar 2013 15:26
    An: graphhopper/graphhopper <[email protected]mailto:[email protected]>
    Cc: Martin Schaller <[email protected]mailto:[email protected]>
    Betreff: Re: [graphhopper] creating graph for android (#9)

    This is not an android issue. A levelgraph is used on android to make everything faster via Contraction Hierarchies

    So, either specify
    osmreader.levelgraph=true
    osmreader.chShortcuts=true
    when creating the graph. Or use the normal GraphStorage on android (a bit slower but more powerful).

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-12134276.

  3. karussell commented on Jan 11, 2013

    @karussell
    Member

    I managed it to calculate routes on an Android device.

    via levelgraph?

    The route distance is around 30x bigger than the real route length

    hmmh this could be a bug. I'll investigate

    By the way: I looked long time for an appropriate routing algorithm for android and this is the first one I really like!

    Thanks! Of course it is in a very early stage (and a bit slow and weak here and there) but it will improve :) !

  4. karussell commented on Jan 11, 2013

    @karussell
    Member

    If you set osmreader.sortGraph=false before creating the graph - does it fix your problem? If not, I need your code snippet to reproduce this bug.

  5. martinschaller commented on Jan 12, 2013

    @martinschaller
    Author

    Creating the graph with osmreader.sortGraph=false fixed the problem. I calculated the route via levelgraph.
    I also wanted to use the GraphHopperWeb(). But it always appends to the URL "&type=bin&minPathPrecision=1.0&algo=dijkstrabi" and it is not working with the Servlet.

  6. karussell commented on Jan 12, 2013

    @karussell
    Member

    Regarding sortGraph -> that is a known bug ;) ... regarding the web api, please make sure you append the "api" path like so:

    GraphHopperAPI gh = new GraphHopperWeb().load("http://217.92.216.224:8080/api");
    GHResponse ph = gh.route(new GHRequest(53.080827, 9.074707, 50.597186, 11.184082));
    System.out.println(ph);

    I'll document that better ...

  7. karussell commented on Jan 20, 2013

    @karussell
    Member

    I'll close this for now. Let me know if still something is broken. Regarding the sortGraph=false - I've opened #12

  8. zhiqiangZHAO commented on Jul 25, 2018

    @zhiqiangZHAO
    Contributor

    It seems the sortGraph only sort the nodes, the order of edges won't be touched. Is it right?

    I noticed the comments
    /**
    * Sorts the graph according to depth-first search traversal. Other traversals have either no
    * significant difference (bfs) for querying or are worse (z-curve).
    */
    Do we have an explanation why DFS helps?

  9. karussell commented on Jul 26, 2018

    @karussell
    Member

    It seems the sortGraph only sort the nodes, the order of edges won't be touched. Is it right?

    We recreate the entire graph, so both are sorted.

    Do we have an explanation why DFS helps?

    Not really - I would have expected BFS. Still some paper mention DFS too.

  10. zhiqiangZHAO commented on Jul 26, 2018

    @zhiqiangZHAO
    Contributor

    Thanks!
    I re-read the code. For edges, I think the order is kept. Only skip some invalid edge.
    For nodes, it's totally re-sorted.

    And this change would only improve latency for single thread query? Or it's also valid for multi-thread server scenario?

    I assume the change is make the geographical nearby data also close inside disk/memory. So there is high chance the connected edge data is already in high speed cache. Is it right?

  11. karussell commented on Jul 27, 2018

    @karussell
    Member

    I re-read the code. For edges, I think the order is kept. Only skip some invalid edge.

    No. It recreates the whole graph and it creates the new edges according to the traversal so the order changes.

    And this change would only improve latency for single thread query? Or it's also valid for multi-thread server scenario?

    Improves single thread and therefore also multi-thread accordingly

    So there is high chance the connected edge data is already in high speed cache. Is it right?

    Yes, exactly.

  12. zhiqiangZHAO commented on Jul 30, 2018

    @zhiqiangZHAO
    Contributor

    Hi Karussell,

    Sorry I am still not very clear. Below is the code I looked:
    AllEdgesIterator will iterate edge from the beginning to the end.
    looks like the below code only read all the edges then translate the nodeID to new nodeID and store the new edge in another graph. So I thought the edge order are kept except some empty entries might be skipped.

    
    static Graph createSortedGraph(Graph fromGraph, Graph toSortedGraph, final IntIndexedContainer oldToNewNodeList) {
            AllEdgesIterator eIter = fromGraph.getAllEdges();
            while (eIter.next()) {
                int base = eIter.getBaseNode();
                int newBaseIndex = oldToNewNodeList.get(base);
                int adj = eIter.getAdjNode();
                int newAdjIndex = oldToNewNodeList.get(adj);
    
                // ignore empty entries
                if (newBaseIndex < 0 || newAdjIndex < 0)
                    continue;
    
                eIter.copyPropertiesTo(toSortedGraph.edge(newBaseIndex, newAdjIndex));
            }
    
  13. zhiqiangZHAO commented on Jul 30, 2018

    @zhiqiangZHAO
    Contributor

    Hah, usually each CPU core has its own high-speed cache. So the improvement should also work for server scenario. I still feel a little strange. I think the Hilbert curve should works, too. Or even better.

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