/
CHLevelEdgeFilter.java
71 lines (60 loc) 路 2.51 KB
/
CHLevelEdgeFilter.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* 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.edgefilters.ch;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.storage.CHEdgeFilter;
import com.graphhopper.storage.RoutingCHEdgeIteratorState;
import com.graphhopper.storage.RoutingCHGraph;
import org.heigit.ors.routing.graphhopper.extensions.util.GraphUtils;
public abstract class CHLevelEdgeFilter implements CHEdgeFilter {
protected final FlagEncoder encoder;
protected final RoutingCHGraph graph;
protected final int maxNodes;
protected int highestNode = -1;
protected int highestNodeLevel = -1;
protected int baseNode;
protected int baseNodeLevel = -1;
protected CHLevelEdgeFilter(RoutingCHGraph g, FlagEncoder encoder) {
graph = g;
maxNodes = GraphUtils.getBaseGraph(g).getNodes();
this.encoder = encoder;
}
@Override
public boolean accept(RoutingCHEdgeIteratorState edgeIterState) {
return false;
}
public int getHighestNode() {
return highestNode;
}
public void setBaseNode(int nodeId) {
baseNode = nodeId;
if (nodeId < maxNodes)
baseNodeLevel = graph.getLevel(nodeId);
}
public void updateHighestNode(int node) {
if (node < maxNodes) {
if (highestNode == -1 || highestNodeLevel < graph.getLevel(node)) {
highestNode = node;
highestNodeLevel = graph.getLevel(highestNode);
}
} else {
if (highestNode == -1)
highestNode = node;
}
}
protected boolean isAccessible(RoutingCHEdgeIteratorState edgeIterState, boolean reverse) {
return edgeIterState.getWeight(reverse) != Double.POSITIVE_INFINITY;
}
public boolean isHighestNodeFound() {
return this.getHighestNode() != -1;
}
}