Skip to content

Commit

Permalink
and choice experiment policy
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Dec 10, 2024
1 parent af74b60 commit 68e4ae3
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.matsim.run.policies;

import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
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.application.MATSimApplication;
import org.matsim.core.router.TripStructureUtils;
import org.matsim.run.OpenBerlinScenario;
import picocli.CommandLine;

/**
* This class can be used to run some synthetic choice experiments on the OpenBerlin scenario.
*/
public class OpenBerlinChoiceExperiment extends OpenBerlinScenario {

@CommandLine.Option(names = "--bike-speed-factor", description = "Speed factor for bikes", defaultValue = "1.0")
private double bikeSpeedFactor = 1.0;

public static void main(String[] args) {
MATSimApplication.execute(OpenBerlinChoiceExperiment.class, args);
}

@Override
protected void prepareScenario(Scenario scenario) {

super.prepareScenario(scenario);

// If bike speed is adjusted, we need to remove all bike routes and travel times
// These times will be recalculated by the router
if (bikeSpeedFactor != 1.0) {
for (Person person : scenario.getPopulation().getPersons().values()) {
for (Plan plan : person.getPlans()) {
for (Leg leg : TripStructureUtils.getLegs(plan)) {
if (leg.getMode().equals(TransportMode.bike)) {
leg.setRoute(null);
leg.setTravelTimeUndefined();
}
}
}
}
}
}
}

0 comments on commit 68e4ae3

Please sign in to comment.