From f288e695297feee2f536ab6bac08a108e1ef0d92 Mon Sep 17 00:00:00 2001 From: awagner Date: Tue, 10 Oct 2023 14:07:51 +0200 Subject: [PATCH] added PlanInheritanceConfigGroup.java to en-/disable planInheritance, intialised planInheritance attributes != null bc planAttributes writer --- .../java/org/matsim/core/config/Config.java | 11 +++- .../groups/PlanInheritanceConfigGroup.java | 59 +++++++++++++++++++ .../replanning/GenericPlanStrategyImpl.java | 3 +- .../inheritance/PlanInheritanceModule.java | 8 ++- 4 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 matsim/src/main/java/org/matsim/core/config/groups/PlanInheritanceConfigGroup.java diff --git a/matsim/src/main/java/org/matsim/core/config/Config.java b/matsim/src/main/java/org/matsim/core/config/Config.java index ecff0be5678..a409e64d579 100644 --- a/matsim/src/main/java/org/matsim/core/config/Config.java +++ b/matsim/src/main/java/org/matsim/core/config/Config.java @@ -47,8 +47,7 @@ import org.matsim.core.config.groups.NetworkConfigGroup; import org.matsim.core.config.groups.ReplanningConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup; -import org.matsim.core.config.groups.RoutingConfigGroup; -import org.matsim.core.config.groups.PlansConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup;import org.matsim.core.config.groups.PlansConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.ScenarioConfigGroup; import org.matsim.core.config.groups.SubtourModeChoiceConfigGroup; @@ -123,7 +122,6 @@ public void addCoreModules() { this.modules.put(QSimConfigGroup.GROUP_NAME, new QSimConfigGroup()); this.modules.put(CountsConfigGroup.GROUP_NAME, new CountsConfigGroup()); - this.modules.put(ScoringConfigGroup.GROUP_NAME, new ScoringConfigGroup()); this.modules.put(NetworkConfigGroup.GROUP_NAME, new NetworkConfigGroup()); @@ -147,6 +145,7 @@ public void addCoreModules() { this.modules.put(TimeAllocationMutatorConfigGroup.GROUP_NAME, new TimeAllocationMutatorConfigGroup()); this.modules.put(VspExperimentalConfigGroup.GROUP_NAME, new VspExperimentalConfigGroup()); + this.modules.put(TransitConfigGroup.GROUP_NAME, new TransitConfigGroup()); @@ -168,6 +167,8 @@ public void addCoreModules() { this.modules.put(HermesConfigGroup.NAME, new HermesConfigGroup()); this.modules.put(ReplanningAnnealerConfigGroup.GROUP_NAME, new ReplanningAnnealerConfigGroup()); + + this.modules.put(PlanInheritanceConfigGroup.GROUP_NAME, new PlanInheritanceConfigGroup()); this.addConfigConsistencyChecker(new VspConfigConsistencyCheckerImpl()); this.addConfigConsistencyChecker(new UnmaterializedConfigGroupChecker()); @@ -488,6 +489,10 @@ public HermesConfigGroup hermes() { public ReplanningAnnealerConfigGroup replanningAnnealer() { return (ReplanningAnnealerConfigGroup) this.getModule(ReplanningAnnealerConfigGroup.GROUP_NAME); } + + public PlanInheritanceConfigGroup planInheritance() { + return (PlanInheritanceConfigGroup) this.getModule(PlanInheritanceConfigGroup.GROUP_NAME); + } // other: diff --git a/matsim/src/main/java/org/matsim/core/config/groups/PlanInheritanceConfigGroup.java b/matsim/src/main/java/org/matsim/core/config/groups/PlanInheritanceConfigGroup.java new file mode 100644 index 00000000000..922f2e37eb0 --- /dev/null +++ b/matsim/src/main/java/org/matsim/core/config/groups/PlanInheritanceConfigGroup.java @@ -0,0 +1,59 @@ +/* *********************************************************************** * + * project: org.matsim.* + * * + * *********************************************************************** * + * * + * copyright : (C) 2011 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.core.config.groups; + +import java.util.Map; + +import org.matsim.core.config.ReflectiveConfigGroup; + +/** + * @author awagner + */ +public final class PlanInheritanceConfigGroup extends ReflectiveConfigGroup { + + public static final String GROUP_NAME = "planInheritance"; + + private static final String ENABLED = "enabled"; + + private boolean enabled = false; + + public PlanInheritanceConfigGroup() { + super(GROUP_NAME); + } + + @Override + public Map getComments() { + Map comments = super.getComments(); + comments.put(ENABLED, "Specifies whether or not PlanInheritance Information should be tracked."); + return comments; + } + + + @StringSetter( ENABLED ) + public void setWriteLinkStatsInterval(boolean enabled) { + this.enabled = enabled; + } + + + @StringGetter( ENABLED ) + public boolean getEnabled() { + return this.enabled; + } +} diff --git a/matsim/src/main/java/org/matsim/core/replanning/GenericPlanStrategyImpl.java b/matsim/src/main/java/org/matsim/core/replanning/GenericPlanStrategyImpl.java index 341e32d1ca6..75daefffb28 100644 --- a/matsim/src/main/java/org/matsim/core/replanning/GenericPlanStrategyImpl.java +++ b/matsim/src/main/java/org/matsim/core/replanning/GenericPlanStrategyImpl.java @@ -93,7 +93,8 @@ public void run(final HasPlansAndId person) { // set the working plan to a copy of the selected plan: plan = person.createCopyOfSelectedPlanAndMakeSelected(); - if (plan instanceof Plan) { + //planId is only set inside planInheritance -> if null planInheritance is disabled + if (plan instanceof Plan && ((Plan) plan).getPlanId() != null) { // add plan inheritance flags ((Plan) plan).setIterationCreated(this.replanningContext.getIteration()); ((Plan) plan).setPlanMutator(this.toString()); diff --git a/matsim/src/main/java/org/matsim/core/replanning/inheritance/PlanInheritanceModule.java b/matsim/src/main/java/org/matsim/core/replanning/inheritance/PlanInheritanceModule.java index c16514a4ecc..c400c04b234 100644 --- a/matsim/src/main/java/org/matsim/core/replanning/inheritance/PlanInheritanceModule.java +++ b/matsim/src/main/java/org/matsim/core/replanning/inheritance/PlanInheritanceModule.java @@ -36,6 +36,7 @@ import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Plan; import org.matsim.core.config.groups.ControlerConfigGroup.CompressionType; +import org.matsim.core.config.groups.PlanInheritanceConfigGroup; import org.matsim.core.config.groups.StrategyConfigGroup.StrategySettings; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.events.BeforeMobsimEvent; @@ -47,6 +48,7 @@ import org.matsim.core.population.PersonUtils; import org.matsim.core.replanning.GenericPlanStrategy; import org.matsim.core.replanning.StrategyManager; +import org.matsim.core.replanning.annealing.ReplanningAnnealerConfigGroup; import org.matsim.core.utils.io.IOUtils; import com.google.inject.Singleton; @@ -92,8 +94,8 @@ public void notifyStartup(StartupEvent event) { // reset all plan attributes that might be present from a previously performed matsim run for (Person person : event.getServices().getScenario().getPopulation().getPersons().values()) { for (Plan plan : person.getPlans()) { - plan.setPlanId(null); - plan.setPlanMutator(null); + plan.setPlanId(Long.toString(0, 36)); + plan.setPlanMutator(INITIAL_PLAN); plan.setIterationCreated(0); } } @@ -262,6 +264,6 @@ public void notifyShutdown(ShutdownEvent event) { @Override public void install() { - addControlerListenerBinding().to(PlanInheritanceModule.class); + if (getConfig().planInheritance().getEnabled()) addControlerListenerBinding().to(PlanInheritanceModule.class); } }