Avoid Junctions by setting higher weight

I’m trying to have a route where I want to avoid the junctions if there are other routes possible, one possibility is for me to set higher weight to these edges which are part of a junction. Is there any way already which helps me to achieve this or do I need to keep track of the edges in a HashMap or something like that?

You could count the edges of every junction node and change the priority of the associated edges.

For the priority per edge, see the BikeFlagEncoder. For the edge counting you would need to do this after the data import and could hook into the GraphHopper.postProcessing() method and GHUtility.getProblems shows you a way how to loop through all junction nodes and then loop through their edges.

Why do you prefer adding this into postprocessing method rather than applyweight method?

I’m not sure how would I determine junction edges from the below code:

int nodes = g.getNodes();
	int nodeIndex = 0;
	NodeAccess na = g.getNodeAccess();
	try {
		EdgeExplorer explorer = g.createEdgeExplorer();
		for (; nodeIndex < nodes; nodeIndex++) {
			EdgeIterator iter = explorer.setBaseNode(nodeIndex);
			while (iter.next()) {
	} catch (Exception ex) {
		throw new RuntimeException("problem with node " + nodeIndex, ex);

Could you throw some light on how do I actually determine the junctions?

See some of the docs: https://github.com/graphhopper/graphhopper/blob/master/docs/core/low-level-api.md#what-are-pillar-and-tower-nodes

Got it. It was only sad that I didn’t read the docs earlier. So immature on my part. Thank you for that!

No problem :slight_smile: If the docs are incomplete or improvable let us know - or even better: provider a PR