Comments (10)
We could add this to GraphUtility.
Two questions:
- why do you need it :)? I mean, the nodes should be simply 0-maxNode, also when importing possible unused small networks are removed from the node set.
- again, as the nodes should be nearly incident you should use a BitSet (more memory efficient) and to avoid implementation deps use the MyBitSet interface with the MyBitSetImpl.
from graphhopper.
- I construct my graph using the
edge
method. A bi-product of edge creation is node creation, and the nodes are created according to their ids passed toedge
. Nothing requires the node ids to be labeled in sequential order, so (as far as I understand) we can't use a simplefor
loop to cycle through the nodes -- at a certain indexi
, nodei
might not exist. - Thanks for the tip! I'll look into this.
from graphhopper.
I don't understand 1.
In graphhopper it is - per definition - that node ids are in sequential order. Of course you can create holes via setNode or edge method but I don't understand your use case why you need to do that.
Why is it sequential? Because:
- to avoid hash lookups and use direct 'pointer' lookup in GraphStorage itself but in a lot other datastructures for the graph. Indeed this definition is the key to make GraphHopper faster and more mem efficient
- to make use of efficient boolean storage like BitSet (again instead of a more expensive map ala Map<Integer, Boolean>)
from graphhopper.
This is not indispensable; I think we can close the issue.
However, just to be clear, let me explain by an example. If I add edges
graph.edge(2, 5, 1, false);
graph.edge(3, 2, 1, false);
graph.edge(3, 7, 1, false);
graph.edge(7, 2, 1, false);
then I have indirectly created the nodes 2, 3, 5, 7.
Say, for example, that I implement my own version of Dijkstra's algorithm for use in calculating betweenness centrality (where I need to calculate the number and length of all possible shortest paths).
At the end of the calculation I want to print, for each node, the number of shortest paths their length to every other node. This looks something like the following:
protected void printSPInfo(
int startNode) {
System.out.println(" d SP pred");
TIntIterator it = nodeSet.iterator();
while (it.hasNext()) {
int node = it.next();
final NodeBetweennessInfo nodeNBInfo = nodeBetweenness.get(node);
System.out.print("(" + startNode + "," + node + ") ");
System.out.format("%-12f%-3d%-12s",
nodeNBInfo.getDistance(),
nodeNBInfo.getSPCount(),
nodeNBInfo.getPredecessors().toString());
System.out.println("");
}
}
If I have the nodeSet()
method, then it is easy to go through all the nodes using an iterator and print out the appropriate information. However, without this method, I don't see an easy way to go through all the nodes.
A possible (and simple) solution would be to add a method
int node(int index);
to Graph
which returns the node id (passed to edge
as at the start of this post) at the given index, assuming that the indices go from 0
to graph.nodes() - 1
.
from graphhopper.
Probably still some missunderstanding on your or my side.
In graphhopper you don't have a mapping between an 'index' and the 'node'. They are synonyms.
If you do graph.edge(7, 2, 1, false) you'll indirectly increase the underlying node array to make it accepting at least 8 nodes with indices 0 to 7.
E.g. when importing data from OSM then I'm using a temporary BigLongIntMap object to map long-osm-ids to integer-graphhopper-nodes. And when an unknown osm ids comes through I'm creating a new mapping with an increased counter. Then I do not create a hole in the nodes array or similar ...
from graphhopper.
I confirm, still some misunderstanding on my side.
I'm looking at your diagram in section "2. The Graph" of your wiki's Developers page.
Could you show me how you would write a method
void printNodes(Graph graph);
such that if the graph in your example were passed to this method, the output would be
0
1
2
3
5
7
?
from graphhopper.
Oh, is this misunderstanding coming from my illustration? oh no :( -> I'll improve that
The nodes 4 and 6 just do not have edges but it does not mean that they are invalid. They could e.g. have associated node properties like lat+lon etc. For your method you could then just check if a node has an edge:
for(int i = 0; i < graph.nodes(); i++) {
if(graph.getEdges(i).next())
println(i);
}
from graphhopper.
Ah okay, I think I understand better now.
What this means is that if we wanted to create a (theoretical) graph consisting of only the edges in your illustration and only nodes that have edges, this is technically not possible. I.e., the nodes 4 and 6 exist even though we have not added them to the graph. I don't think this will pose a problem for me now that I understand the test if(graph.getEdges(i).next()
.
However, this also means that if we create a graph and execute, for example, the single instruction
graph.edge(0, 999999999, 1, false);
then the graph will contain 1 billion nodes (and one edge), even though we have only indirectly added two nodes (connected by the single edge).
from graphhopper.
Yes, this is one 'disadvantage' of this design. Which is ok as we get a fast+memory efficient storage if we follow some simple rules.
from graphhopper.
Ok, thanks for your replies and insight!
from graphhopper.
Related Issues (20)
- Pedestrian street with vehicles allowed not routable by car profile HOT 20
- Setting a EncodedValueFactory fails if the EnumEncodedValue class is not within `com.graphhopper.routing.ev` package
- Could not create weighting for profile: 'truck' HOT 1
- CarAverageSpeedParser should use estimated max speed HOT 1
- Implementing railway route planning based on version 7.0 HOT 2
- 8.0 Set a No-Go Zone HOT 1
- Incorrect handling of turn restrictions sharing the same via-way HOT 18
- Motorcycle profile speed section is ignored HOT 10
- Problem when using speed limit estimation and turn restrictions
- incorrect leg_distance entries if two stops are identical
- foot with turn restrictions leads to NPE for CH preparation
- Refactoring: Introduce a FSM for OSM file parsing
- new capacity has to be strictly positive with custom encoder for "piste" ways HOT 4
- Custom vehicle doesn't work after update to 8.0 HOT 5
- Wrong exit number in a roundabout if a waypoint is inside HOT 3
- Add crossing encoded values for accessible pedestrian routing. HOT 2
- Failed Import - SRTM elevation - There was an issue looking up the coordinates for - Could not parse OSM file HOT 2
- Sorting the graph is currently not supported in the presence of turn costs HOT 1
- total distance seems incorrect for alternative route HOT 1
- max_slope should be able to get negative HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphhopper.