Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding plan inheritance #2831

Merged
merged 10 commits into from
Oct 16, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg;
Expand Down Expand Up @@ -158,6 +159,36 @@ public String getType() {
public void setType(String type) {
throw new UnsupportedOperationException();
}

@Override
public int getIterationCreated() {
throw new UnsupportedOperationException();
}

@Override
public void setIterationCreated(int iteration) {
throw new UnsupportedOperationException();
}

@Override
public Id<Plan> getId() {
throw new UnsupportedOperationException();
}

@Override
public void setPlanId(Id<Plan> planId) {
throw new UnsupportedOperationException();
}

@Override
public String getPlanMutator() {
throw new UnsupportedOperationException();
}

@Override
public void setPlanMutator(String planMutator) {
throw new UnsupportedOperationException();
}

@Override
public void setScore(Double score) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,35 @@ else if (planElement instanceof Leg) {
destPlan.score = srcPlan.getScore();
}

@Override
public void setPlanId(Id<Plan> planId) {
throw new UnsupportedOperationException();

}

@Override
public Id<Plan> getId() {
throw new UnsupportedOperationException();
}

@Override
public int getIterationCreated() {
throw new UnsupportedOperationException();
}

@Override
public void setIterationCreated(int iteration) {
throw new UnsupportedOperationException();
}

@Override
public String getPlanMutator() {
throw new UnsupportedOperationException();
}

@Override
public void setPlanMutator(String planMutator) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,24 @@ public String getType() {
public void setType(final String type) {
this.type = type;
}

@Override
public Id<Plan> getId() { return null; }

@Override
public void setPlanId(Id<Plan> planId) { /* nothing to do here */ }

@Override
public int getIterationCreated() { return -1; }

@Override
public void setIterationCreated(int iteration) { /* nothing to do here */ }

@Override
public String getPlanMutator() { return null; }

@Override
public void setPlanMutator(String planMutator) { /* nothing to do here */ }

@Override
public final List<PlanElement> getPlanElements() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person;
Expand Down Expand Up @@ -172,6 +173,24 @@ public String getType() {
public void setType(String type) {
this.delegate.setType(type);
}

@Override
public Id<Plan> getId() { return null; }

@Override
public void setPlanId(Id<Plan> planId) { /* nothing to do here */ }

@Override
public int getIterationCreated() { return -1; }

@Override
public void setIterationCreated(int iteration) { /* nothing to do here */ }

@Override
public String getPlanMutator() { return null; }

@Override
public void setPlanMutator(String planMutator) { /* nothing to do here */ }

@Override
public Person getPerson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.List;

import org.matsim.api.core.v01.Customizable;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Identifiable;
import org.matsim.core.api.internal.MatsimPopulationObject;
import org.matsim.utils.objectattributes.attributable.Attributable;

Expand All @@ -34,7 +36,7 @@
* The only thing which is not "expected" in the same sense is the score.
*
*/
public interface Plan extends MatsimPopulationObject, Customizable, BasicPlan, Attributable {
public interface Plan extends MatsimPopulationObject, Customizable, BasicPlan, Attributable, Identifiable<Plan> {

public abstract List<PlanElement> getPlanElements();

Expand All @@ -49,6 +51,18 @@ public interface Plan extends MatsimPopulationObject, Customizable, BasicPlan, A
public abstract String getType();

public abstract void setType(final String type);

public abstract void setPlanId(Id<Plan> planId);

public abstract Id<Plan> getId();

public abstract int getIterationCreated();

public abstract void setIterationCreated(int iteration);

public abstract String getPlanMutator();

public abstract void setPlanMutator(String planMutator);

public abstract Person getPerson();

Expand All @@ -59,5 +73,6 @@ public interface Plan extends MatsimPopulationObject, Customizable, BasicPlan, A
* you are using this method!.
*/
public abstract void setPerson(Person person);


}
12 changes: 9 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 @@ -45,10 +45,10 @@
import org.matsim.core.config.groups.HouseholdsConfigGroup;
import org.matsim.core.config.groups.LinkStatsConfigGroup;
import org.matsim.core.config.groups.NetworkConfigGroup;
import org.matsim.core.config.groups.PlanInheritanceConfigGroup;
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 +123,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 +146,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 +168,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 +490,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 setEnabled(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 @@ -37,6 +37,7 @@
import org.matsim.core.population.VspPlansCleanerModule;
import org.matsim.core.replanning.StrategyManagerModule;
import org.matsim.core.replanning.annealing.ReplanningAnnealer;
import org.matsim.core.replanning.inheritance.PlanInheritanceModule;
import org.matsim.core.router.TripRouterModule;
import org.matsim.core.router.costcalculators.TravelDisutilityModule;
import org.matsim.core.scoring.functions.CharyparNagelScoringFunctionModule;
Expand Down Expand Up @@ -76,6 +77,7 @@ public void install() {
install(new VspPlansCleanerModule());
install(new SnapshotWritersModule());
install(new DependencyGraphModule());
install(new PlanInheritanceModule());

// Comment by Tarek Chouaki.
// To make sure the cache files used under ChartUtils are located in tmp folder in the output directory
Expand Down
45 changes: 45 additions & 0 deletions matsim/src/main/java/org/matsim/core/population/PlanImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Customizable;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.core.replanning.inheritance.PlanInheritanceModule;
import org.matsim.core.scenario.CustomizableUtils;
import org.matsim.utils.objectattributes.attributable.Attributes;
import org.matsim.utils.objectattributes.attributable.AttributesImpl;

/* deliberately package */ final class PlanImpl implements Plan {

private Id<Plan> id= null;

private ArrayList<PlanElement> actsLegs = new ArrayList<>();

private Double score = null;
Expand Down Expand Up @@ -121,6 +126,44 @@ public String getType() {
public void setType(final String type) {
this.type = type;
}

@Override
public Id<Plan> getId() {
if(this.id!=null)
return this.id;
else {
if(this.getAttributes().getAttribute(PlanInheritanceModule.PLAN_ID)!=null)
return Id.create(this.getAttributes().getAttribute(PlanInheritanceModule.PLAN_ID).toString(),Plan.class);
else return null;
}

}

@Override
public void setPlanId(Id<Plan> planId) {
this.getAttributes().putAttribute(PlanInheritanceModule.PLAN_ID, planId.toString());
this.id = planId;
}

@Override
public int getIterationCreated() {
return (int) this.getAttributes().getAttribute(PlanInheritanceModule.ITERATION_CREATED);
}

@Override
public void setIterationCreated(int iteration) {
this.getAttributes().putAttribute(PlanInheritanceModule.ITERATION_CREATED, iteration);
}

@Override
public String getPlanMutator() {
return (String) this.getAttributes().getAttribute(PlanInheritanceModule.PLAN_MUTATOR);
}

@Override
public void setPlanMutator(String planMutator) {
this.getAttributes().putAttribute(PlanInheritanceModule.PLAN_MUTATOR, planMutator);
}

@Override
public final List<PlanElement> getPlanElements() {
Expand Down Expand Up @@ -164,6 +207,8 @@ public final Map<String, Object> getCustomAttributes() {
return this.customizableDelegate.getCustomAttributes();
}



// public final void setLocked() {
// for ( PlanElement pe : this.actsLegs ) {
// if ( pe instanceof ActivityImpl ) {
Expand Down
Loading
Loading