Skip to content

Commit c03cedf

Browse files
committed
Remove GHRequest#hasXYZ and various clean-ups
1 parent 9eb6558 commit c03cedf

File tree

20 files changed

+100
-136
lines changed

20 files changed

+100
-136
lines changed

api/src/main/java/com/graphhopper/GHRequest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ public List<String> getPointHints() {
217217
return pointHints;
218218
}
219219

220-
public boolean hasPointHints() {
221-
return pointHints.size() == points.size() && !points.isEmpty();
222-
}
223-
224220
public GHRequest setCurbsides(List<String> curbsides) {
225221
this.curbsides = curbsides;
226222
return this;
@@ -230,19 +226,11 @@ public List<String> getCurbsides() {
230226
return curbsides;
231227
}
232228

233-
public boolean hasCurbsides() {
234-
return curbsides.size() == points.size() && !points.isEmpty();
235-
}
236-
237229
public GHRequest setSnapPreventions(List<String> snapPreventions) {
238230
this.snapPreventions = snapPreventions;
239231
return this;
240232
}
241233

242-
public boolean hasSnapPreventions() {
243-
return !snapPreventions.isEmpty();
244-
}
245-
246234
public List<String> getSnapPreventions() {
247235
return snapPreventions;
248236
}

api/src/main/java/com/graphhopper/util/Parameters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public static final class RoundTrip {
9191
* Parameters that can be passed as hints and influence routing per request.
9292
*/
9393
public static final class Routing {
94+
public static final String ALGORITHM = "algorithm";
9495
public static final String EDGE_BASED = "edge_based";
9596
public static final String TURN_COSTS = "turn_costs";
9697
public static final String U_TURN_COSTS = "u_turn_costs";

api/src/main/java/com/graphhopper/util/exceptions/PointNotFoundException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class PointNotFoundException extends IllegalArgumentException implements
3030

3131
protected final int pointIndex;
3232

33-
public PointNotFoundException(String var1, int pointIndex) {
34-
super(var1);
33+
public PointNotFoundException(String message, int pointIndex) {
34+
super(message);
3535
this.pointIndex = pointIndex;
3636
}
3737

client-hc/src/main/java/com/graphhopper/api/GHMRequest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ public List<String> getPointHints() {
120120
throw new IllegalStateException("Use getFromPointHints or getToPointHints");
121121
}
122122

123-
@Override
124-
public boolean hasPointHints() {
125-
return this.fromPointHints.size() == this.fromPoints.size() && !fromPoints.isEmpty() &&
126-
this.toPointHints.size() == this.toPoints.size() && !toPoints.isEmpty();
127-
}
128-
129123
public GHRequest addFromPointHint(String pointHint) {
130124
this.fromPointHints.add(pointHint);
131125
return this;
@@ -196,12 +190,6 @@ public List<String> getCurbsides() {
196190
throw new IllegalStateException("Use getFromCurbsides or getToCurbsides");
197191
}
198192

199-
@Override
200-
public boolean hasCurbsides() {
201-
return fromCurbsides.size() == fromPoints.size() && !fromPoints.isEmpty() &&
202-
toCurbsides.size() == toPoints.size() && !toPoints.isEmpty();
203-
}
204-
205193
/**
206194
* @param failFast if false the matrix calculation will be continued even when some points are not connected
207195
*/
@@ -215,7 +203,7 @@ public boolean getFailFast() {
215203
}
216204

217205
/**
218-
* This method makes it more likely that hasPointHints returns true as often point hints are added although the
206+
* This method clears the point hint lists if they only contain empty values. Often point hints are added although the
219207
* strings are empty. But because they could be used as placeholder we do not know earlier if they are meaningless.
220208
*/
221209
void compactPointHints() {

core/src/main/java/com/graphhopper/routing/DirectionResolverResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import static com.graphhopper.util.Parameters.Routing.CURBSIDE;
2626

2727
public class DirectionResolverResult {
28-
private static DirectionResolverResult UNRESTRICTED = new DirectionResolverResult(ANY_EDGE, ANY_EDGE, ANY_EDGE, ANY_EDGE);
29-
private static DirectionResolverResult IMPOSSIBLE = new DirectionResolverResult(NO_EDGE, NO_EDGE, NO_EDGE, NO_EDGE);
28+
private static final DirectionResolverResult UNRESTRICTED = new DirectionResolverResult(ANY_EDGE, ANY_EDGE, ANY_EDGE, ANY_EDGE);
29+
private static final DirectionResolverResult IMPOSSIBLE = new DirectionResolverResult(NO_EDGE, NO_EDGE, NO_EDGE, NO_EDGE);
3030

3131
private final int inEdgeRight;
3232
private final int outEdgeRight;

core/src/main/java/com/graphhopper/routing/Router.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,9 @@ private void checkNonChMaxWaypointDistance(List<GHPoint> points) {
302302
GHPoint lastPoint = points.get(0);
303303
GHPoint point;
304304
double dist;
305-
DistanceCalc calc = DIST_EARTH;
306305
for (int i = 1; i < points.size(); i++) {
307306
point = points.get(i);
308-
dist = calc.calcDist(lastPoint.getLat(), lastPoint.getLon(), point.getLat(), point.getLon());
307+
dist = DIST_EARTH.calcDist(lastPoint.getLat(), lastPoint.getLon(), point.getLat(), point.getLon());
309308
if (dist > routerConfig.getNonChMaxWaypointDistance()) {
310309
Map<String, Object> detailMap = new HashMap<>(2);
311310
detailMap.put("from", i - 1);

core/src/main/java/com/graphhopper/routing/RoutingAlgorithmFactorySimple.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
4444
} else if (DIJKSTRA.equalsIgnoreCase(algoStr)) {
4545
ra = new Dijkstra(g, weighting, opts.getTraversalMode());
4646

47-
} else if (ASTAR_BI.equalsIgnoreCase(algoStr) || Helper.isEmpty(opts.getAlgorithm())) {
47+
} else if (ASTAR_BI.equalsIgnoreCase(algoStr) || Helper.isEmpty(algoStr)) {
4848
AStarBidirection aStarBi = new AStarBidirection(g, weighting,
4949
opts.getTraversalMode());
5050
aStarBi.setApproximation(getApproximation(ASTAR_BI, opts, g.getNodeAccess()));

core/src/main/java/com/graphhopper/routing/lm/LMRoutingAlgorithmFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
5959
algo.setApproximation(getApproximator(g, activeLM, epsilon));
6060
algo.setMaxVisitedNodes(opts.getMaxVisitedNodes());
6161
return algo;
62-
} else if (ASTAR_BI.equalsIgnoreCase(algoStr) || Helper.isEmpty(opts.getAlgorithm())) {
62+
} else if (ASTAR_BI.equalsIgnoreCase(algoStr) || Helper.isEmpty(algoStr)) {
6363
double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStarBi.EPSILON, 1);
6464
AStarBidirection algo = new AStarBidirection(g, weighting, opts.getTraversalMode());
6565
algo.setApproximation(getApproximator(g, activeLM, epsilon));

core/src/main/java/com/graphhopper/routing/template/RoundTripRoutingTemplate.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package com.graphhopper.routing.template;
1919

20+
import com.carrotsearch.hppc.IntHashSet;
2021
import com.graphhopper.GHRequest;
2122
import com.graphhopper.GHResponse;
2223
import com.graphhopper.ResponsePath;
@@ -33,12 +34,9 @@
3334
import com.graphhopper.routing.weighting.Weighting;
3435
import com.graphhopper.storage.index.LocationIndex;
3536
import com.graphhopper.storage.index.QueryResult;
36-
import com.graphhopper.util.Helper;
37-
import com.graphhopper.util.Parameters;
37+
import com.graphhopper.util.*;
3838
import com.graphhopper.util.Parameters.Algorithms;
3939
import com.graphhopper.util.Parameters.Algorithms.RoundTrip;
40-
import com.graphhopper.util.PathMerger;
41-
import com.graphhopper.util.Translation;
4240
import com.graphhopper.util.exceptions.PointNotFoundException;
4341
import com.graphhopper.util.shapes.GHPoint;
4442

@@ -119,6 +117,8 @@ public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoF
119117

120118
long visitedNodesSum = 0L;
121119
QueryResult start = queryResults.get(0);
120+
IntHashSet previousEdges = new IntHashSet();
121+
avoidPathWeighting.setAvoidedEdges(previousEdges);
122122
for (int qrIndex = 1; qrIndex < queryResults.size(); qrIndex++) {
123123
RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, algoOpts);
124124
// instead getClosestNode (which might be a virtual one and introducing unnecessary tails of the route)
@@ -134,8 +134,10 @@ public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoF
134134

135135
pathList.add(path);
136136

137-
// it is important to avoid previously visited nodes for future paths
138-
avoidPathWeighting.addEdges(path.calcEdges());
137+
// add the edges of this path to the set of previous edges so they will be avoided from now, otherwise
138+
// we do not get a nice 'round trip'. note that for this reason we cannot use CH for round-trips currently
139+
for (EdgeIteratorState e : path.calcEdges())
140+
previousEdges.add(e.getEdge());
139141
}
140142

141143
ghResponse.getHints().putObject("visited_nodes.sum", visitedNodesSum);

core/src/main/java/com/graphhopper/routing/template/ViaRoutingTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ public List<QueryResult> lookup(List<GHPoint> points) {
7777
if (points.size() < 2)
7878
throw new IllegalArgumentException("At least 2 points have to be specified, but was:" + points.size());
7979

80-
EdgeFilter strictEdgeFilter = !ghRequest.hasSnapPreventions()
80+
EdgeFilter strictEdgeFilter = ghRequest.getSnapPreventions().isEmpty()
8181
? edgeFilter
8282
: new SnapPreventionEdgeFilter(edgeFilter, roadClassEnc, roadEnvEnc, ghRequest.getSnapPreventions());
8383
queryResults = new ArrayList<>(points.size());
8484
for (int placeIndex = 0; placeIndex < points.size(); placeIndex++) {
8585
GHPoint point = points.get(placeIndex);
8686
QueryResult qr = null;
87-
if (ghRequest.hasPointHints())
87+
if (!ghRequest.getPointHints().isEmpty())
8888
qr = locationIndex.findClosest(point.lat, point.lon, new NameSimilarityEdgeFilter(strictEdgeFilter,
8989
ghRequest.getPointHints().get(placeIndex), point, 100));
90-
else if (ghRequest.hasSnapPreventions())
90+
else if (!ghRequest.getSnapPreventions().isEmpty())
9191
qr = locationIndex.findClosest(point.lat, point.lon, strictEdgeFilter);
9292
if (qr == null || !qr.isValid())
9393
qr = locationIndex.findClosest(point.lat, point.lon, edgeFilter);

core/src/main/java/com/graphhopper/routing/weighting/AvoidEdgesWeighting.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121
import com.graphhopper.coll.GHIntHashSet;
2222
import com.graphhopper.util.EdgeIteratorState;
2323

24-
import java.util.Collection;
25-
2624
/**
27-
* Rates already used Paths worse.
25+
* Increases the weight for a certain set of edges by a given factor and thus makes them less likely to be part of
26+
* a shortest path
2827
*
2928
* @author Robin Boldt
3029
*/
3130
public class AvoidEdgesWeighting extends AbstractAdjustedWeighting {
3231
// contains the edge IDs of the already visited edges
33-
protected final IntSet visitedEdges = new GHIntHashSet();
34-
32+
protected IntSet avoidedEdges = new GHIntHashSet();
3533
private double edgePenaltyFactor = 5.0;
3634

3735
public AvoidEdgesWeighting(Weighting superWeighting) {
@@ -43,20 +41,14 @@ public AvoidEdgesWeighting setEdgePenaltyFactor(double edgePenaltyFactor) {
4341
return this;
4442
}
4543

46-
/**
47-
* This method adds the specified path to this weighting which should be penalized in the
48-
* calcWeight method.
49-
*/
50-
public void addEdges(Collection<EdgeIteratorState> edges) {
51-
for (EdgeIteratorState edge : edges) {
52-
visitedEdges.add(edge.getEdge());
53-
}
44+
public void setAvoidedEdges(IntSet avoidedEdges) {
45+
this.avoidedEdges = avoidedEdges;
5446
}
5547

5648
@Override
5749
public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse) {
5850
double weight = superWeighting.calcEdgeWeight(edgeState, reverse);
59-
if (visitedEdges.contains(edgeState.getEdge()))
51+
if (avoidedEdges.contains(edgeState.getEdge()))
6052
return weight * edgePenaltyFactor;
6153

6254
return weight;

core/src/main/java/com/graphhopper/routing/weighting/QueryGraphWeighting.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public String getName() {
109109
return weighting.getName();
110110
}
111111

112+
@Override
113+
public String toString() {
114+
return getName();
115+
}
116+
112117
private int getOriginalEdge(int edge) {
113118
return closestEdges.get((edge - firstVirtualEdgeId) / 4);
114119
}

core/src/main/java/com/graphhopper/util/FetchMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
* {@link EdgeIteratorState#fetchWayGeometry(FetchMode)}. See also docs/core/low-level-api.md
66
*/
77
public enum FetchMode {
8-
TOWER_ONLY, PILLAR_ONLY, BASE_AND_PILLAR, PILLAR_AND_ADJ, ALL;
8+
TOWER_ONLY, PILLAR_ONLY, BASE_AND_PILLAR, PILLAR_AND_ADJ, ALL
99
}

core/src/test/java/com/graphhopper/GraphHopperAPITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testLoad() {
6767
loadGraph(graph);
6868
// 3 -> 0
6969
GHResponse rsp = instance.route(new GHRequest(42, 10.4, 42, 10).setProfile(profile));
70-
assertFalse(rsp.hasErrors());
70+
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
7171
ResponsePath responsePath = rsp.getBest();
7272
assertEquals(80, responsePath.getDistance(), 1e-6);
7373

core/src/test/java/com/graphhopper/routing/DirectedBidirectionalDijkstraTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.graphhopper.routing;
22

33
import com.carrotsearch.hppc.IntArrayList;
4+
import com.carrotsearch.hppc.IntHashSet;
45
import com.graphhopper.Repeat;
56
import com.graphhopper.RepeatRule;
67
import com.graphhopper.routing.ev.DecimalEncodedValue;
@@ -22,7 +23,6 @@
2223
import org.junit.Test;
2324

2425
import java.util.Arrays;
25-
import java.util.Collections;
2626
import java.util.HashSet;
2727
import java.util.Random;
2828

@@ -455,7 +455,7 @@ public void blockArea() {
455455
private AvoidEdgesWeighting createAvoidEdgeWeighting(EdgeIteratorState edgeOut) {
456456
AvoidEdgesWeighting avoidEdgesWeighting = new AvoidEdgesWeighting(weighting);
457457
avoidEdgesWeighting.setEdgePenaltyFactor(Double.POSITIVE_INFINITY);
458-
avoidEdgesWeighting.addEdges(Collections.singletonList(edgeOut));
458+
avoidEdgesWeighting.setAvoidedEdges(IntHashSet.from(edgeOut.getEdge()));
459459
return avoidEdgesWeighting;
460460
}
461461

0 commit comments

Comments
 (0)