Skip to content

Commit 0e8c29e

Browse files
committed
2 parents b7ead91 + 14bd13a commit 0e8c29e

15 files changed

Lines changed: 249 additions & 515 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 5.0 [not yet released]
22

3+
- use GraphHopper#setGraphHopperLocation before calling load() instead of GraphHopper#load(graphHopperLocation) (#2437)
34
- barrier nodes at junctions are now ignored (#2433)
45
- AbstractFlagEncoder#handleNodeTags was replaced by AbstractFlagEncoder#isBarrier (#2434)
56
- consider heading when snapping coordinates to the road network, this is especially important for navigation (#2411)

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

Lines changed: 71 additions & 101 deletions
Large diffs are not rendered by default.

core/src/main/java/com/graphhopper/routing/ch/CHPreparationHandler.java

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class CHPreparationHandler {
4646
// we first add the profiles and later read them to create the config objects (because they require
4747
// the actual Weightings)
4848
private final List<CHProfile> chProfiles = new ArrayList<>();
49-
private final List<CHConfig> chConfigs = new ArrayList<>();
5049
private int preparationThreads;
5150
private ExecutorService threadPool;
5251
// ORS-GH MOD START change visibility private-> protected and allow overriding String constants
@@ -74,57 +73,7 @@ public void init(GraphHopperConfig ghConfig) {
7473
}
7574

7675
public final boolean isEnabled() {
77-
return !chProfiles.isEmpty() || !chConfigs.isEmpty() || !preparations.isEmpty();
78-
}
79-
80-
/**
81-
* Decouple CH profiles from PrepareContractionHierarchies as we need CH profiles for the
82-
* graphstorage and the graphstorage for the preparation.
83-
*/
84-
public CHPreparationHandler addCHConfig(CHConfig chConfig) {
85-
chConfigs.add(chConfig);
86-
return this;
87-
}
88-
89-
public CHPreparationHandler addPreparation(PrepareContractionHierarchies pch) {
90-
// we want to make sure that CH preparations are added in the same order as their corresponding profiles
91-
if (preparations.size() >= chConfigs.size()) {
92-
throw new IllegalStateException("You need to add the corresponding CH configs before adding preparations.");
93-
}
94-
CHConfig expectedConfig = chConfigs.get(preparations.size());
95-
if (!pch.getCHConfig().equals(expectedConfig)) {
96-
throw new IllegalArgumentException("CH config of preparation: " + pch + " needs to be identical to previously added CH config: " + expectedConfig);
97-
}
98-
preparations.add(pch);
99-
return this;
100-
}
101-
102-
public final boolean hasCHConfigs() {
103-
return !chConfigs.isEmpty();
104-
}
105-
106-
public List<CHConfig> getCHConfigs() {
107-
return chConfigs;
108-
}
109-
110-
public List<CHConfig> getNodeBasedCHConfigs() {
111-
List<CHConfig> result = new ArrayList<>();
112-
for (CHConfig chConfig : chConfigs) {
113-
if (!chConfig.getTraversalMode().isEdgeBased()) {
114-
result.add(chConfig);
115-
}
116-
}
117-
return result;
118-
}
119-
120-
public List<CHConfig> getEdgeBasedCHConfigs() {
121-
List<CHConfig> result = new ArrayList<>();
122-
for (CHConfig chConfig : chConfigs) {
123-
if (chConfig.getTraversalMode().isEdgeBased()) {
124-
result.add(chConfig);
125-
}
126-
}
127-
return result;
76+
return !chProfiles.isEmpty() || !preparations.isEmpty();
12877
}
12978

13079
public CHPreparationHandler setCHProfiles(CHProfile... chProfiles) {
@@ -206,14 +155,11 @@ public void prepare(final StorableProperties properties, final boolean closeEarl
206155
}
207156

208157
public void createPreparations(GraphHopperStorage ghStorage) {
209-
if (!isEnabled() || !preparations.isEmpty())
210-
return;
211-
if (!hasCHConfigs())
212-
throw new IllegalStateException("No CH profiles found");
213-
158+
if (!preparations.isEmpty())
159+
throw new IllegalStateException("CH preparations were created already");
214160
LOGGER.info("Creating CH preparations, {}", getMemInfo());
215-
for (CHConfig chConfig : chConfigs) {
216-
addPreparation(createCHPreparation(ghStorage, chConfig));
161+
for (CHConfig chConfig : ghStorage.getCHConfigs()) {
162+
preparations.add(createCHPreparation(ghStorage, chConfig));
217163
}
218164
}
219165

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

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ public class LMPreparationHandler {
5757
private int landmarkCount = 16;
5858

5959
private final List<PrepareLandmarks> preparations = new ArrayList<>();
60-
// we first add the profiles and later read them to create the config objects (because they require
61-
// the actual Weightings)
6260
private final List<LMProfile> lmProfiles = new ArrayList<>();
63-
private final List<LMConfig> lmConfigs = new ArrayList<>();
6461
private final Map<String, Double> maximumWeights = new HashMap<>();
6562
private int minNodes = -1;
6663
private final List<String> lmSuggestionsLocations = new ArrayList<>(5);
@@ -123,7 +120,7 @@ public int getLandmarks() {
123120
}
124121

125122
public final boolean isEnabled() {
126-
return !lmProfiles.isEmpty() || !lmConfigs.isEmpty() || !preparations.isEmpty();
123+
return !lmProfiles.isEmpty() || !preparations.isEmpty();
127124
}
128125

129126
public int getPreparationThreads() {
@@ -162,40 +159,10 @@ public List<LMProfile> getLMProfiles() {
162159
return lmProfiles;
163160
}
164161

165-
/**
166-
* Decouple weightings from PrepareLandmarks as we need weightings for the graphstorage and the
167-
* graphstorage for the preparation.
168-
*/
169-
public LMPreparationHandler addLMConfig(LMConfig lmConfig) {
170-
lmConfigs.add(lmConfig);
171-
return this;
172-
}
173-
174-
public LMPreparationHandler addPreparation(PrepareLandmarks plm) {
175-
preparations.add(plm);
176-
int lastIndex = preparations.size() - 1;
177-
if (lastIndex >= lmConfigs.size())
178-
throw new IllegalStateException("Cannot access profile for PrepareLandmarks with " + plm.getLMConfig()
179-
+ ". Call add(LMConfig) before");
180-
181-
if (preparations.get(lastIndex).getLMConfig() != lmConfigs.get(lastIndex))
182-
throw new IllegalArgumentException("LMConfig of PrepareLandmarks " + preparations.get(lastIndex).getLMConfig()
183-
+ " needs to be identical to previously added " + lmConfigs.get(lastIndex));
184-
return this;
185-
}
186-
187-
public boolean hasLMProfiles() {
188-
return !lmConfigs.isEmpty();
189-
}
190-
191162
public int size() {
192163
return preparations.size();
193164
}
194165

195-
public List<LMConfig> getLMConfigs() {
196-
return lmConfigs;
197-
}
198-
199166
public List<PrepareLandmarks> getPreparations() {
200167
return preparations;
201168
}
@@ -222,13 +189,15 @@ public PrepareLandmarks getPreparation(String profile) {
222189
* @return true if the preparation data for at least one profile was calculated.
223190
* @see CHPreparationHandler#prepare(StorableProperties, boolean) for a very similar method
224191
*/
225-
public boolean loadOrDoWork(final StorableProperties properties, final boolean closeEarly) {
192+
public boolean loadOrDoWork(List<LMConfig> lmConfigs, GraphHopperStorage ghStorage, LocationIndex locationIndex, final boolean closeEarly) {
193+
createPreparations(lmConfigs, ghStorage, locationIndex);
226194
for (PrepareLandmarks prep : preparations) {
227195
// using the area index we separate certain areas from each other but we do not change the base graph for this
228196
// so that other algorithms still can route between these areas
229197
if (areaIndex != null)
230198
prep.setAreaIndex(areaIndex);
231199
}
200+
StorableProperties properties = ghStorage.getProperties();
232201
ExecutorCompletionService<String> completionService = new ExecutorCompletionService<>(threadPool);
233202
int counter = 0;
234203
final AtomicBoolean prepared = new AtomicBoolean(false);
@@ -269,12 +238,9 @@ public boolean loadOrDoWork(final StorableProperties properties, final boolean c
269238
/**
270239
* This method creates the landmark storages ready for landmark creation.
271240
*/
272-
public void createPreparations(GraphHopperStorage ghStorage, LocationIndex locationIndex) {
273-
if (!isEnabled() || !preparations.isEmpty())
274-
return;
275-
if (lmConfigs.isEmpty())
276-
throw new IllegalStateException("No landmark weightings found");
277-
241+
void createPreparations(List<LMConfig> lmConfigs, GraphHopperStorage ghStorage, LocationIndex locationIndex) {
242+
if (!preparations.isEmpty())
243+
throw new IllegalStateException("LM preparations were created already");
278244
LOGGER.info("Creating LM preparations, {}", getMemInfo());
279245
List<LandmarkSuggestion> lmSuggestions = new ArrayList<>(lmSuggestionsLocations.size());
280246
if (!lmSuggestionsLocations.isEmpty()) {
@@ -288,28 +254,34 @@ public void createPreparations(GraphHopperStorage ghStorage, LocationIndex locat
288254
}
289255

290256
// ORS-GH MOD START abstract to a method in order to facilitate overriding
291-
createPreparationsInternal(ghStorage, lmSuggestions);
257+
createPreparationsInternal(ghStorage, lmConfigs, lmSuggestions);
292258
}
293259

294-
protected void createPreparationsInternal(GraphHopperStorage ghStorage, List<LandmarkSuggestion> lmSuggestions) {
260+
protected void createPreparationsInternal(GraphHopperStorage ghStorage, List<LMConfig> lmConfigs, List<LandmarkSuggestion> lmSuggestions) {
295261
// ORS-GH MOD END
296262
for (LMConfig lmConfig : lmConfigs) {
297263
Double maximumWeight = maximumWeights.get(lmConfig.getName());
298264
if (maximumWeight == null)
299265
throw new IllegalStateException("maximumWeight cannot be null. Default should be just negative. " +
300266
"Couldn't find " + lmConfig.getName() + " in " + maximumWeights);
301267

302-
PrepareLandmarks tmpPrepareLM = new PrepareLandmarks(ghStorage.getDirectory(), ghStorage,
268+
PrepareLandmarks prepareLandmarks = new PrepareLandmarks(ghStorage.getDirectory(), ghStorage,
303269
lmConfig, landmarkCount).
304270
setLandmarkSuggestions(lmSuggestions).
305271
setMaximumWeight(maximumWeight).
306272
setLogDetails(logDetails);
307273
if (minNodes > 1)
308-
tmpPrepareLM.setMinimumNodes(minNodes);
309-
addPreparation(tmpPrepareLM);
274+
prepareLandmarks.setMinimumNodes(minNodes);
275+
preparations.add(prepareLandmarks);
310276
}
311277
}
312278

279+
// ORS-GH MOD START for tests
280+
public void createPreparations(List<LMConfig> lmConfigs, GraphHopperStorage ghStorage) {
281+
createPreparations(lmConfigs, ghStorage, null);
282+
}
283+
// ORS-GH MOD END
284+
313285
private JsonFeatureCollection loadLandmarkSplittingFeatureCollection(String splitAreaLocation) {
314286
ObjectMapper objectMapper = new ObjectMapper();
315287
objectMapper.registerModule(new JtsModule());
@@ -331,10 +303,6 @@ private JsonFeatureCollection loadLandmarkSplittingFeatureCollection(String spli
331303
}
332304

333305
// ORS-GH MOD START add methods
334-
public List<Weighting> getWeightings() {
335-
return lmConfigs.stream().map(lmConfig -> lmConfig.getWeighting()).collect(Collectors.toList());
336-
}
337-
338306
public Map<String, Double> getMaximumWeights() {
339307
return maximumWeights;
340308
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* suboptimal automatic landmark finding process.
1717
*/
1818
public class LandmarkSuggestion {
19-
private List<Integer> nodeIds;
20-
private BBox box;
19+
private final List<Integer> nodeIds;
20+
private final BBox box;
2121

2222
public LandmarkSuggestion(List<Integer> nodeIds, BBox box) {
2323
this.nodeIds = nodeIds;
@@ -36,10 +36,10 @@ public BBox getBox() {
3636
* The expected format is lon,lat per line where lines starting with characters will be ignored. You can create
3737
* such a file manually via geojson.io -> Save as CSV. Optionally add a second line with
3838
* <pre>#BBOX:minLat,minLon,maxLat,maxLon</pre>
39-
*
39+
* <p>
4040
* to specify an explicit bounding box. TODO: support GeoJSON instead.
4141
*/
42-
public static final LandmarkSuggestion readLandmarks(String file, LocationIndex locationIndex) throws IOException {
42+
public static LandmarkSuggestion readLandmarks(String file, LocationIndex locationIndex) throws IOException {
4343
// landmarks should be suited for all vehicles
4444
EdgeFilter edgeFilter = EdgeFilter.ALL_EDGES;
4545
List<String> lines = Helper.readFile(file);

core/src/main/java/com/graphhopper/storage/GraphHopperStorage.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ protected CHEntry createCHEntry(CHConfig chConfig) {
159159
* @see #addCHGraph(CHConfig)
160160
*/
161161
public GraphHopperStorage addCHGraphs(List<CHConfig> chConfigs) {
162-
for (CHConfig chConfig : chConfigs) {
162+
for (CHConfig chConfig : chConfigs)
163163
addCHGraph(chConfig);
164-
}
165164
return this;
166165
}
167166

0 commit comments

Comments
 (0)