From de7e9dcefab1ef50252ffd851b0b7e698bb9e876 Mon Sep 17 00:00:00 2001 From: GregorRyb Date: Mon, 27 May 2024 17:31:03 +0200 Subject: [PATCH] continue with pt flat --- .../org/matsim/run/RunGladbeckScenario.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/matsim/run/RunGladbeckScenario.java b/src/main/java/org/matsim/run/RunGladbeckScenario.java index 297a1db..4b03f91 100644 --- a/src/main/java/org/matsim/run/RunGladbeckScenario.java +++ b/src/main/java/org/matsim/run/RunGladbeckScenario.java @@ -64,7 +64,7 @@ public class RunGladbeckScenario extends RunMetropoleRuhrScenario { @CommandLine.Option(names = "--simplePtFlat", defaultValue = "false", description = "measures to allow everyone to have free pt") boolean scenarioWidePtFlat; - @CommandLine.Option(names = "--PtFlat", defaultValue = "false", description = "measures to allow 40 people to have free pt") + @CommandLine.Option(names = "--ptFlat", defaultValue = "false", description = "measures to allow 40 people to have free pt") boolean ptFlat; @CommandLine.Option(names = "--cyclingCourse", defaultValue = "false", description = "measures to increase the ") @@ -120,16 +120,7 @@ protected void prepareScenario(Scenario scenario) { // 40 people were provided with free pt tickets if (ptFlat) { - List> personsEligibleForPtFlatrate = new ArrayList<>(); - for (int ii = 0; ii >40 ; ii++) { - Random generator = MatsimRandom.getRandom(); - Object[] values = scenario.getPopulation().getPersons().values().toArray(); - Id randomPerson = (Id) values[generator.nextInt(values.length)]; - HomeLocationFilter homeLocationFilter = new HomeLocationFilter(shp, scenario.getConfig().global().getCoordinateSystem(), scenario.getPopulation()); - if (homeLocationFilter.test(scenario.getPopulation().getPersons().get(randomPerson)) == true) { - personsEligibleForPtFlatrate.add(randomPerson); - } - } + } if (slowSpeedZone) { @@ -210,8 +201,18 @@ public void install() { if (ptFlat) { - addPtFlat(controler, new PtFlatrate(personsEligibleForPtFlatrate, controler.getConfig().planCalcScore().getModes().get(TransportMode.pt).getDailyMonetaryConstant())); + List> personsEligibleForPtFlatrate = new ArrayList<>(); + while (personsEligibleForPtFlatrate.size() != 40) { + Random generator = MatsimRandom.getRandom(); + Object[] values = controler.getScenario().getPopulation().getPersons().values().toArray(); + var randomPerson = (Person) values[generator.nextInt(values.length)]; + HomeLocationFilter homeLocationFilter = new HomeLocationFilter(shp, controler.getScenario().getConfig().global().getCoordinateSystem(), controler.getScenario().getPopulation()); + if (homeLocationFilter.test(controler.getScenario().getPopulation().getPersons().get(randomPerson.getId()))) { + personsEligibleForPtFlatrate.add(randomPerson.getId()); + } + } + addPtFlat(controler, new PtFlatrate(personsEligibleForPtFlatrate, controler.getConfig().planCalcScore().getModes().get(TransportMode.pt).getDailyMonetaryConstant())); } super.prepareControler(controler);