22 package org.matsim.core.controler;
25 import jakarta.inject.Inject;
26 import jakarta.inject.Provider;
27 import org.apache.logging.log4j.LogManager;
28 import org.apache.logging.log4j.Logger;
58 import javax.annotation.Nullable;
125 log.info(
"Network seems to be multimodal. Create car-only network which is handed over to PersonPrepareForSim.");
128 HashSet<String> modes =
new HashSet<>();
130 filter.
filter(carOnlyNetwork, modes);
149 case onePerActivityLinkInPlansFile:
151 case onePerActivityLocationInPlansFile:
159 facilitiesFromPopulation.
run(population);
179 if (prepareForSimAlgorithms != null) {
199 ((Lockable)scenario).setLocked();
203 if (population instanceof Lockable) {
204 ((Lockable) population).setLocked();
207 if ( network instanceof Lockable ) {
208 ((Lockable) network).setLocked();
211 if (activityFacilities instanceof Lockable) {
212 ((Lockable) activityFacilities).setLocked();
228 Map<String, Id<Vehicle>> modeToVehicle =
new HashMap<>();
233 for (Map.Entry<String,
VehicleType> modeType : modeVehicleTypes.entrySet()) {
235 String mode = modeType.getKey();
243 if (modeTypes != null && modeTypes.containsKey(mode)) {
247 throw new IllegalStateException(
"Vehicle type " + typeId +
" specified for person " + person.getId() +
", but not found in scenario.");
254 modeToVehicle.put(mode, vehicleId);
265 log.warn(
"'usePersonIdForMissingVehicleId' is deprecated. It will be removed soon.");
277 Map<String, VehicleType> modeVehicleTypes =
new HashMap<>();
281 return modeVehicleTypes;
284 Set<String> modes =
new HashSet<>(qSimConfigGroup.
getMainModes());
287 for (String mode : modes) {
296 case modeVehicleTypesFromVehiclesData:
299 log.fatal(
"Could not find requested vehicle type =" + mode +
". With config setting " + modeVehicleTypesFromVehiclesData.toString() +
", you need");
300 log.fatal(
"to add, for each mode that performs network routing and/or is used as network/main mode in the qsim, a vehicle type for that mode." );
301 throw new RuntimeException(
"Could not find requested vehicle type = " + mode +
". See above.");
308 modeVehicleTypes.put(mode, type);
310 return modeVehicleTypes;
319 case modeVehicleTypesFromVehiclesData:
324 throw new RuntimeException(
"Expecting a vehicle id which is missing in the vehicles database: " + vehicleId);
338 for (
Plan plan : person.getPlans()) {
340 List<Leg> legs = trip.getLegsOnly();
341 if (legs.size() >= 1) {
344 for (
Leg leg : legs) {
347 if (routingMode != null) {
348 String errorMessage =
"Found a mixed trip having some legs with routingMode set and others without. " 349 +
"This is inconsistent. Agent id: " + person.getId().toString()
350 +
"\nTrip: " + trip.getTripElements().toString();
351 log.error(errorMessage);
359 String errorMessage =
"Found a trip whose legs have different routingModes. " 360 +
"This is inconsistent. Agent id: " + person.getId().toString()
361 +
"\nTrip: " + trip.getTripElements().toString();
362 log.error(errorMessage);
369 if (routingMode == null) {
370 if (legs.size() == 1) {
375 if (oldMainMode != null) {
376 routingMode = oldMainMode;
380 routingMode = legs.get(0).getMode();
385 for (
Leg leg : legs) {
391 String errorMessage =
"Found a trip with multiple legs and no routingMode. " 392 +
"Person id " + person.getId().toString()
393 +
"\nTrip: " + trip.getTripElements().toString()
394 +
"\nTerminating. Take care to inject an adequate MainModeIdentifier and set config switch " 395 +
"plansConfigGroup.setHandlingOfPlansWithoutRoutingMode(" 397 log.error(errorMessage);
403 for (
Leg leg : legs) {
407 "Found a walk leg with a NetworkRoute. This is the only allowed use case of having " 408 +
"non_network_walk as an access/egress mode. PrepareForSimImpl replaces " 409 +
"non_network_walk with walk, because access/egress to modes other than walk should " 410 +
"use the walk Router. If this causes any problem please report to gleich or kai -nov'19");
414 for (
Leg leg : legs) {
427 if (insistingOnPlansWithoutRoutingModeLogWarnNotShownYet) {
429 "Insisting on using backward compatibility MainModeIdentifier instead of setting routingMode directly.");
430 insistingOnPlansWithoutRoutingModeLogWarnNotShownYet =
false;
432 if (backwardCompatibilityMainModeIdentifier == null) {
434 "Found a trip without routingMode, but there is no MainModeIdentifier set up for PrepareForSim, so cannot infer the routing mode from a MainModeIdentifier. Trip: " 436 throw new RuntimeException(
"no MainModeIdentifier set up for PrepareForSim");
439 if (routingMode != null) {
444 String errorMessage =
"Found a trip whose legs had no routingMode. " 445 +
"The backwardCompatibilityMainModeIdentifier could not identify the mode. " +
"Agent id: " 446 + person.getId().toString() +
"\nTrip: " + trip.
getTripElements().toString();
447 log.error(errorMessage);
455 if (leg.
getMode().equals(
"access_walk") || leg.
getMode().equals(
"egress_walk")) {
487 String oldMainMode = leg.
getMode().substring(0, leg.
getMode().length() - 5);
494 if (leg.
getMode().endsWith(
"_fallback")) {
495 String oldMainMode = leg.
getMode().substring(0, leg.
getMode().length() - 9);
final FacilitiesConfigGroup facilitiesConfigGroup
Map< Id< ActivityFacility >, ? extends ActivityFacility > getFacilities()
static< T > Id< T > get(int index, final Class< T > type)
final PlansConfigGroup plansConfigGroup
static String getRoutingMode(Leg leg)
String replaceOutdatedFallbackModesAndReturnOldMainMode(Leg leg, String routingMode)
modeVehicleTypesFromVehiclesData
final Population population
static void assertIf(boolean flag)
void run(final Population population)
static Id< Vehicle > createVehicleId(final long key)
static void run(Network network, ActivityFacilities facilities)
List< Leg > getLegsOnly()
final NetworkConfigGroup network()
Collection< String > getMainModes()
static boolean isMultimodal(final Network network)
VehiclesFactory getFactory()
void filter(final Network subNetwork, final Set< String > extractModes)
Map< Id< VehicleType >, VehicleType > getVehicleTypes()
static Map< String, Id< VehicleType > > getVehicleTypes(Person person)
String identifyMainMode(List<? extends PlanElement > tripElements)
void addVehicleType(final VehicleType type)
Map< Id< Person >,? extends Person > getPersons()
void createAndAddVehiclesForEveryNetworkMode()
static< T > Id< T > create(final long key, final Class< T > type)
void setMode(String mode)
static void setRoutingMode(Leg leg, String mode)
final Provider< TripRouter > tripRouterProvider
void addVehicle(final Vehicle v)
final QSimConfigGroup qSimConfigGroup
final MainModeIdentifier backwardCompatibilityMainModeIdentifier
final VehiclesSource getVehiclesSource()
Population getPopulation()
final ActivityFacilities activityFacilities
static Network createNetwork()
static final String transit_walk
final HandlingOfPlansWithoutRoutingMode getHandlingOfPlansWithoutRoutingMode()
static List< Trip > getTrips(final Plan plan)
static boolean insistingOnPlansWithoutRoutingModeLogWarnNotShownYet
static VehicleType createDefaultVehicleType()
static void run(final Population population, final int numberOfThreads, final PersonAlgorithm algorithm)
static void assertNotNull(Object obj)
final GlobalConfigGroup globalConfigGroup
RoutingConfigGroup routing()
void replaceOutdatedNonNetworkWalk(Leg leg, String routingMode)
void createAndAddVehicleIfNecessary(Id< Vehicle > vehicleId, VehicleType vehicleType)
Vehicle createVehicle(Id< Vehicle > id, VehicleType type)
final Id< VehicleType > getId()
static Id< Vehicle > createVehicleId(Person person, String mode)
FacilitiesSource getFacilitiesSource()
static final String non_network_walk
Map< Id< Vehicle >, Vehicle > getVehicles()
Set< PersonPrepareForSimAlgorithm > prepareForSimAlgorithms
Id< Vehicle > createVehicleId(Person person, String modeType)
boolean getUsePersonIdForMissingVehicleId()
void adaptOutdatedPlansForRoutingMode()
Map< String, VehicleType > getVehicleTypesForAllNetworkAndMainModes()
Collection< String > getNetworkModes()
String getAndAddRoutingModeFromBackwardCompatibilityMainModeIdentifier(Person person, Trip trip)
static void insertVehicleIdsIntoAttributes(Person person, Map< String, Id< Vehicle >> modeToVehicle)
List< PlanElement > getTripElements()
void replaceOutdatedAccessEgressWalkModes(Leg leg, String routingMode)
final TimeInterpretation timeInterpretation