-
Notifications
You must be signed in to change notification settings - Fork 376
/
ORSFastestWeighting.java
54 lines (43 loc) 路 2.22 KB
/
ORSFastestWeighting.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* This file is part of Openrouteservice.
*
* Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, see <https://www.gnu.org/licenses/>.
*/
package org.heigit.ors.routing.graphhopper.extensions.weighting;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.routing.weighting.FastestWeighting;
import com.graphhopper.routing.weighting.TurnCostProvider;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.PMap;
import com.graphhopper.util.Parameters;
/**
* Modified `FastestWeighting` which has the penalty for edges with access destination or private removed.
*/
public class ORSFastestWeighting extends FastestWeighting {
private final double headingPenalty;
public ORSFastestWeighting(FlagEncoder encoder) {
this(encoder, new PMap(0), TurnCostProvider.NO_TURN_COST_PROVIDER);
}
public ORSFastestWeighting(FlagEncoder encoder, PMap map, TurnCostProvider turnCostProvider) {
super(encoder, map, turnCostProvider);
headingPenalty = map.getDouble(Parameters.Routing.HEADING_PENALTY, Parameters.Routing.DEFAULT_HEADING_PENALTY);
}
@Override
public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse, long edgeEnterTime) {
double speed = speedCalculator.getSpeed(edgeState, reverse, edgeEnterTime);
if (speed == 0)
return Double.POSITIVE_INFINITY;
double time = edgeState.getDistance() / speed * SPEED_CONV;
// add direction penalties at start/stop/via points
boolean unfavoredEdge = edgeState.get(EdgeIteratorState.UNFAVORED_EDGE);
if (unfavoredEdge)
time += headingPenalty;
return time;
}
}