For the moment, I have created a class implementing the Weighting interface:
import java.util.HashMap;
import org.joda.time.DateTime;
import com.graphhopper.GraphHopper;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.routing.util.HintsMap;
import com.graphhopper.routing.util.Weighting;
import com.graphhopper.util.EdgeIteratorState;
public class HourlyWeighting implements Weighting{
private HashMap<Integer, double[]> hourlySpeeds = new HashMap<Integer, double[]>();
private GraphHopper hopper;
private String name = "HourlyWeighting";
private double maxVelocity = 130.0;
public HourlyWeighting(GraphHopper hopper) {
this.hopper = hopper;
for (int i=0; i <= 23; i++) {
hourlySpeeds.put(i, new double[hopper.getGraphHopperStorage().getAllEdges().getMaxId()]);
}
//A method to populate the arrays from a csv data goes here
}
public double getMinWeight(double distance) {
return distance/maxVelocity;
}
public double calcWeight(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) {
DateTime dt = new DateTime();
return hourlySpeeds.get(dt.getHourOfDay())[edgeState.getEdge()];
}
public FlagEncoder getFlagEncoder() {
return hopper.getEncodingManager().fetchEdgeEncoders().get(0);
}
public String getName() {
return name;
}
public boolean matches(HintsMap map) {
String weighting = map.getWeighting();
String vehicle = map.getVehicle();
return (name.equals(weighting) && ????.equals(vehicle));
}
}
Now, what I don’t see is how to set this new HourlyWeighting weighting to my graph. Any help on this please?
Thanks,
José