Skip to content

Commit

Permalink
still work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
vsp-gleich committed Aug 2, 2024
1 parent f755653 commit 4a02319
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, String> 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);
}
);
Expand Down

0 comments on commit 4a02319

Please sign in to comment.