Is it possible to dynamically disable some of the edge on the graph after setting the osmfile of a hopper(Or maybe increase its cost to a reletively high value?)? Can it be done without using lower-level api to build a graph from scratch?
After the OSM import the graph is more or less a read-only data structure. With some (more advanced) exceptions. Do you want to disable an edge from the server-side, or enable/disable it dynamically for each routing request?
The latter one, I didn’t really use it as a server. I actually use it as a java lib. What I want to do is, get a request with filter from the client side and server side will give a response of the route without traverse those edges in the filter.
This should be possible using custom models. Maybe the easiest you can do is exclude a route based on the OSM way ID using the built-in
osm_way_id encoded value. However, this might close several edges (that share the same way ID). To close a single edge based on the edge ID you might have to modify the Java code in WeightingFactory where you could set the weight for the corresponding edge to infinity. Note that such dynamic changes don’t work with CH.
I found 2 methods in GraphHopper, they are getBaseGraph and set setBaseGraph. Can I use them to changing the distance or cost of a graph. Is it possible to set the distance of some of the edges by creating a temporary hopper and using those previous methods for each request with a filter?
To change the cost of an edge you should rather modify the weighting. In principle you can also change the cost of an edge by modifying the distance (which is stored in the graph), something like