Skip to content

Commit

Permalink
set home coordinates in the open population
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jan 9, 2024
1 parent 34ad301 commit 7ad3b31
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

JAR := matsim-gladbeck-*.jar
V := v1.0
V := v2.0
CRS := EPSG:25832

$(JAR):
Expand All @@ -11,8 +11,7 @@ NETWORK := ../public-svn/matsim/scenarios/countries/de/metropole-ruhr/metropole-
SHAPE := scenarios/study-area-utm.shp
export JAVA_TOOL_OPTIONS := -Xmx50G -Xms50G

scenarios/input/gladbeck-$V-25pct.plans.xml.gz:

scenarios/gladbeck-$V/input/gladbeck-$V-25pct.plans.xml.gz:
java -jar $(JAR) prepare scenario-cutout\
--input $(POPULATION)\
--network $(NETWORK)\
Expand All @@ -33,8 +32,14 @@ scenarios/input/gladbeck-$V-25pct.plans.xml.gz:
--sample-size 0.25\
--samples 0.1 0.01

scenarios/input/gladbeck-$V-homes.csv: scenarios/input/gladbeck-$V-25pct.plans.xml.gz
scenarios/gladbeck-$V/input/gladbeck-$V-10pct.open-plans-initial.xml.gz:
java -jar $(JAR) prepare open-population\
--open-population ../../shared-svn/projects/matsim-metropole-ruhr/metropole-ruhr-v1.0/input/metropole-ruhr-v1.4-25pct.open-plans.xml.gz\
--calibrated-population ../../shared-svn/projects/GlaMoBi/matsim-input-files/gladbeck-v1.3-10pct.plans-cleaned.xml.gz\
--output $@

scenarios/gladbeck-$V/input/gladbeck-$V-homes.csv: scenarios/gladbeck-$V/input/gladbeck-$V-25pct.plans.xml.gz
java -jar $(JAR) prepare extract-home-coordinates $< --csv $@

prepare: scenarios/input/gladbeck-$V-25pct.plans.xml.gz scenarios/input/gladbeck-$V-homes.csv
prepare: scenarios/gladbeck-$V/input/gladbeck-$V-25pct.plans.xml.gz scenarios/gladbeck-$V/input/gladbeck-$V-homes.csv
echo "Done"
37 changes: 33 additions & 4 deletions src/main/java/org/matsim/prepare/PrepareOpenPopulation.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.matsim.prepare;

import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.api.core.v01.population.Population;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.population.*;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.prepare.population.ExtractHomeCoordinates;
import org.matsim.core.population.PopulationUtils;
import org.matsim.core.router.TripStructureUtils;
import picocli.CommandLine;
Expand Down Expand Up @@ -50,6 +49,9 @@ public Integer call() throws Exception {
prepare(person, openPerson);
}

// Re-calculates home coordinates
calibratedPopulation.getPersons().values().forEach(PrepareOpenPopulation::setHomeCoordinate);

PopulationUtils.writePopulation(calibratedPopulation, output.toString());

return 0;
Expand Down Expand Up @@ -117,4 +119,31 @@ private void prepare(Person targetPerson, Person sourcePerson) {
TripStructureUtils.getLegs(plan).forEach(leg -> leg.setRoute(null));
}
}

/**
* Can be removed in new MATSim version.
* @see ExtractHomeCoordinates
*/
private static void setHomeCoordinate(Person person) {

outer:
for (Plan plan : person.getPlans()) {
for (PlanElement planElement : plan.getPlanElements()) {
if (planElement instanceof Activity) {
String actType = ((Activity) planElement).getType();
if (actType.startsWith("home")) {
Coord homeCoord = ((Activity) planElement).getCoord();

person.getAttributes().putAttribute("home_x", homeCoord.getX());
person.getAttributes().putAttribute("home_y", homeCoord.getY());

break outer;
}
}
}

}

}

}
3 changes: 2 additions & 1 deletion src/main/java/org/matsim/run/RunGladbeckScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.matsim.core.utils.io.IOUtils;
import org.matsim.prepare.AssignPersonAttributes;
import org.matsim.prepare.BicyclePolicies;
import org.matsim.prepare.PrepareOpenPopulation;
import org.matsim.prepare.ScenarioCutOut;
import org.matsim.run.policies.KlimaTaler;
import org.matsim.run.policies.ReduceSpeed;
Expand All @@ -39,7 +40,7 @@
import java.util.Set;

@CommandLine.Command(header = ":: Gladbeck Scenario ::", version = RunGladbeckScenario.VERSION)
@MATSimApplication.Prepare({ScenarioCutOut.class, DownSamplePopulation.class, FixSubtourModes.class, XYToLinks.class, ExtractHomeCoordinates.class, BicyclePolicies.class})
@MATSimApplication.Prepare({ScenarioCutOut.class, DownSamplePopulation.class, FixSubtourModes.class, XYToLinks.class, ExtractHomeCoordinates.class, BicyclePolicies.class, PrepareOpenPopulation.class})
@MATSimApplication.Analysis({NoiseAnalysis.class, AirPollutionByVehicleCategory.class, AirPollutionSpatialAggregation.class})
public class RunGladbeckScenario extends RunMetropoleRuhrScenario {

Expand Down

0 comments on commit 7ad3b31

Please sign in to comment.