Skip to content

Commit bea62d0

Browse files
committed
Merge branch 'master' into client_hc_vehicle_to_profile
2 parents 9bb101c + 4ce551b commit bea62d0

29 files changed

+260
-416
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Please read [our contributing guide](https://github.com/graphhopper/graphhopper/blob/master/CONTRIBUTING.md) and note that also your contribution falls under the Apache License 2.0 as outlined there.
2+
3+
Your first contribution should include a change where you add yourself to the CONTRIBUTORS.md file.

CONTRIBUTING.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,8 @@ appear on your fork its github page afterwards.
2525

2626
## License Agreement
2727

28-
For contributions like pull requests, bug fixes and translations please read
29-
the <a href="https://graphhopper.com/agreements/individual-cla.html">GraphHopper License Agreement</a>, which includes our
30-
<a href="https://graphhopper.com/agreements/cccoc.html">contributor covenant code of conduct</a>.
31-
<a href="https://graphhopper.com/#contact">Send us</a> an email with the signed print out of this CLA. Or, if you prefer
32-
the faster electronically method via signaturit.com, please send us an email with a request for this -
33-
keep in mind that this requires storing your Email there.
34-
35-
For companies that would like that their developers work for us, we need an additional [corporate CLA signed](https://graphhopper.com/agreements/corporate-cla.html).
36-
37-
Note, our CLA does not influence your rights on your contribution but it makes sure for others that you agree to the Apache License, Version 2.
38-
After this you'll appear in the <a href="CONTRIBUTORS.md">contributors list</a> and your pull request can also be discussed technically.
39-
40-
Read more in [this issue](https://github.com/graphhopper/graphhopper/pull/1129#issuecomment-375820168) why it is not that easy to make this CLA-signing process simpler for first-time contributors and maintainers.
28+
All contributions like pull requests, bug fixes, documentation changes and translations fall under the Apache License and contributors agree to our
29+
<a href="https://www.graphhopper.com/code-of-conduct/">contributor covenant code of conduct</a>.
4130

4231
## Code formatting
4332

CONTRIBUTORS.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Contributors
22

3-
Most of the contributors are mentioned at Github as [Members](https://github.com/graphhopper?tab=members) or [Contributors](https://github.com/graphhopper/graphhopper/contributors).
4-
5-
Contributors that agree to the [project its CLA](https://www.graphhopper.com/individual-contributor-license-agreement/)
6-
state this as a comment via a separate, signed commit.
3+
Most of the contributors are mentioned at Github as [Members](https://github.com/graphhopper?tab=members) or [Contributors](https://github.com/graphhopper/graphhopper/contributors).
74

85
Here is an overview:
96

config-example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ graphhopper:
123123

124124
# In many cases the road network consists of independent components without any routes going in between. In
125125
# the most simple case you can imagine an island without a bridge or ferry connection. The following parameter
126-
# allows setting a minimum size (number of nodes) for such detached components. This can be used to reduce the number
126+
# allows setting a minimum size (number of edges) for such detached components. This can be used to reduce the number
127127
# of cases where a connection between locations might not be found.
128128
prepare.min_network_size: 200
129129

core/src/main/java/com/graphhopper/GraphHopper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ private List<PrepareJob> buildSubnetworkRemovalJobs() {
11061106
TurnCostProvider turnCostProvider = new DefaultTurnCostProvider(encoder, ghStorage.getTurnCostStorage(), 0);
11071107
jobs.add(new PrepareJob(encoder.toString(), encoder.getAccessEnc(), turnCostProvider));
11081108
} else {
1109-
jobs.add(new PrepareJob(encoder.toString(), encoder.getAccessEnc(), null));
1109+
jobs.add(new PrepareJob(encoder.toString(), encoder.getAccessEnc(), TurnCostProvider.NO_TURN_COST_PROVIDER));
11101110
}
11111111
}
11121112
return jobs;

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

Lines changed: 20 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -18,91 +18,53 @@
1818
package com.graphhopper.routing;
1919

2020
import com.graphhopper.routing.util.TraversalMode;
21-
import com.graphhopper.routing.weighting.Weighting;
2221
import com.graphhopper.util.PMap;
2322
import com.graphhopper.util.Parameters;
2423

2524
/**
26-
* The algorithm options. Create an immutable object via:
27-
* <pre>
28-
* AlgorithmOptions algoOpts = AlgorithmOptions.start().
29-
* algorithm(Parameters.Algorithms.DIJKSTRA).
30-
* weighting(weighting).
31-
* build();
32-
* </pre>
33-
* <p>
34-
*
3525
* @author Peter Karich
3626
*/
3727
public class AlgorithmOptions {
38-
private final PMap hints = new PMap(5);
28+
private PMap hints = new PMap();
3929
private String algorithm = Parameters.Algorithms.DIJKSTRA_BI;
40-
private Weighting weighting;
4130
private TraversalMode traversalMode = TraversalMode.NODE_BASED;
4231
private int maxVisitedNodes = Integer.MAX_VALUE;
4332

44-
private AlgorithmOptions() {
33+
public AlgorithmOptions() {
4534
}
4635

47-
/**
48-
* Default traversal mode NODE_BASED is used.
49-
*/
50-
public AlgorithmOptions(String algorithm, Weighting weighting) {
51-
this.algorithm = algorithm;
52-
this.weighting = weighting;
36+
public AlgorithmOptions(AlgorithmOptions b) {
37+
setAlgorithm(b.getAlgorithm());
38+
setTraversalMode(b.getTraversalMode());
39+
setMaxVisitedNodes(b.getMaxVisitedNodes());
40+
setHints(b.getHints());
5341
}
5442

55-
public AlgorithmOptions(String algorithm, Weighting weighting, TraversalMode tMode) {
43+
public AlgorithmOptions setAlgorithm(String algorithm) {
5644
this.algorithm = algorithm;
57-
this.weighting = weighting;
58-
this.traversalMode = tMode;
45+
return this;
5946
}
6047

61-
/**
62-
* This method starts the building process for AlgorithmOptions.
63-
*/
64-
public static Builder start() {
65-
return new Builder();
48+
public AlgorithmOptions setTraversalMode(TraversalMode traversalMode) {
49+
this.traversalMode = traversalMode;
50+
return this;
6651
}
6752

68-
/**
69-
* This method clones the specified AlgorithmOption object with the possibility for further
70-
* changes.
71-
*/
72-
public static Builder start(AlgorithmOptions opts) {
73-
Builder b = new Builder();
74-
if (opts.algorithm != null)
75-
b.algorithm(opts.getAlgorithm());
76-
if (opts.traversalMode != null)
77-
b.traversalMode(opts.getTraversalMode());
78-
if (opts.weighting != null)
79-
b.weighting(opts.getWeighting());
80-
if (opts.maxVisitedNodes >= 0)
81-
b.maxVisitedNodes(opts.maxVisitedNodes);
82-
if (!opts.hints.isEmpty())
83-
b.hints(opts.hints);
53+
public AlgorithmOptions setMaxVisitedNodes(int maxVisitedNodes) {
54+
this.maxVisitedNodes = maxVisitedNodes;
55+
return this;
56+
}
8457

85-
return b;
58+
public AlgorithmOptions setHints(PMap pMap) {
59+
this.hints = new PMap(pMap);
60+
return this;
8661
}
8762

88-
/**
89-
* @return the traversal mode, where node-based is the default.
90-
*/
9163
public TraversalMode getTraversalMode() {
9264
return traversalMode;
9365
}
9466

95-
public boolean hasWeighting() {
96-
return weighting != null;
97-
}
98-
99-
public Weighting getWeighting() {
100-
assertNotNull(weighting, "weighting");
101-
return weighting;
102-
}
103-
10467
public String getAlgorithm() {
105-
assertNotNull(algorithm, "algorithm");
10668
return algorithm;
10769
}
10870

@@ -114,57 +76,9 @@ public PMap getHints() {
11476
return hints;
11577
}
11678

117-
private void assertNotNull(Object optionValue, String optionName) {
118-
if (optionValue == null)
119-
throw new NullPointerException("Option '" + optionName + "' must NOT be null");
120-
}
121-
12279
@Override
12380
public String toString() {
124-
return algorithm + ", " + weighting + ", " + traversalMode;
81+
return algorithm + ", " + traversalMode;
12582
}
12683

127-
public static class Builder {
128-
private AlgorithmOptions opts = new AlgorithmOptions();
129-
private boolean buildCalled;
130-
131-
public Builder traversalMode(TraversalMode traversalMode) {
132-
if (traversalMode == null)
133-
throw new IllegalArgumentException("null as traversal mode is not allowed");
134-
135-
this.opts.traversalMode = traversalMode;
136-
return this;
137-
}
138-
139-
public Builder weighting(Weighting weighting) {
140-
this.opts.weighting = weighting;
141-
return this;
142-
}
143-
144-
/**
145-
* For possible values see {@link Parameters.Algorithms}
146-
*/
147-
public Builder algorithm(String algorithm) {
148-
this.opts.algorithm = algorithm;
149-
return this;
150-
}
151-
152-
public Builder maxVisitedNodes(int maxVisitedNodes) {
153-
this.opts.maxVisitedNodes = maxVisitedNodes;
154-
return this;
155-
}
156-
157-
public Builder hints(PMap hints) {
158-
this.opts.hints.putAll(hints);
159-
return this;
160-
}
161-
162-
public AlgorithmOptions build() {
163-
if (buildCalled)
164-
throw new IllegalStateException("Cannot call AlgorithmOptions.Builder.build() twice");
165-
166-
buildCalled = true;
167-
return opts;
168-
}
169-
}
17084
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.carrotsearch.hppc.cursors.IntCursor;
2222
import com.graphhopper.routing.querygraph.QueryGraph;
23+
import com.graphhopper.routing.weighting.Weighting;
2324
import com.graphhopper.util.Parameters;
2425
import com.graphhopper.util.StopWatch;
2526

@@ -31,13 +32,15 @@
3132
public class FlexiblePathCalculator implements PathCalculator {
3233
private final QueryGraph queryGraph;
3334
private final RoutingAlgorithmFactory algoFactory;
35+
private Weighting weighting;
3436
private AlgorithmOptions algoOpts;
3537
private String debug;
3638
private int visitedNodes;
3739

38-
public FlexiblePathCalculator(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, AlgorithmOptions algoOpts) {
40+
public FlexiblePathCalculator(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, Weighting weighting, AlgorithmOptions algoOpts) {
3941
this.queryGraph = queryGraph;
4042
this.algoFactory = algoFactory;
43+
this.weighting = weighting;
4144
this.algoOpts = algoOpts;
4245
}
4346

@@ -49,7 +52,7 @@ public List<Path> calcPaths(int from, int to, EdgeRestrictions edgeRestrictions)
4952

5053
private RoutingAlgorithm createAlgo() {
5154
StopWatch sw = new StopWatch().start();
52-
RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, algoOpts);
55+
RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, weighting, algoOpts);
5356
debug = ", algoInit:" + (sw.stop().getNanos() / 1000) + " μs";
5457
return algo;
5558
}
@@ -97,11 +100,11 @@ public int getVisitedNodes() {
97100
return visitedNodes;
98101
}
99102

100-
public AlgorithmOptions getAlgoOpts() {
101-
return algoOpts;
103+
public Weighting getWeighting() {
104+
return weighting;
102105
}
103106

104-
public void setAlgoOpts(AlgorithmOptions algoOpts) {
105-
this.algoOpts = algoOpts;
107+
public void setWeighting(Weighting weighting) {
108+
this.weighting = weighting;
106109
}
107110
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,10 @@ private static class RoundTripCalculator {
152152
RoundTripCalculator(FlexiblePathCalculator pathCalculator) {
153153
this.pathCalculator = pathCalculator;
154154
// we make the path calculator use our avoid edges weighting
155-
AvoidEdgesWeighting avoidPreviousPathsWeighting = new AvoidEdgesWeighting(pathCalculator.getAlgoOpts().getWeighting())
155+
AvoidEdgesWeighting avoidPreviousPathsWeighting = new AvoidEdgesWeighting(pathCalculator.getWeighting())
156156
.setEdgePenaltyFactor(5);
157157
avoidPreviousPathsWeighting.setAvoidedEdges(previousEdges);
158-
AlgorithmOptions algoOpts = AlgorithmOptions.start(pathCalculator.getAlgoOpts()).
159-
weighting(avoidPreviousPathsWeighting).build();
160-
pathCalculator.setAlgoOpts(algoOpts);
158+
pathCalculator.setWeighting(avoidPreviousPathsWeighting);
161159
}
162160

163161
Path calcPath(int from, int to) {

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,11 @@ public GHResponse route(GHRequest request) {
121121
PMap requestHints = new PMap(request.getHints());
122122
requestHints.putObject(CustomModel.KEY, request.getCustomModel());
123123
Weighting weighting = createWeighting(profile, requestHints, request.getPoints(), disableCH);
124-
AlgorithmOptions algoOpts = AlgorithmOptions.start().
125-
algorithm(request.getAlgorithm()).
126-
traversalMode(traversalMode).
127-
weighting(weighting).
128-
maxVisitedNodes(maxVisitedNodesForRequest).
129-
hints(request.getHints()).
130-
build();
124+
AlgorithmOptions algoOpts = new AlgorithmOptions().
125+
setAlgorithm(request.getAlgorithm()).
126+
setTraversalMode(traversalMode).
127+
setMaxVisitedNodes(maxVisitedNodesForRequest).
128+
setHints(request.getHints());
131129

132130
if (ROUND_TRIP.equalsIgnoreCase(request.getAlgorithm())) {
133131
return routeRoundTrip(request, algoOpts, weighting, profile, disableLM);
@@ -158,13 +156,10 @@ protected GHResponse routeRoundTrip(GHRequest request, AlgorithmOptions algoOpts
158156
ghRsp.addDebugInfo("idLookup:" + sw.stop().getSeconds() + "s");
159157

160158
// use A* for round trips
161-
AlgorithmOptions roundTripAlgoOpts = AlgorithmOptions
162-
.start(algoOpts)
163-
.algorithm(Parameters.Algorithms.ASTAR_BI)
164-
.build();
159+
AlgorithmOptions roundTripAlgoOpts = new AlgorithmOptions(algoOpts).setAlgorithm(Parameters.Algorithms.ASTAR_BI);
165160
roundTripAlgoOpts.getHints().putObject(Parameters.Algorithms.AStarBi.EPSILON, 2);
166161
QueryGraph queryGraph = QueryGraph.create(ghStorage, qResults);
167-
FlexiblePathCalculator pathCalculator = createFlexiblePathCalculator(queryGraph, profile, roundTripAlgoOpts, disableLM);
162+
FlexiblePathCalculator pathCalculator = createFlexiblePathCalculator(queryGraph, profile, weighting, roundTripAlgoOpts, disableLM);
168163

169164
RoundTripRouting.Result result = RoundTripRouting.calcPaths(qResults, pathCalculator);
170165
// we merge the different legs of the roundtrip into one response path
@@ -183,7 +178,7 @@ protected GHResponse routeAlt(GHRequest request, AlgorithmOptions algoOpts, Weig
183178
List<Snap> qResults = ViaRouting.lookup(encodingManager, request.getPoints(), weighting, locationIndex, request.getSnapPreventions(), request.getPointHints());
184179
ghRsp.addDebugInfo("idLookup:" + sw.stop().getSeconds() + "s");
185180
QueryGraph queryGraph = QueryGraph.create(ghStorage, qResults);
186-
PathCalculator pathCalculator = createPathCalculator(queryGraph, profile, algoOpts, disableCH, disableLM);
181+
PathCalculator pathCalculator = createPathCalculator(queryGraph, profile, weighting, algoOpts, disableCH, disableLM);
187182

188183
if (passThrough)
189184
throw new IllegalArgumentException("Alternative paths and " + PASS_THROUGH + " at the same time is currently not supported");
@@ -214,7 +209,7 @@ protected GHResponse routeVia(GHRequest request, AlgorithmOptions algoOpts, Weig
214209
// (base) query graph used to resolve headings, curbsides etc. this is not necessarily the same thing as
215210
// the (possibly implementation specific) query graph used by PathCalculator
216211
QueryGraph queryGraph = QueryGraph.create(ghStorage, qResults);
217-
PathCalculator pathCalculator = createPathCalculator(queryGraph, profile, algoOpts, disableCH, disableLM);
212+
PathCalculator pathCalculator = createPathCalculator(queryGraph, profile, weighting, algoOpts, disableCH, disableLM);
218213
ViaRouting.Result result = ViaRouting.calcPaths(request.getPoints(), queryGraph, qResults, weighting, pathCalculator, request.getCurbsides(), forceCurbsides, request.getHeadings(), passThrough);
219214

220215
if (request.getPoints().size() != result.paths.size() + 1)
@@ -249,22 +244,22 @@ private Weighting createWeighting(Profile profile, PMap requestHints, List<GHPoi
249244
}
250245
}
251246

252-
private PathCalculator createPathCalculator(QueryGraph queryGraph, Profile profile, AlgorithmOptions algoOpts, boolean disableCH, boolean disableLM) {
247+
private PathCalculator createPathCalculator(QueryGraph queryGraph, Profile profile, Weighting weighting, AlgorithmOptions algoOpts, boolean disableCH, boolean disableLM) {
253248
if (chEnabled && !disableCH) {
254249
PMap opts = new PMap(algoOpts.getHints());
255250
opts.putObject(ALGORITHM, algoOpts.getAlgorithm());
256251
opts.putObject(MAX_VISITED_NODES, algoOpts.getMaxVisitedNodes());
257252
return createCHPathCalculator(queryGraph, profile, opts);
258253
} else {
259-
return createFlexiblePathCalculator(queryGraph, profile, algoOpts, disableLM);
254+
return createFlexiblePathCalculator(queryGraph, profile, weighting, algoOpts, disableLM);
260255
}
261256
}
262257

263258
private PathCalculator createCHPathCalculator(QueryGraph queryGraph, Profile profile, PMap opts) {
264259
return new CHPathCalculator(new CHRoutingAlgorithmFactory(getRoutingCHGraph(profile.getName()), queryGraph), opts);
265260
}
266261

267-
private FlexiblePathCalculator createFlexiblePathCalculator(QueryGraph queryGraph, Profile profile, AlgorithmOptions algoOpts, boolean disableLM) {
262+
private FlexiblePathCalculator createFlexiblePathCalculator(QueryGraph queryGraph, Profile profile, Weighting weighting, AlgorithmOptions algoOpts, boolean disableLM) {
268263
RoutingAlgorithmFactory algorithmFactory;
269264
// for now do not allow mixing CH&LM #1082,#1889
270265
if (lmEnabled && !disableLM) {
@@ -277,7 +272,7 @@ private FlexiblePathCalculator createFlexiblePathCalculator(QueryGraph queryGrap
277272
} else {
278273
algorithmFactory = new RoutingAlgorithmFactorySimple();
279274
}
280-
return new FlexiblePathCalculator(queryGraph, algorithmFactory, algoOpts);
275+
return new FlexiblePathCalculator(queryGraph, algorithmFactory, weighting, algoOpts);
281276
}
282277

283278
private RoutingCHGraph getRoutingCHGraph(String profileName) {

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

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

20+
import com.graphhopper.routing.weighting.Weighting;
2021
import com.graphhopper.storage.Graph;
2122

2223
/**
@@ -28,5 +29,5 @@ public interface RoutingAlgorithmFactory {
2829
/**
2930
* This method creates an algorithm out of this factory based on the specified opts and graph.
3031
*/
31-
RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts);
32+
RoutingAlgorithm createAlgo(Graph g, Weighting w, AlgorithmOptions opts);
3233
}

0 commit comments

Comments
 (0)