MATSIM
PermissibleModesCalculatorImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * PermissibleModesCalculatorImpl.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2012 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 package org.matsim.core.population.algorithms;
21 
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
27 import jakarta.inject.Inject;
31 import org.matsim.core.config.Config;
33 
35 
36  private final List<String> availableModes;
37  private final List<String> availableModesWithoutCar;
38  private final boolean considerCarAvailability;
39 
40  @Inject
42  this.availableModes = Arrays.asList(config.subtourModeChoice().getModes());
43 
44  if (this.availableModes.contains(TransportMode.car)) {
45  final List<String> l = new ArrayList<String>(this.availableModes);
46  while (l.remove(TransportMode.car)) {
47  }
48  this.availableModesWithoutCar = Collections.unmodifiableList(l);
49  } else {
50  this.availableModesWithoutCar = this.availableModes;
51  }
52 
53  this.considerCarAvailability = config.subtourModeChoice().considerCarAvailability();
54  }
55 
56  @Override
57  public Collection<String> getPermissibleModes(final Plan plan) {
58  if (!considerCarAvailability) return availableModes;
59 
60  final Person person;
61  try {
62  person = plan.getPerson();
63  }
64  catch (ClassCastException e) {
65  throw new IllegalArgumentException( "I need a PersonImpl to get car availability" );
66  }
67 
68  final boolean carAvail =
69  !"no".equals( PersonUtils.getLicense(person) ) &&
70  !"never".equals( PersonUtils.getCarAvail(person) );
71 
72  return carAvail ? availableModes : availableModesWithoutCar;
73  }
74 }
static String getCarAvail(Person person)
SubtourModeChoiceConfigGroup subtourModeChoice()
Definition: Config.java:471
static String getLicense(Person person)