Skip to content

Commit

Permalink
refactor Config Renames, default Iteration removed changed to -1
Browse files Browse the repository at this point in the history
  • Loading branch information
awagner committed Oct 13, 2023
1 parent 78532cf commit bae280b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions matsim/src/main/java/org/matsim/core/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ public void setType(final String type) {
public Id<Plan> getId() {
if(this.id!=null)
return this.id;
else return Id.create(this.getAttributes().getAttribute(PlanInheritanceModule.PLAN_ID).toString(),Plan.class);
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import org.matsim.api.core.v01.Id;
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.StrategyConfigGroup.StrategySettings;
import org.matsim.core.config.groups.ControllerConfigGroup.CompressionType;
import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.events.BeforeMobsimEvent;
import org.matsim.core.controler.events.ShutdownEvent;
Expand Down Expand Up @@ -85,9 +85,9 @@ public class PlanInheritanceModule extends AbstractModule implements StartupList
@Override
public void notifyStartup(StartupEvent event) {
// initialize all default writers
CompressionType compressionType = event.getServices().getConfig().controler().getCompressionType();
CompressionType compressionType = event.getServices().getConfig().controller().getCompressionType();
this.planInheritanceRecordWriter = new PlanInheritanceRecordWriter(event.getServices().getControlerIO().getOutputFilename(FILENAME_PLAN_INHERITANCE_RECORDS + ".csv", compressionType));
this.strategies = this.getActiveStrategies(event.getServices().getConfig().strategy().getStrategySettings(), event.getServices().getStrategyManager());
this.strategies = this.getActiveStrategies(event.getServices().getConfig().replanning().getStrategySettings(), event.getServices().getStrategyManager());
this.selectedPlanStrategyShareWriter = this.initializeDistributionWriter(this.strategies, event.getServices().getControlerIO().getOutputFilename(FILENAME_PLAN_INHERITANCE_RECORDS + "_shares_selected.csv"));
this.planStrategyShareWriter = this.initializeDistributionWriter(this.strategies, event.getServices().getControlerIO().getOutputFilename(FILENAME_PLAN_INHERITANCE_RECORDS + "_shares.csv"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PlanInheritanceRecord {
/**
* Iteration in which the plan had been removed from the choice-set.
*/
private int iterationRemoved;
private int iterationRemoved = -1;

/**
* Collection of iterations this plan had been the selected plan.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void testPlanInheritanceEnabled() throws IOException {
String outputDirectory = util.getOutputDirectory();

Config config = this.util.loadConfig("test/scenarios/equil/config_plans1.xml");
config.controler().setLastIteration(10);
config.controler().setOutputDirectory(outputDirectory);
config.controller().setLastIteration(10);
config.controller().setOutputDirectory(outputDirectory);
config.planInheritance().setEnabled(true);
Controler c = new Controler(config);

Expand Down Expand Up @@ -76,15 +76,15 @@ public void run(Person person) {
assert( ((PlanInheritanceRecord) records.get(0)).getAncestorId().equals(Id.create("NONE",Plan.class)));
assert( ((PlanInheritanceRecord) records.get(0)).getMutatedBy().equals(PlanInheritanceModule.INITIAL_PLAN));
assert( ((PlanInheritanceRecord) records.get(0)).getIterationCreated() == 0);
assert( ((PlanInheritanceRecord) records.get(0)).getIterationRemoved() == 0);
assert( ((PlanInheritanceRecord) records.get(0)).getIterationRemoved() == -1);
assert( ((PlanInheritanceRecord) records.get(0)).getPlanId().equals(Id.create("1",Plan.class)));
assert( ((PlanInheritanceRecord) records.get(0)).getIterationsSelected().equals(Arrays.asList(0, 1, 2, 3, 4, 6, 7, 8, 9, 10)));

assert( ((PlanInheritanceRecord) records.get(1)).getAgentId().equals(Id.createPersonId("1")));
assert( ((PlanInheritanceRecord) records.get(1)).getAncestorId().equals(Id.create("1",Plan.class)));
assert( ((PlanInheritanceRecord) records.get(1)).getMutatedBy().equals("RandomPlanSelector_ReRoute"));
assert( ((PlanInheritanceRecord) records.get(1)).getIterationCreated() == 5);
assert( ((PlanInheritanceRecord) records.get(1)).getIterationRemoved() == 0);
assert( ((PlanInheritanceRecord) records.get(1)).getIterationRemoved() == -1);
assert( ((PlanInheritanceRecord) records.get(1)).getPlanId().equals(Id.create("2",Plan.class)));
assert( ((PlanInheritanceRecord) records.get(1)).getIterationsSelected().equals(Arrays.asList(5)));

Expand All @@ -97,8 +97,8 @@ public void testPlanInheritanceDisabled() throws IOException {
String outputDirectory = util.getOutputDirectory();

Config config = this.util.loadConfig("test/scenarios/equil/config_plans1.xml");
config.controler().setLastIteration(1);
config.controler().setOutputDirectory(outputDirectory);
config.controller().setLastIteration(1);
config.controller().setOutputDirectory(outputDirectory);
Controler c = new Controler(config);

c.run();
Expand Down

0 comments on commit bae280b

Please sign in to comment.