MATSIM
BestPlanSelector.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * BestPlanSelector.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 
25 
31 public class BestPlanSelector<T extends BasicPlan, I> implements PlanSelector<T, I> {
32 
36  @Override
37  public T selectPlan(final HasPlansAndId<T, I> person) {
38 
39  double maxScore = Double.NEGATIVE_INFINITY;
40  T bestPlan = null;
41 
42  for (T plan : person.getPlans()) {
43  Double score = plan.getScore();
44  if ((score != null) && (score.doubleValue() > maxScore) && !score.isNaN() ) {
45  maxScore = plan.getScore().doubleValue();
46  bestPlan = plan;
47  }
48  }
49 
50  if (bestPlan == null && person.getPlans().size() > 0) {
51  // it seems none of the plans has a real score... so just return the first one (if there is one)
52  return person.getPlans().get(0);
53  }
54  return bestPlan;
55  }
56 
57 }
T selectPlan(final HasPlansAndId< T, I > person)
abstract List<? extends T > getPlans()