MATSIM
DefaultPlanStrategiesModule.java
Go to the documentation of this file.
1 /*
2  * *********************************************************************** *
3  * * project: org.matsim.*
4  * * DefaultPlanStrategiesModule.java
5  * * *
6  * * *********************************************************************** *
7  * * *
8  * * copyright : (C) 2015 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 
23 package org.matsim.core.replanning.strategies;
24 
25 import com.google.inject.TypeLiteral;
26 import java.util.HashSet;
27 import java.util.Set;
28 import jakarta.inject.Inject;
29 import jakarta.inject.Provider;
30 import org.apache.logging.log4j.LogManager;
31 import org.apache.logging.log4j.Logger;
46 
48  private static final Logger log = LogManager.getLogger( DefaultPlanStrategiesModule.class );
49 
50  public enum DefaultPlansRemover { WorstPlanSelector, SelectRandom, SelectExpBetaForRemoval, ChangeExpBetaForRemoval,
52 
53  @Override
54  public void install() {
55  if (getConfig().replanning().getPlanSelectorForRemoval().equals(DefaultPlansRemover.WorstPlanSelector.toString())) {
57  }
58  if (getConfig().replanning().getPlanSelectorForRemoval().equals(WorstPlanForRemovalSelectorWithConflicts.SELECTOR_NAME)) {
60  }
61  if (getConfig().replanning().getPlanSelectorForRemoval().equals(DefaultPlansRemover.SelectRandom.toString())) {
63  }
64  if (getConfig().replanning().getPlanSelectorForRemoval().equals(DefaultPlansRemover.SelectExpBetaForRemoval.toString())) {
66  }
67  if (getConfig().replanning().getPlanSelectorForRemoval().equals(DefaultPlansRemover.ChangeExpBetaForRemoval.toString())) {
69  }
70  if (getConfig().replanning().getPlanSelectorForRemoval().equals(DefaultPlansRemover.PathSizeLogitSelectorForRemoval.toString())) {
72  }
73 
74  // We only bind those stategies that the StrategyManager is actually going to use,
75  // according to the Config.
76  // If you bind your own strategy from your own module, and then don't reference it from the Config,
77  // that's fine: The StrategyManager will still only add those strategies to itself which are configured.
78  // But we don't want to clutter the container here.
79  Set<String> usedStrategyNames = new HashSet<>();
81  usedStrategyNames.add(settings.getStrategyName());
82  }
83 
84  // strategy packages that only select:
85  if (usedStrategyNames.contains(DefaultSelector.KeepLastSelected)) {
87  }
88  if (usedStrategyNames.contains(DefaultSelector.BestScore)) {
90  }
91  if (usedStrategyNames.contains(DefaultSelector.SelectExpBeta)) {
93  }
94  if (usedStrategyNames.contains(DefaultSelector.ChangeExpBeta)) {
96  }
97  if (usedStrategyNames.contains(DefaultSelector.SelectRandom)) {
99  }
100  if (usedStrategyNames.contains(DefaultSelector.SelectPathSizeLogit)) {
102  }
103 
104  // strategy packages that select, copy, and modify. (The copying is done implicitly as soon as "addStrategyModule" is called
105  // at least once).
106 
107  if (usedStrategyNames.contains(DefaultStrategy.ReRoute)) {
109  }
110  if (usedStrategyNames.contains(DefaultStrategy.TimeAllocationMutator)) {
112  }
113  if (usedStrategyNames.contains(DefaultStrategy.TimeAllocationMutator_ReRoute)) {
115  }
116  if (usedStrategyNames.contains(DefaultStrategy.SubtourModeChoice)) {
119  }
120  if (usedStrategyNames.contains(DefaultStrategy.ChangeTripMode)) {
122  }
123  if (usedStrategyNames.contains(DefaultStrategy.ChangeSingleTripMode)) {
125  }
126 
127  // td, 15 feb 16: removed the "Leg" versions of strategies. Notify the users that they should switch to the
128  // "Trip" versions. Should be left in 0.8.XXX releases, and then deleted, along with their name in the enum.
129  if ( usedStrategyNames.contains(DefaultStrategy.ChangeLegMode) ) {
130  log.error( DefaultStrategy.ChangeLegMode+" replanning strategy does not exist anymore. Please use "+DefaultStrategy.ChangeTripMode+" instead." );
131  }
132  if ( usedStrategyNames.contains(DefaultStrategy.ChangeSingleLegMode) ) {
133  log.error( DefaultStrategy.ChangeSingleLegMode+" replanning strategy does not exist anymore. Please use "+DefaultStrategy.ChangeSingleTripMode+" instead." );
134  }
135  if ( usedStrategyNames.contains(DefaultStrategy.TripSubtourModeChoice) ) {
136  log.error( DefaultStrategy.TripSubtourModeChoice+" replanning strategy does not exist anymore. Please use "+DefaultStrategy.SubtourModeChoice+" instead." );
137  }
138  }
139 
140  public interface DefaultSelector {
141  String KeepLastSelected="KeepLastSelected" ;
142  String BestScore="BestScore";
143  String ChangeExpBeta="ChangeExpBeta";
144  String SelectExpBeta="SelectExpBeta";
145  String SelectRandom="SelectRandom";
146  String SelectPathSizeLogit="SelectPathSizeLogit" ;
147  }
148 
149 
150  public interface DefaultStrategy {
151  String ReRoute="ReRoute";
152  String TimeAllocationMutator="TimeAllocationMutator";
153  @Deprecated String ChangeLegMode="ChangeLegMode";
154  String TimeAllocationMutator_ReRoute="TimeAllocationMutator_ReRoute" ;
155  @Deprecated String ChangeSingleLegMode = "ChangeSingleLegMode" ;
156  String ChangeSingleTripMode="ChangeSingleTripMode" ;
157  String SubtourModeChoice = "SubtourModeChoice" ;
158  String ChangeTripMode = "ChangeTripMode" ;
159  @Deprecated String TripSubtourModeChoice = "TripSubtourModeChoice" ;
160  }
161 
162  // yyyy Why are the following always implementing Providers of the full implementations, and not just the interface
163  // (i.e. Provider<GenericPlanSelector<Plan,Person>)? kai, jan'15
164 
165  private static class ExpBetaPlanSelectorForRemoval implements Provider<ExpBetaPlanSelector<Plan, Person>> {
166 
167  @Inject private ScoringConfigGroup config;
168 
169  @Override
171  return new ExpBetaPlanSelector<>( - config.getBrainExpBeta());
172  }
173  }
174 
175  private static class ExpBetaPlanChangerForRemoval implements Provider<ExpBetaPlanChanger<Plan, Person>> {
176 
177  @Inject private ScoringConfigGroup config;
178 
179  @Override
181  return new ExpBetaPlanChanger<>( - config.getBrainExpBeta());
182  }
183  }
184 
185  private static class PathSizeLogitSelectorForRemoval implements Provider<PathSizeLogitSelector> {
186 
187  @Inject
189  @Inject Network network;
190 
191  @Override
192  public PathSizeLogitSelector get() {
193  return new PathSizeLogitSelector(config.getPathSizeLogitBeta(), -config.getBrainExpBeta(),
194  network);
195  }
196  }
197 
198 }
final com.google.inject.binder.LinkedBindingBuilder< PlanStrategy > addPlanStrategyBinding(String selectorName)
final com.google.inject.binder.LinkedBindingBuilder< PlanSelector< Plan, Person > > bindPlanSelectorForRemoval()
final ReplanningConfigGroup replanning()
Definition: Config.java:427
StrategySettings getStrategySettings(final Id< StrategySettings > index, final boolean createIfMissing)