Hi,
I have a custom weighting and I’m seeing some sub-optimal routes being generated when very small weights are used. Whilst troubleshooting this, I’ve found that the sub-optimal routes occur when all edges are assigned a custom weight of 0.03125. If I use a slightly larger weight at 0.05, the problem vanishes.
(Obviously this is a contrived scenario and in reality not all edges have the same weight. But in this case there were lots of edges near one another with the same very small weight, and that’s how I noticed this issue).
For example (on the left is the sub-optimal route, on the right is the optimal one. Only difference is the weights of 0.03125 vs 0.05):
I can reproduce this reliably using GH 4.0 and the default foot profile. I’m not using CH or LM.
A minimal example of my custom weighting that can reproduce this is as follows:
public class MyWeightingFactory implements WeightingFactory {
public Weighting createWeighting(Profile profile, PMap requestHints, boolean disableTurnCosts) {
PMap hints = new PMap();
hints.putAll(profile.getHints());
hints.putAll(requestHints);
FlagEncoder encoder = encodingManager.getEncoder(profile.getVehicle());
TurnCostProvider turnCostProvider = NO_TURN_COST_PROVIDER;
Weighting parentWeighting = new PriorityWeighting(encoder, hints, turnCostProvider);
Weighting myWeighting = new MyWeighting(parentWeighting);
return myWeighting;
}
}
public class MyWeighting extends AbstractAdjustedWeighting {
public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse) {
double superWeight = super.calcEdgeWeight(edgeState, reverse);
// This triggers the issue
return superWeight * 0.03125;
// But this does not
//return superWeight * 0.05;
}
}
Any ideas? Thanks!
Update: I’ve found that the issue occurs with AStarBi, but not with DijkstraBi.