MATSIM
RandomUnscoredPlanSelector.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 RandomUnscoredPlanSelector<T extends BasicPlan, I> implements PlanSelector<T, I> {
34 
39  @Override
40  public T selectPlan(final HasPlansAndId<T, I> person) {
41  // following code copied from PersonImpl and then made runnable
42 
43  int cntUnscored = 0;
44  for (T plan : person.getPlans()) {
45  if (plan.getScore() == null) {
46  cntUnscored++;
47  }
48  }
49  if (cntUnscored > 0) {
50  // select one of the unscored plans
51  int idxUnscored = MatsimRandom.getRandom().nextInt(cntUnscored);
52  cntUnscored = 0;
53  for (T plan : person.getPlans()) {
54  if (plan.getScore() == null) {
55  if (cntUnscored == idxUnscored) {
56  return plan;
57  }
58  cntUnscored++;
59  }
60  }
61  }
62  return null;
63  }
64 }
abstract List<? extends T > getPlans()