MATSIM
ReplanningUtils.java
Go to the documentation of this file.
1 /*
2  * *********************************************************************** *
3  * * project: org.matsim.*
4  * * PlanStrategies.java
5  * * *
6  * * *********************************************************************** *
7  * * *
8  * * copyright : (C) 2014 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;
24 
25 import javax.annotation.Nullable;
26 
30 
31 public final class ReplanningUtils {
32 
33  static public final String INITIAl_PLAN_ATTRIBUTE = "isInitialPlan";
34 
35  public static boolean isInitialPlan(Plan plan) {
36  Boolean isInitialPlan = (Boolean) plan.getAttributes().getAttribute(INITIAl_PLAN_ATTRIBUTE);
37  return isInitialPlan != null && isInitialPlan;
38  }
39 
40  @Nullable
41  public static Plan getInitialPlan(Person person) {
42  for (Plan plan : person.getPlans()) {
43  if (isInitialPlan(plan)) {
44  return plan;
45  }
46  }
47 
48  return null;
49  }
50 
51  public static void setInitialPlan(Person person) {
52  person.getPlans().forEach(plan -> plan.getAttributes().removeAttribute(INITIAl_PLAN_ATTRIBUTE));
53  person.getSelectedPlan().getAttributes().putAttribute(INITIAl_PLAN_ATTRIBUTE, true);
54  }
55 
59  public static <P extends BasicPlan, R> boolean isInnovativeStrategy(GenericPlanStrategy<P, R> planStrategy) {
60  return !isOnlySelector(planStrategy);
61  }
62 
63  public static <P extends BasicPlan, R> boolean isOnlySelector(GenericPlanStrategy<P, R> planStrategy) {
64  if (planStrategy instanceof PlanStrategyImpl) {
65  return ((PlanStrategyImpl) planStrategy).getNumberOfStrategyModules() == 0;
66  }
67  return false;
68  }
69 
70 }
static< P extends BasicPlan, R > boolean isOnlySelector(GenericPlanStrategy< P, R > planStrategy)
static< P extends BasicPlan, R > boolean isInnovativeStrategy(GenericPlanStrategy< P, R > planStrategy)
abstract List<? extends T > getPlans()