@@ -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 }
0 commit comments