Skip to content

Commit

Permalink
Merge branch 'master' into person-vehicle-types
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow authored Oct 16, 2023
2 parents 33d6689 + 3d665b5 commit 8e37029
Show file tree
Hide file tree
Showing 22 changed files with 920 additions and 1,425 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public void install() {

controller.run();

assertEquals(44196, (int) listener.counts.get("pt"));

System.out.println((int) listener.counts.get("pt"));
System.out.println((int) listener.counts.get("car"));
System.out.println(listener.counts.get("walk"));

assertEquals(44195, (int) listener.counts.get("pt"));
assertEquals(132316, (int) listener.counts.get("car"));
assertEquals(82140, (int) listener.counts.get("walk"));
// assertEquals(42520, (int) listener.counts.get("pt"));
// assertEquals(132100, (int) listener.counts.get("car"));
// assertEquals(79106, (int) listener.counts.get("walk"));
// ...setConstrainedModes(...) (inside configureAsSubtourModeChoiceReplacement(...)) used to ignore its arguments because of a typo.
// This is now corrected, but results are no longer backwards compatible. kai, jan'23
assertEquals(82139, (int) listener.counts.get("walk"));

}

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

package org.matsim.contrib.pseudosimulation;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Assert;
Expand All @@ -29,15 +25,18 @@
import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
import org.matsim.pt.config.TransitConfigGroup.TransitRoutingAlgorithmType;
import org.matsim.testcases.MatsimTestUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RunPSimTest {
@Rule
public MatsimTestUtils utils = new MatsimTestUtils();

private Logger logger = LogManager.getLogger(RunPSimTest.class );
private final Logger logger = LogManager.getLogger(RunPSimTest.class );

private final Config config = ConfigUtils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-tutorial" ),"0.config.xml" ) );

Expand All @@ -57,10 +56,7 @@ public void testA() {
//identify selector strategies
Field[] selectors = DefaultPlanStrategiesModule.DefaultSelector.class.getDeclaredFields();
List<String> selectorNames = new ArrayList<>();
// for (Field selector : selectors) {
// selectorNames.add(selector.toString());
// logger.warn( selector.toString() );
// }

// yyyyyy does not work as designed
selectorNames.add( DefaultPlanStrategiesModule.DefaultSelector.ChangeExpBeta );
selectorNames.add( DefaultPlanStrategiesModule.DefaultSelector.BestScore );
Expand Down Expand Up @@ -107,7 +103,8 @@ public void install() {
Population popActual = PopulationUtils.createPopulation( config );
PopulationUtils.readPopulation( popActual, outDir + "/output_plans.xml.gz" );
new PopulationComparison().compare( popExpected, popActual ) ;
Assert.assertEquals("RunPsim score changed.", 138.88788052033888, psimScore, MatsimTestUtils.EPSILON);
Assert.assertEquals("RunPsim score changed.", 138.86084460860525, psimScore, MatsimTestUtils.EPSILON);

}

/**
Expand All @@ -130,8 +127,9 @@ public void testB() {
controler.run();

double qsimScore = execScoreTracker.executedScore;
logger.info("Default controller score was " + qsimScore );
Assert.assertEquals("Default controller score changed.", 131.85545404187428, qsimScore, MatsimTestUtils.EPSILON);
logger.info("Default controler score was " + qsimScore );
// Assert.assertEquals("Default controler score changed.", 131.84309487251033d, qsimScore, MatsimTestUtils.EPSILON);
Assert.assertEquals("Default controler score changed.", 131.8303325803256, qsimScore, MatsimTestUtils.EPSILON);
}

class ExecScoreTracker implements ShutdownListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ public final void test() throws UncheckedIOException, ConfigurationException, UR

OutputData data = countLegs(controller.getControlerIO().getOutputPath() + "/output_events.xml.gz");

Assert.assertEquals(82689, (long) data.counts.get("car"));
Assert.assertEquals(29890, (long) data.counts.get("walk"));
Assert.assertEquals(30, (long) data.counts.get("bike"));
Assert.assertEquals(19115, (long) data.counts.get("pt"));
Assert.assertEquals(82629, (long) data.counts.get("car"));
Assert.assertEquals(29739, (long) data.counts.get("walk"));
Assert.assertEquals(31, (long) data.counts.get("bike"));
Assert.assertEquals(19029, (long) data.counts.get("pt"));

Assert.assertEquals(21, (long) data.pickupCounts.get("wheels"));
Assert.assertEquals(2, (long) data.pickupCounts.get("mobility"));
Assert.assertEquals(9, (long) data.pickupCounts.get("velib"));
Assert.assertEquals(10, (long) data.pickupCounts.get("velib"));

Assert.assertEquals(21, (long) data.dropoffCounts.get("wheels"));
Assert.assertEquals(0, (long) data.dropoffCounts.getOrDefault("mobility", 0L));
Assert.assertEquals(9, (long) data.dropoffCounts.get("velib"));
Assert.assertEquals(10, (long) data.dropoffCounts.get("velib"));

Assert.assertEquals(0, (long) data.failedPickupCounts.getOrDefault("wheels",0L));
Assert.assertEquals(0, (long) data.failedPickupCounts.getOrDefault("mobility",0L));
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@

import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ReflectiveConfigGroup;
import org.matsim.core.utils.misc.Time;

public final class TimeAllocationMutatorConfigGroup extends ReflectiveConfigGroup {

public static final String GROUP_NAME = "timeAllocationMutator";


public TimeAllocationMutatorConfigGroup() {
super(GROUP_NAME);
}
Expand All @@ -39,15 +41,49 @@ public Map<String, String> getComments() {
Map<String, String> comments = super.getComments();
comments.put(MUTATION_RANGE, "Default:1800.0; Defines how many seconds a time mutation can maximally shift a time.");
comments.put(MUTATION_AFFECTS_DURATION, "Default:true; Defines whether time mutation changes an activity's duration.");
comments.put(USE_INDIVIDUAL_SETTINGS_FOR_SUBPOPULATIONS, "false; Use individual settings for each subpopulation. "
+ "If enabled but no settings are found, regular settings are uses as fallback.");
comments.put(LATEST_ACTIVITY_END_TIME,"Latest Activity End Time. Default = 24:00:00");
comments.put(MUTATION_RANGE_STEP,"Mutation Range Step, default = 1 second");
comments.put(MUTATE_AROUND_INITIAL_END_TIME_ONLY,"Mutates times only around the initially defined end times.");
return comments;
}

// ---

private static final String LATEST_ACTIVITY_END_TIME = "latestActivityEndTime";
private static final String MUTATE_AROUND_INITIAL_END_TIME_ONLY = "mutateAroundInitialEndTimeOnly";
private static final String MUTATION_RANGE_STEP = "mutationRangeStep";
private static final String MUTATION_RANGE = "mutationRange";
private double mutationRange = 1800.0;
private double latestActivityEndTime = 24*3600.0;
private boolean mutateAroundInitialEndTimeOnly = false;
private double mutationRangeStep = 1.0;

@StringGetter(MUTATION_RANGE_STEP)
public double getMutationRangeStep() {
return mutationRangeStep;
}
@StringSetter(MUTATION_RANGE_STEP)
public void setMutationRangeStep(double mutationRangeStep) {
this.mutationRangeStep = mutationRangeStep;
}
@StringGetter(LATEST_ACTIVITY_END_TIME)
public double getLatestActivityEndTime() {
return latestActivityEndTime;
}
@StringSetter(LATEST_ACTIVITY_END_TIME)
public void setLatestActivityEndTime(String latestActivityEndTime) {
this.latestActivityEndTime = Time.parseTime(latestActivityEndTime);
}

@StringGetter(MUTATE_AROUND_INITIAL_END_TIME_ONLY)
public boolean isMutateAroundInitialEndTimeOnly() {
return mutateAroundInitialEndTimeOnly;
}
@StringSetter(MUTATE_AROUND_INITIAL_END_TIME_ONLY)
public void setMutateAroundInitialEndTimeOnly(boolean mutateAroundInitialEndTimeOnly) {
this.mutateAroundInitialEndTimeOnly = mutateAroundInitialEndTimeOnly;
}

@StringGetter(MUTATION_RANGE)
public double getMutationRange() {
return this.mutationRange;
Expand All @@ -71,112 +107,4 @@ public void setAffectingDuration(boolean affectingDuration) {
}

// ---

private static final String USE_INDIVIDUAL_SETTINGS_FOR_SUBPOPULATIONS = "useIndividualSettingsForSubpopulations";
private boolean useIndividualSettingsForSubpopulations = false;
// @StringGetter(USE_INDIVIDUAL_SETTINGS_FOR_SUBPOPULATIONS) // I am disabling the xml usage for the time being, see comment below. kai, may'19
public boolean isUseIndividualSettingsForSubpopulations() {
// yyyy is it really so plausible to have this? If we continue in this direction, we will eventually have the PTV behaviorally homogeneous
// groups. I would find it more natural to have behavior that depends continuously on person type, and then use Java in order to define that
// behaviour. Rather than to overload the config mechanism. kai, may'19
return this.useIndividualSettingsForSubpopulations;
}
// @StringSetter(USE_INDIVIDUAL_SETTINGS_FOR_SUBPOPULATIONS) // I am disabling the xml usage for the time being, see comments. kai, may'19
public void setUseIndividualSettingsForSubpopulations(boolean useIndividualSettingsForSubpopulations) {
// yyyy see comment under isUseIndividualSettingsForSubpopulations. kai, may'10
this.useIndividualSettingsForSubpopulations = useIndividualSettingsForSubpopulations;
}

// ---

public TimeAllocationMutatorSubpopulationSettings getTimeAllocationMutatorSubpopulationSettings(String subpopulation) {

if (subpopulation == null) return null;

Collection<? extends ConfigGroup> configGroups = this.getParameterSets(TimeAllocationMutatorSubpopulationSettings.SET_NAME);
for (ConfigGroup group : configGroups) {
if (group instanceof TimeAllocationMutatorSubpopulationSettings) {
TimeAllocationMutatorSubpopulationSettings subpopulationSettings = (TimeAllocationMutatorSubpopulationSettings) group;
if (subpopulation.equals(subpopulationSettings.subpopulation)) return subpopulationSettings;
}
}

return null;
}

@Override
public ConfigGroup createParameterSet(final String type) {
switch (type) {
case TimeAllocationMutatorSubpopulationSettings.SET_NAME:
return new TimeAllocationMutatorSubpopulationSettings();
default:
throw new IllegalArgumentException("unknown set type '" + type + "'");
}
}

@Override
public void addParameterSet(final ConfigGroup set) {
switch (set.getName()) {
case TimeAllocationMutatorSubpopulationSettings.SET_NAME:
super.addParameterSet(set);
break;
default:
throw new IllegalArgumentException( set.getName() );
}
}

public static class TimeAllocationMutatorSubpopulationSettings extends ReflectiveConfigGroup {

public static final String SET_NAME = "subpopulationSettings";
private static final String MUTATION_RANGE = "mutationRange";
private static final String MUTATION_AFFECTS_DURATION = "mutationAffectsDuration";
private static final String SUBPOPULATION = "subpopulation";

private double mutationRange = 1800.0;
private boolean affectingDuration = true;
private String subpopulation = null;

public TimeAllocationMutatorSubpopulationSettings() {
super(SET_NAME);
}

@Override
public final Map<String, String> getComments() {
Map<String,String> comments = super.getComments();
comments.put(MUTATION_RANGE, "Default:1800.0; Defines how many seconds a time mutation can maximally shift a time.");
comments.put(MUTATION_AFFECTS_DURATION, "Default:true; Defines whether time mutation changes an activity's duration.");
comments.put(SUBPOPULATION, "Subpopulation to which the values from this parameter set are applied.");
return comments;
}

@StringGetter(MUTATION_RANGE)
public double getMutationRange() {
return this.mutationRange;
}

@StringSetter(MUTATION_RANGE)
public void setMutationRange(final double val) {
this.mutationRange = val;
}

@StringGetter(MUTATION_AFFECTS_DURATION)
public boolean isAffectingDuration() {
return affectingDuration;
}

@StringSetter(MUTATION_AFFECTS_DURATION)
public void setAffectingDuration(boolean affectingDuration) {
this.affectingDuration = affectingDuration;
}

@StringSetter(SUBPOPULATION)
public void setSubpopulation(final String subpopulation) {
this.subpopulation = subpopulation;
}

@StringGetter(SUBPOPULATION)
public String getSubpopulation() {
return this.subpopulation;
}
}
}
Loading

0 comments on commit 8e37029

Please sign in to comment.