Skip to content

Commit

Permalink
first version of script to adjust open population
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Nov 29, 2023
1 parent d8d9ea8 commit aa20a18
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/main/java/org/matsim/prepare/PrepareOpenPopulation.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.matsim.prepare;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.application.MATSimAppCommand;
import org.matsim.core.population.PopulationUtils;
import org.matsim.core.router.TripStructureUtils;
import picocli.CommandLine;

import java.nio.file.Path;
import java.util.List;

@CommandLine.Command(
name = "open-population",
description = "Prepare open population"
)
public class PrepareOpenPopulation implements MATSimAppCommand {

private static final Logger log = LogManager.getLogger(PrepareOpenPopulation.class);

@CommandLine.Option(names = "--open-population", description = "Path to population using open data", required = true)
private Path openPopulationPath;

Expand All @@ -34,9 +34,6 @@ public static void main(String[] args) {
@Override
public Integer call() throws Exception {

// TODO read open population
// replace coordinates from

Population openPopulation = PopulationUtils.readPopulation(openPopulationPath.toString());
Population calibratedPopulation = PopulationUtils.readPopulation(calibratedPopulationPath.toString());

Expand All @@ -62,8 +59,37 @@ public Integer call() throws Exception {
*/
private void prepare(Person targetPerson, Person sourcePerson) {

// Activities with type "other" were added synthetically, these coordinates are not copied
List<Activity> activities = TripStructureUtils.getActivities(sourcePerson.getSelectedPlan(), TripStructureUtils.StageActivityHandling.ExcludeStageActivities);

// TODO
}
for (Plan plan : targetPerson.getPlans()) {

List<Activity> targetActs = TripStructureUtils.getActivities(plan, TripStructureUtils.StageActivityHandling.ExcludeStageActivities);

int toActivityCounter = 0;
for (int fromActivityCounter = 0; fromActivityCounter < activities.size(); fromActivityCounter++) {
Activity fromActivity = activities.get(fromActivityCounter);
Activity toActivity = targetActs.get(toActivityCounter);

// Skip other and the second part of the actual activity (which are both not present in the target)
if (fromActivity.getType().startsWith("other")) {
fromActivityCounter++;
continue;
}

if (toActivity.getType().startsWith("other")) {
Activity secondOccurrenceOfLastFromActivity = targetActs.get(toActivityCounter + 1);
secondOccurrenceOfLastFromActivity.setCoord(activities.get(fromActivityCounter - 1).getCoord());

toActivityCounter += 2;
continue;
}

toActivity.setCoord(fromActivity.getCoord());
toActivityCounter++;
}

TripStructureUtils.getLegs(plan).forEach(leg -> leg.setRoute(null));
}
}
}

0 comments on commit aa20a18

Please sign in to comment.