Skip to content

Commit

Permalink
simplify test setups
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Sep 2, 2024
1 parent 700e9de commit 7e56092
Showing 1 changed file with 33 additions and 72 deletions.
105 changes: 33 additions & 72 deletions src/test/java/org/matsim/run/RunIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ void runScenario() {
@Test
void runScenarioIncludingDrt() {

// TODO: add dummy drt person.
// TODO: test smc with drt. THere has to be some person changing to drt before iteration1
Config config = ConfigUtils.loadConfig(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION));
ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;

Expand All @@ -70,48 +68,7 @@ void runScenarioIncludingDrt() {

Path inputPath = p.resolve("drt-test-population.xml.gz");

Population population = PopulationUtils.createPopulation(config);
PopulationFactory fac = population.getFactory();
Person person = fac.createPerson(ptPersonId);
Plan plan = PopulationUtils.createPlan(person);

// home in hoyerswerda
Activity home = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24));
home.setEndTime(8 * 3600);
Activity home2 = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24));
home2.setEndTime(19 * 3600);
// work in ruhland rail station
Activity work = fac.createActivityFromCoord("work_2400", new Coord(838300.95,5711890.36));
work.setEndTime(17 * 3600 + 25 * 60);

Leg leg = fac.createLeg(TransportMode.drt);

plan.addActivity(home);
plan.addLeg(leg);
plan.addActivity(work);
plan.addLeg(leg);
plan.addActivity(home2);

person.addPlan(plan);
PersonUtils.setIncome(person, 1000.);
person.getAttributes().putAttribute("subpopulation", "person");
population.addPerson(person);

Person person2 = fac.createPerson(Id.createPersonId("smc-person"));
Plan plan2 = PopulationUtils.createPlan(person2);
Leg carLeg = fac.createLeg(TransportMode.car);

plan2.addActivity(home);
plan2.addLeg(carLeg);
plan2.addActivity(work);
plan2.addLeg(carLeg);
plan2.addActivity(home2);
person2.addPlan(plan2);

PersonUtils.setIncome(person2, 1000.);
person2.getAttributes().putAttribute("subpopulation", "person");
population.addPerson(person2);
new PopulationWriter(population).write(inputPath.toString());
createTestPopulation(config, inputPath, TransportMode.drt, new Coord(838300.95,5711890.36));

assert MATSimApplication.execute(RunLausitzDrtScenario.class, config,
"--1pct",
Expand All @@ -129,34 +86,7 @@ void runScenarioIncludingAdditionalPtLine() {

Path inputPath = p.resolve("pt-test-population.xml.gz");

Population population = PopulationUtils.createPopulation(config);
PopulationFactory fac = population.getFactory();
Person person = fac.createPerson(ptPersonId);
Plan plan = PopulationUtils.createPlan(person);

// home in hoyerswerda
Activity home = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24));
home.setEndTime(8 * 3600);
Activity home2 = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24));
home2.setEndTime(19 * 3600);
// work in cottbus
Activity work = fac.createActivityFromCoord("work_2400", new Coord(867489.48,5746587.47));
work.setEndTime(17 * 3600 + 25 * 60);

Leg leg = fac.createLeg(TransportMode.pt);

plan.addActivity(home);
plan.addLeg(leg);
plan.addActivity(work);
plan.addLeg(leg);
plan.addActivity(home2);

person.addPlan(plan);
PersonUtils.setIncome(person, 1000.);
person.getAttributes().putAttribute("subpopulation", "person");
population.addPerson(person);

new PopulationWriter(population).write(inputPath.toString());
createTestPopulation(config, inputPath, TransportMode.pt, new Coord(867489.48,5746587.47));

assert MATSimApplication.execute(RunLausitzPtScenario.class, config,
"--1pct",
Expand Down Expand Up @@ -191,6 +121,37 @@ void runScenarioIncludingAdditionalPtLine() {

}

private static void createTestPopulation(Config config, Path inputPath, String mode, Coord workLocation) {
Population population = PopulationUtils.createPopulation(config);
PopulationFactory fac = population.getFactory();
Person person = fac.createPerson(ptPersonId);
Plan plan = PopulationUtils.createPlan(person);

// home in hoyerswerda
Activity home = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24));
home.setEndTime(8 * 3600);
Activity home2 = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24));
home2.setEndTime(19 * 3600);
// work in given location
Activity work = fac.createActivityFromCoord("work_2400", workLocation);
work.setEndTime(17 * 3600 + 25 * 60);

Leg leg = fac.createLeg(mode);

plan.addActivity(home);
plan.addLeg(leg);
plan.addActivity(work);
plan.addLeg(leg);
plan.addActivity(home2);

person.addPlan(plan);
PersonUtils.setIncome(person, 1000.);
person.getAttributes().putAttribute("subpopulation", "person");
population.addPerson(person);

new PopulationWriter(population).write(inputPath.toString());
}

private static final class PersonEntersPtVehicleEventHandler implements PersonEntersVehicleEventHandler {
static List<PersonEntersVehicleEvent> enterEvents = new ArrayList<>();

Expand Down

0 comments on commit 7e56092

Please sign in to comment.