diff --git a/src/main/java/playground/gleich/plans/ModifyIncomeStreamReading.java b/src/main/java/playground/gleich/plans/ModifyIncomeAndPersonScoreAttributesStreamReading.java similarity index 64% rename from src/main/java/playground/gleich/plans/ModifyIncomeStreamReading.java rename to src/main/java/playground/gleich/plans/ModifyIncomeAndPersonScoreAttributesStreamReading.java index 9594c8e..b6267d5 100644 --- a/src/main/java/playground/gleich/plans/ModifyIncomeStreamReading.java +++ b/src/main/java/playground/gleich/plans/ModifyIncomeAndPersonScoreAttributesStreamReading.java @@ -20,11 +20,18 @@ package playground.gleich.plans; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; +import org.matsim.api.core.v01.population.Person; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.gbl.MatsimRandom; import org.matsim.core.population.PersonUtils; import org.matsim.core.population.io.StreamingPopulationReader; import org.matsim.core.population.io.StreamingPopulationWriter; import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.core.scoring.functions.PersonSpecificScoringAttributesSetter; +import org.matsim.utils.math.RandomFromDistribution; + +import java.util.*; /** * @author gleich @@ -33,25 +40,36 @@ * pass through this area by car (and ignore all other agents). * */ -public class ModifyIncomeStreamReading { +public class ModifyIncomeAndPersonScoreAttributesStreamReading { public static void main(String[] args) { - String inputPopulationPath = "/home/gregor/git/public-svn/matsim/scenarios/countries/de/berlin/berlin-v5.5-10pct/input/berlin-v5.5-10pct.plans.xml.gz"; - String outputPopulationPath = "/home/gregor/git/public-svn/matsim/scenarios/countries/de/berlin/berlin-v5.5-10pct/input/berlin-v5.5-10pct.plans_income_all_identical.xml.gz"; + double mean = -0.017; + double sigma = 3; + String mode = TransportMode.car; + String inputPopulationPath = "../public-svn/matsim/scenarios/countries/de/berlin/berlin-v6.0/input/berlin-v6.0-10pct.plans.xml.gz"; + String outputPopulationPath = "../public-svn/matsim/scenarios/countries/de/berlin/berlin-v6.0/input/berlin-v6.0-10pct.plans_person_asc_" + mode + "_mean_" + mean + "_sigma_" + sigma + ".xml.gz"; Scenario inputScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); System.out.println("initialize done"); StreamingPopulationWriter popWriter = new StreamingPopulationWriter(); popWriter.writeStartPlans(outputPopulationPath); + + SplittableRandom splittableRandom = new SplittableRandom(1234); StreamingPopulationReader spr = new StreamingPopulationReader(inputScenario); spr.addAlgorithm(person -> { - Double oldIncome = PersonUtils.getIncome(person); - if (oldIncome != null) { - double newIncome = 1; - PersonUtils.setIncome(person, newIncome); +// Double oldIncome = PersonUtils.getIncome(person); +// if (oldIncome != null) { +// double newIncome = 1; +// PersonUtils.setIncome(person, newIncome); +// } + Map modeConstants = PersonUtils.getModeConstants(person); + if (modeConstants == null) { + modeConstants = new HashMap<>(); } + modeConstants.put(mode, Double.toString(RandomFromDistribution.nextLogNormalFromMeanAndSigma(splittableRandom, mean, sigma))); + PersonUtils.setModeConstants(person, modeConstants); popWriter.writePerson(person); } );