MATSIM
RandomPlanSelector.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * RandomPlanSelector.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 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 
21 package org.matsim.core.replanning.selectors;
22 
26 
27 
33 public class RandomPlanSelector<T extends BasicPlan, I> implements PlanSelector<T, I> {
34 
39  @Override
40  public T selectPlan(final HasPlansAndId<T, I> person) {
41  // this used to use person.getRandomPlan(), but I inlined the function here in order to get rid of the function of the data class.
42  // kai, nov'13
43  if (person.getPlans().size() == 0) {
44  return null;
45  }
46 
47  int index = (int)(MatsimRandom.getRandom().nextDouble()*person.getPlans().size());
48  // yyyy As far as I can tell, this produces race conditions when running multi-threaded. I.e. when running the same
49  // setup twice, this function may return different results per thread or per person. kai, jun'14
50 
51  return person.getPlans().get(index);
52  }
53 }
abstract List<? extends T > getPlans()