How to increase weight of certain edges

Hi… I have some origin-destination pairs for which i need to find out the shortest paths (fastest). I need to increase the weight of the edges that were used for the shortest path of a pair and thus those specific edges will have a little increased weight for the next path calculation. I do not want to block those, just increase the weights.
e.g. i have 1000 origin-dest pairs. I stored the edges (EGE - int) used in a path calculation and a corresponding value (VAL - float) in a hashmap. So, in path calculation of the next pair, the weights of EGEs will be = weight + weight * VAL. The problem is I don’t understand how to access that hashmap and use in path calculation.

I crated a custom weighting class (MyCustomWeighting by copying “FastestWeighting”) and added:

private double dynamicEdgePenaltyFactor = 5.0 ;
public IntFloatHashMap myWeighedEdges = new IntFloatHashMap();  //contains EGE & VAL
public double calcWeight(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId) {
    double speed = reverse ? edge.getReverse(avSpeedEnc) : edge.get(avSpeedEnc);
    if (speed == 0)
        return Double.POSITIVE_INFINITY;

    double time = edge.getDistance() / speed * SPEED_CONV;

    // add direction penalties at start/stop/via points
    boolean unfavoredEdge = edge.get(EdgeIteratorState.UNFAVORED_EDGE);
    if (unfavoredEdge)
        time += headingPenalty;

    **// get the VAL of the edge**
    if (myWeighedEdges.containsKey(edge.getEdge()))
       time=  time + time * dynamicEdgePenaltyFactor * myWeighedEdges.get(edge.getEdge()); 

    return time ;

I also added the following to GraphHopper class

public Weighting createWeighting(HintsMap hintsMap, FlagEncoder encoder, Graph graph) {

else if ("MyCustomWeight ".equalsIgnoreCase(weightingStr)) {
weighting = new MyCustomWeighting (encoder, hintsMap);

My q is: if in the main class I create a hashmap (myWeighedEdges) to store the EGE and VALs, how to connect that to the myWeighedEdges in MyCustomWeighting class?

GHResponse rsp = new GHResponse();
IntFloatHashMap myWeighedEdges = new IntFloatHashMap();

List paths = graphHopper.calcPaths (new GHReques t(or-lat, or-lng, des-lat, des-lng).setWeighting("MyCustomWeight ").setVehicle(“car”), rsp)

Is there any other better way to do it? please note that, I am still using the previous version of graphhopper because I am getting errors with SDK while trying to use the new one.

Thanks in advance

Powered by Discourse