26
26
import com .graphhopper .routing .RoutingAlgorithmFactorySimple ;
27
27
import com .graphhopper .routing .ch .CHPreparationHandler ;
28
28
import com .graphhopper .routing .util .HintsMap ;
29
- import com .graphhopper .routing .weighting .AbstractWeighting ;
30
- import com .graphhopper .routing .weighting .Weighting ;
31
29
import com .graphhopper .storage .Graph ;
32
30
import com .graphhopper .storage .GraphHopperStorage ;
33
31
import com .graphhopper .storage .StorableProperties ;
@@ -59,8 +57,8 @@ public class LMPreparationHandler {
59
57
private final List <PrepareLandmarks > preparations = new ArrayList <>();
60
58
// input weighting list from configuration file
61
59
// one such entry can result into multiple Weighting objects e.g. fastest & car,foot => fastest|car and fastest|foot
62
- private final List <String > weightingsAsStrings = new ArrayList <>();
63
- private final List <Weighting > weightings = new ArrayList <>();
60
+ private final List <String > lmProfileStrings = new ArrayList <>();
61
+ private final List <LMProfile > lmProfiles = new ArrayList <>();
64
62
private final Map <String , Double > maximumWeights = new HashMap <>();
65
63
private boolean enabled = false ;
66
64
private int minNodes = -1 ;
@@ -89,10 +87,10 @@ public void init(GraphHopperConfig ghConfig) {
89
87
String lmWeightingsStr = ghConfig .get (Landmark .PREPARE + "weightings" , "" );
90
88
if (!lmWeightingsStr .isEmpty () && !lmWeightingsStr .equalsIgnoreCase ("no" ) && !lmWeightingsStr .equalsIgnoreCase ("false" )) {
91
89
List <String > tmpLMWeightingList = Arrays .asList (lmWeightingsStr .split ("," ));
92
- setWeightingsAsStrings (tmpLMWeightingList );
90
+ setLMProfileStrings (tmpLMWeightingList );
93
91
}
94
92
95
- boolean enableThis = !weightingsAsStrings .isEmpty ();
93
+ boolean enableThis = !getLMProfileStrings () .isEmpty ();
96
94
setEnabled (enableThis );
97
95
if (enableThis )
98
96
setDisablingAllowed (ghConfig .getBool (Landmark .INIT_DISABLING_ALLOWED , isDisablingAllowed ()));
@@ -137,40 +135,34 @@ public void setPreparationThreads(int preparationThreads) {
137
135
}
138
136
139
137
/**
140
- * Enables the use of contraction hierarchies to reduce query times. Enabled by default .
138
+ * Enables the use of landmarks to reduce query times.
141
139
*
142
- * @param weightingList A list containing multiple weightings like: "fastest", "shortest" or
143
- * your own weight-calculation type.
140
+ * @param lmProfilesStrings A list containing multiple lm profiles like: "fastest", "shortest" or
141
+ * your own weight-calculation type.
144
142
*/
145
- public LMPreparationHandler setWeightingsAsStrings (List <String > weightingList ) {
146
- if (weightingList .isEmpty ())
147
- throw new IllegalArgumentException ("It is not allowed to pass an emtpy weightingList" );
148
-
149
- weightingsAsStrings .clear ();
150
- for (String strWeighting : weightingList ) {
151
- strWeighting = toLowerCase (strWeighting );
152
- strWeighting = strWeighting .trim ();
153
- addWeighting (strWeighting );
143
+ public LMPreparationHandler setLMProfileStrings (List <String > lmProfilesStrings ) {
144
+ lmProfileStrings .clear ();
145
+ for (String profileStr : lmProfilesStrings ) {
146
+ profileStr = toLowerCase (profileStr );
147
+ profileStr = profileStr .trim ();
148
+ addLMProfileAsString (profileStr );
154
149
}
155
150
return this ;
156
151
}
157
152
158
- public List <String > getWeightingsAsStrings () {
159
- if (this .weightingsAsStrings .isEmpty ())
160
- throw new IllegalStateException ("Potential bug: weightingsAsStrings is empty" );
161
-
162
- return this .weightingsAsStrings ;
153
+ public List <String > getLMProfileStrings () {
154
+ return lmProfileStrings ;
163
155
}
164
156
165
- public LMPreparationHandler addWeighting (String weighting ) {
166
- String [] str = weighting .split ("\\ |" );
157
+ public LMPreparationHandler addLMProfileAsString (String profile ) {
158
+ String [] str = profile .split ("\\ |" );
167
159
double value = -1 ;
168
160
if (str .length > 1 ) {
169
- PMap map = new PMap (weighting );
161
+ PMap map = new PMap (profile );
170
162
value = map .getDouble ("maximum" , -1 );
171
163
}
172
164
173
- weightingsAsStrings .add (str [0 ]);
165
+ lmProfileStrings .add (str [0 ]);
174
166
maximumWeights .put (str [0 ], value );
175
167
return this ;
176
168
}
@@ -179,26 +171,26 @@ public LMPreparationHandler addWeighting(String weighting) {
179
171
* Decouple weightings from PrepareLandmarks as we need weightings for the graphstorage and the
180
172
* graphstorage for the preparation.
181
173
*/
182
- public LMPreparationHandler addWeighting ( Weighting weighting ) {
183
- weightings .add (weighting );
174
+ public LMPreparationHandler addLMProfile ( LMProfile lmProfile ) {
175
+ lmProfiles .add (lmProfile );
184
176
return this ;
185
177
}
186
178
187
179
public LMPreparationHandler addPreparation (PrepareLandmarks plm ) {
188
180
preparations .add (plm );
189
181
int lastIndex = preparations .size () - 1 ;
190
- if (lastIndex >= weightings .size ())
191
- throw new IllegalStateException ("Cannot access weighting for PrepareLandmarks with " + plm .getWeighting ()
192
- + ". Call add(Weighting ) before" );
182
+ if (lastIndex >= lmProfiles .size ())
183
+ throw new IllegalStateException ("Cannot access profile for PrepareLandmarks with " + plm .getLMProfile ()
184
+ + ". Call add(LMProfile ) before" );
193
185
194
- if (preparations .get (lastIndex ).getWeighting () != weightings .get (lastIndex ))
195
- throw new IllegalArgumentException ("Weighting of PrepareContractionHierarchies " + preparations .get (lastIndex ).getWeighting ()
196
- + " needs to be identical to previously added " + weightings .get (lastIndex ));
186
+ if (preparations .get (lastIndex ).getLMProfile () != lmProfiles .get (lastIndex ))
187
+ throw new IllegalArgumentException ("LMProfile of PrepareLandmarks " + preparations .get (lastIndex ).getLMProfile ()
188
+ + " needs to be identical to previously added " + lmProfiles .get (lastIndex ));
197
189
return this ;
198
190
}
199
191
200
- public boolean hasWeightings () {
201
- return !weightings .isEmpty ();
192
+ public boolean hasLMProfiles () {
193
+ return !lmProfiles .isEmpty ();
202
194
}
203
195
204
196
public boolean hasPreparations () {
@@ -209,10 +201,6 @@ public int size() {
209
201
return preparations .size ();
210
202
}
211
203
212
- public List <Weighting > getWeightings () {
213
- return weightings ;
214
- }
215
-
216
204
public List <PrepareLandmarks > getPreparations () {
217
205
return preparations ;
218
206
}
@@ -230,10 +218,10 @@ public RoutingAlgorithmFactory getAlgorithmFactory(HintsMap map) {
230
218
return new LMRoutingAlgorithmFactory (preparations .get (0 ), new RoutingAlgorithmFactorySimple ());
231
219
}
232
220
233
- List <Weighting > lmWeightings = new ArrayList <>(preparations .size ());
221
+ List <String > lmProfiles = new ArrayList <>(preparations .size ());
234
222
for (final PrepareLandmarks p : preparations ) {
235
- lmWeightings .add (p .getWeighting ());
236
- if (p .getWeighting ().matches (map ))
223
+ lmProfiles .add (p .getLMProfile (). getName ());
224
+ if (p .getLMProfile (). getWeighting ().matches (map ))
237
225
return new LMRoutingAlgorithmFactory (p , new RoutingAlgorithmFactorySimple ());
238
226
}
239
227
@@ -244,7 +232,7 @@ public RoutingAlgorithmFactory getAlgorithmFactory(HintsMap map) {
244
232
String requestedString = (map .getWeighting ().isEmpty () ? "*" : map .getWeighting ()) + "|" +
245
233
(map .getVehicle ().isEmpty () ? "*" : map .getVehicle ());
246
234
throw new IllegalArgumentException ("Cannot find matching LM profile for your request." +
247
- "\n requested: " + requestedString + "\n available: " + lmWeightings );
235
+ "\n requested: " + requestedString + "\n available: " + lmProfiles );
248
236
}
249
237
250
238
/**
@@ -271,9 +259,9 @@ public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
271
259
}
272
260
273
261
/**
274
- * This method calculates the landmark data for all weightings (optionally in parallel) or if already existent loads it.
262
+ * This method calculates the landmark data for all profiles (optionally in parallel) or if already existent loads it.
275
263
*
276
- * @return true if the preparation data for at least one weighting was calculated.
264
+ * @return true if the preparation data for at least one profile was calculated.
277
265
* @see CHPreparationHandler#prepare(StorableProperties, boolean) for a very similar method
278
266
*/
279
267
public boolean loadOrDoWork (final StorableProperties properties , final boolean closeEarly ) {
@@ -283,14 +271,14 @@ public boolean loadOrDoWork(final StorableProperties properties, final boolean c
283
271
for (final PrepareLandmarks plm : preparations ) {
284
272
counter ++;
285
273
final int tmpCounter = counter ;
286
- final String name = AbstractWeighting . weightingToFileName ( plm .getWeighting () );
274
+ final String name = plm .getLMProfile (). getName ( );
287
275
completionService .submit (new Runnable () {
288
276
@ Override
289
277
public void run () {
290
278
if (plm .loadExisting ())
291
279
return ;
292
280
293
- LOGGER .info (tmpCounter + "/" + getPreparations ().size () + " calling LM prepare.doWork for " + plm .getWeighting () + " ... (" + getMemInfo () + ")" );
281
+ LOGGER .info (tmpCounter + "/" + getPreparations ().size () + " calling LM prepare.doWork for " + plm .getLMProfile (). getWeighting () + " ... (" + getMemInfo () + ")" );
294
282
prepared .set (true );
295
283
Thread .currentThread ().setName (name );
296
284
plm .doWork ();
@@ -321,7 +309,7 @@ public void run() {
321
309
public void createPreparations (GraphHopperStorage ghStorage , LocationIndex locationIndex ) {
322
310
if (!isEnabled () || !preparations .isEmpty ())
323
311
return ;
324
- if (weightings .isEmpty ())
312
+ if (lmProfiles .isEmpty ())
325
313
throw new IllegalStateException ("No landmark weightings found" );
326
314
327
315
List <LandmarkSuggestion > lmSuggestions = new ArrayList <>(lmSuggestionsLocations .size ());
@@ -335,14 +323,14 @@ public void createPreparations(GraphHopperStorage ghStorage, LocationIndex locat
335
323
}
336
324
}
337
325
338
- for (Weighting weighting : getWeightings () ) {
339
- Double maximumWeight = maximumWeights .get (weighting .getName ());
326
+ for (LMProfile lmProfile : lmProfiles ) {
327
+ Double maximumWeight = maximumWeights .get (lmProfile . getWeighting () .getName ());
340
328
if (maximumWeight == null )
341
329
throw new IllegalStateException ("maximumWeight cannot be null. Default should be just negative. " +
342
- "Couldn't find " + weighting .getName () + " in " + maximumWeights );
330
+ "Couldn't find " + lmProfile .getName () + " in " + maximumWeights );
343
331
344
332
PrepareLandmarks tmpPrepareLM = new PrepareLandmarks (ghStorage .getDirectory (), ghStorage ,
345
- weighting , landmarkCount , activeLandmarkCount ).
333
+ lmProfile , landmarkCount , activeLandmarkCount ).
346
334
setLandmarkSuggestions (lmSuggestions ).
347
335
setMaximumWeight (maximumWeight ).
348
336
setLogDetails (logDetails );
0 commit comments