MATSIM
PrepareForMobsimImpl.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * PrepareForMobsimImpl.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.core.controler;
23 
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
26 import org.matsim.api.core.v01.Scenario;
40 
41 import jakarta.inject.Inject;
42 import jakarta.inject.Provider;
43 import java.util.HashSet;
44 
45 public final class PrepareForMobsimImpl implements PrepareForMobsim {
46  // I think it is ok to have this public final. Since one may want to use it as a delegate. kai, may'18
47  // yyyyyy but how should that work with a non-public constructor? kai, jun'18
48  // Well, I guess it can be injected as well?!
49  // bind( PrepareForSimImpl.class ) ;
50  // bind( PrepareForSim.class ).to( MyPrepareForSimImpl.class ) ;
51 
52  private static final Logger log = LogManager.getLogger(PrepareForMobsimImpl.class);
53 
55  private final Scenario scenario;
56  private final Network network;
57  private final Population population;
59  private final Provider<TripRouter> tripRouterProvider;
61 
62  @Inject
63  PrepareForMobsimImpl(GlobalConfigGroup globalConfigGroup, Scenario scenario, Network network,
64  Population population, ActivityFacilities activityFacilities, Provider<TripRouter> tripRouterProvider, TimeInterpretation timeInterpretation) {
65  this.globalConfigGroup = globalConfigGroup;
66  this.scenario = scenario;
67  this.network = network;
68  this.population = population;
69  this.activityFacilities = activityFacilities;
70  this.tripRouterProvider = tripRouterProvider;
71  this.timeInterpretation = timeInterpretation;
72  }
73 
74 
75  @Override
76  public void run() {
77  /*
78  * Create single-mode network here and hand it over to PersonPrepareForSim. Otherwise, each instance would create its
79  * own single-mode network. However, this assumes that the main mode is car - which PersonPrepareForSim also does. Should
80  * be probably adapted in a way that other main modes are possible as well. cdobler, oct'15.
81  * This is now only used for xy2links, which is the "street address" of the activity location of facility, and here for the time being we indeed
82  * assume that it can be reached by car. kai, jul'18
83  */
84  final Network carOnlyNetwork;
85  if (NetworkUtils.isMultimodal(network)) {
86  log.info("Network seems to be multimodal. Create car-only network which is handed over to PersonPrepareForSim.");
88  carOnlyNetwork = NetworkUtils.createNetwork(scenario.getConfig().network());
89  HashSet<String> modes = new HashSet<>();
90  modes.add(TransportMode.car);
91  filter.filter(carOnlyNetwork, modes);
92  } else {
93  carOnlyNetwork = network;
94  }
95 
96  // make sure all routes are calculated.
97  ParallelPersonAlgorithmUtils.run(population, globalConfigGroup.getNumberOfThreads(),
99  @Override
100  public AbstractPersonAlgorithm getPersonAlgorithm() {
101  return new PersonPrepareForSim(new PlanRouter(tripRouterProvider.get(), activityFacilities, timeInterpretation), scenario,
102  carOnlyNetwork );
103  }
104  // yyyyyy This prepared network is only used for computing the distance. So the full network would
105  // actually be better than the car-only network, without doing damage elsewhere. No? kai, jul'18
106  }
107  );
108 
109  // yy Could now set the vehicle IDs in the routes. But can as well also do this later (currently in PopulationAgentSource). kai, jun'18
110 
111  }
112 
113 }
final NetworkConfigGroup network()
Definition: Config.java:411
static boolean isMultimodal(final Network network)
void filter(final Network subNetwork, final Set< String > extractModes)
static void run(final Population population, final int numberOfThreads, final PersonAlgorithm algorithm)