Skip to content

Commit

Permalink
Fix date in create pt
Browse files Browse the repository at this point in the history
Add option to stuttgart application to remove references to network from population in case population and network don't match
  • Loading branch information
Janekdererste committed Aug 25, 2021
1 parent c91d5b6 commit d2f1332
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/matsim/stuttgart/prepare/CreatePt.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void create(Path sharedSvn, Network network, ElevationReader eleva
GtfsConverter.newBuilder()
.setScenario(scenario)
.setTransform(Utils.getTransformationWGS84ToUTM32())
.setDate(LocalDate.now())
.setDate(LocalDate.of(2021, 4, 29))
.setFeed(sharedSvn.resolve(schedule))
.build()
.convert();
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/org/matsim/stuttgart/run/StuttgartApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.application.MATSimApplication;
import org.matsim.contrib.bicycle.BicycleConfigGroup;
import org.matsim.contrib.bicycle.Bicycles;
Expand Down Expand Up @@ -34,6 +36,9 @@
@CommandLine.Command(header = ":: Open Stuttgart Scenario ::", version = StuttgartApplication.VERSION)
public class StuttgartApplication extends MATSimApplication {

@CommandLine.Option(names = "--cleanNetworkRefs", description = "Removes network ids from plans file")
private boolean cleanNetworkReferences = false;

/**
* Current version identifier.
*/
Expand Down Expand Up @@ -94,7 +99,24 @@ protected Config prepareConfig(Config config) {
@Override
protected void prepareScenario(Scenario scenario) {

// don't do anything
if (this.cleanNetworkReferences) {

// remove references from activities
scenario.getPopulation().getPersons().values().parallelStream()
.flatMap(person -> person.getPlans().stream())
.flatMap(plan -> plan.getPlanElements().stream())
.filter(element -> element instanceof Activity)
.map(element -> (Activity)element)
.forEach(activity -> activity.setLinkId(null));

// remove references from legs
scenario.getPopulation().getPersons().values().parallelStream()
.flatMap(person -> person.getPlans().stream())
.flatMap(plan -> plan.getPlanElements().stream())
.filter(element -> element instanceof Leg)
.map(element -> (Leg)element)
.forEach(leg -> leg.setRoute(null));
}
}

@Override
Expand Down

0 comments on commit d2f1332

Please sign in to comment.