问题
We are thinking to use it in our project where we need to do a route planner. The first problem we had is that we have very dyanimc variables representing our weight values; this means that we can't use the Contraction Hierarchy algorithm becouse every time one of these variables changes we should re-create the "contracted" graph, so we were thinking to configure graphhopper in order to not use the CH algorithm
In this scenario is it possible to modify graphhopper code to support this dynamic edges weight values? For example let's suppose that we have node A and node B and an edge A--B; let's suppose that this edge has a value 3 In our scenario there can be an event that can modify the value of the edge A--B from 3 to 6 or from 3 to 2 Can we modify the code in order to support this feature? Is this dependant to the DataAccess implementation?
回答1:
To modify the speed or distance of an edge you need to get an EdgeIteratorState (e.g. from a coordinate) and then set the flags or distance. Here is a code snippet:
// find edge for lat,lon point
QueryResult qr = locationIndex.findClosest(lat, lon, EdgeFilter.ALL_EDGES);
if(!qr.isValid())
throw RuntimeException("Cannot find nearby location " + lat+","+lon);
EdgeIteratorState edge = qr.getClosestEdge();
// use existing flags to reuse access information
long existingFlags = edge.getFlags();
// set speed
edge.setFlags(carFlagEncoder.setSpeed(existingFlags, newSpeed));
// set distance
edge.setDistance(newDistance);
来源:https://stackoverflow.com/questions/21132484/does-graphhopper-support-dynamic-edge-weights