MATSIM
Classes | Functions
Package org.matsim.core.replanning.modules

Classes

class  AbstractMultithreadedModule
 
class  ChangeLegMode
 
class  ChangeSingleLegMode
 
class  ExceptionHandler
 
interface  GenericPlanStrategyModule
 
class  KeepLastExecuted
 
class  ModeAndRouteConsistencyChecker
 
class  PlanAlgoThread
 
class  ReRoute
 
class  SubtourModeChoice
 
class  TripsToLegsModule
 

Functions

final void prepareReplanning (ReplanningContext replanningContextTmp)
 
final ReplanningContext getReplanningContext ()
 
final void handlePlan (final Plan plan)
 
void beforeFinishReplanningHook ()
 
void afterFinishReplanningHook ()
 
final void finishReplanning ()
 
void initThreads ()
 

Function Documentation

◆ prepareReplanning()

final void org.matsim.core.replanning.modules.prepareReplanning ( ReplanningContext  replanningContextTmp)

Definition at line 101 of file AbstractMultithreadedModule.java.

References org.matsim.core.replanning.modules.AbstractMultithreadedModule.directAlgo, org.matsim.core.replanning.modules.AbstractMultithreadedModule.getPlanAlgoInstance(), org.matsim.core.replanning.modules.initThreads(), org.matsim.core.replanning.modules.AbstractMultithreadedModule.numOfThreads, and org.matsim.core.replanning.modules.AbstractMultithreadedModule.replanningContext.

101  {
102  this.beforePrepareReplanningHook(replanningContextTmp);
103  this.replanningContext = replanningContextTmp;
104  if (this.numOfThreads == 0) {
105  // it seems, no threads are desired :(
106  this.directAlgo = getPlanAlgoInstance();
107  } else {
108  initThreads();
109  }
110  this.afterPrepareReplanningHook(replanningContextTmp);
111  }
Here is the call graph for this function:

◆ getReplanningContext()

final ReplanningContext org.matsim.core.replanning.modules.getReplanningContext ( )
protected

Definition at line 113 of file AbstractMultithreadedModule.java.

References org.matsim.core.replanning.modules.AbstractMultithreadedModule.replanningContext.

113  {
114  return replanningContext;
115  }

◆ handlePlan()

final void org.matsim.core.replanning.modules.handlePlan ( final Plan  plan)

Definition at line 118 of file AbstractMultithreadedModule.java.

References org.matsim.core.replanning.modules.PlanAlgoThread.addPlanToThread(), org.matsim.core.replanning.modules.AbstractMultithreadedModule.algothreads, org.matsim.core.replanning.modules.AbstractMultithreadedModule.count, org.matsim.core.replanning.modules.AbstractMultithreadedModule.directAlgo, org.matsim.core.replanning.modules.AbstractMultithreadedModule.numOfThreads, and org.matsim.core.population.algorithms.PlanAlgorithm.run().

118  {
119  if (this.directAlgo == null) {
120  this.algothreads[this.count % this.numOfThreads].addPlanToThread(plan);
121  this.count++;
122  } else {
123  this.directAlgo.run(plan);
124  }
125  }
Here is the call graph for this function:

◆ beforeFinishReplanningHook()

void org.matsim.core.replanning.modules.beforeFinishReplanningHook ( )
protected

Definition at line 127 of file AbstractMultithreadedModule.java.

Referenced by org.matsim.core.replanning.modules.finishReplanning().

127  {
128  // left empty for inheritance
129  }

◆ afterFinishReplanningHook()

void org.matsim.core.replanning.modules.afterFinishReplanningHook ( )
protected

Definition at line 130 of file AbstractMultithreadedModule.java.

130  {
131  // left empty for inheritance
132  }

◆ finishReplanning()

final void org.matsim.core.replanning.modules.finishReplanning ( )

Definition at line 135 of file AbstractMultithreadedModule.java.

References org.matsim.core.replanning.modules.beforeFinishReplanningHook(), org.matsim.core.replanning.modules.AbstractMultithreadedModule.directAlgo, org.matsim.core.replanning.modules.AbstractMultithreadedModule.log, org.matsim.core.replanning.modules.AbstractMultithreadedModule.name, and org.matsim.core.replanning.modules.AbstractMultithreadedModule.threads.

135  {
137 
138  if (this.directAlgo == null) {
139  // only try to start threads if we did not directly work on all the plans
140  log.info("[" + this.name + "] starting " + this.threads.length + " threads, handling " + this.count + " plans");
141 
142  // start threads
143  for (Thread thread : this.threads) {
144  thread.start();
145  }
146 
147  // wait until each thread is finished
148  try {
149  for (Thread thread : this.threads) {
150  thread.join();
151  }
152  } catch (InterruptedException e) {
153  throw new RuntimeException(e);
154  }
155  log.info("[" + this.name + "] all " + this.threads.length + " threads finished.");
156  Throwable throwable = this.hadException.get();
157  if (throwable != null) {
158  throw new RuntimeException("Some threads crashed, thus not all plans may have been handled.", throwable);
159  }
160  }
161  // reset
162  this.algothreads = null;
163  this.threads = null;
164  this.replanningContext = null;
165  this.count = 0;
166 
168  }
Here is the call graph for this function:

◆ initThreads()

void org.matsim.core.replanning.modules.initThreads ( )
private

Definition at line 170 of file AbstractMultithreadedModule.java.

References org.matsim.core.replanning.modules.AbstractMultithreadedModule.threads.

Referenced by org.matsim.core.replanning.modules.prepareReplanning().

170  {
171  if (this.threads != null) {
172  throw new RuntimeException("threads are already initialized");
173  }
174 
175  this.hadException.set(null);
176  this.threads = new Thread[this.numOfThreads];
177  this.algothreads = new PlanAlgoThread[this.numOfThreads];
178 
179  Counter counter = null;
180  // setup threads
181  for (int i = 0; i < this.numOfThreads; i++) {
182  PlanAlgorithm algo = getPlanAlgoInstance();
183  if (i == 0) {
184  this.name = algo.getClass().getSimpleName();
185  counter = new Counter("[" + this.name + "] handled plan # ");
186  }
187  PlanAlgoThread algothread = new PlanAlgoThread(algo, counter);
188  Thread thread = new Thread(algothread, this.name + "." + i);
189  thread.setUncaughtExceptionHandler(this.exceptionHandler);
190  this.threads[i] = thread;
191  this.algothreads[i] = algothread;
192  }
193  }