Skip to content

Commit

Permalink
added PlanInheritanceConfigGroup.java to en-/disable planInheritance,…
Browse files Browse the repository at this point in the history
… intialised planInheritance attributes != null bc planAttributes writer
  • Loading branch information
awagner committed Oct 13, 2023
1 parent f302b4b commit f288e69
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
11 changes: 8 additions & 3 deletions matsim/src/main/java/org/matsim/core/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());

Expand All @@ -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());
Expand Down Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> getComments() {
Map<String, String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public void run(final HasPlansAndId<T, I> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f288e69

Please sign in to comment.