-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added autofrei scenario for datascience course
- Loading branch information
1 parent
7336b1a
commit 37b38a6
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/main/java/org/matsim/run/OpenBerlinCarfreeScenario.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.matsim.run; | ||
|
||
import org.geotools.api.feature.simple.SimpleFeature; | ||
|
||
import org.geotools.feature.simple.SimpleFeatureImpl; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.matsim.api.core.v01.Scenario; | ||
import org.matsim.api.core.v01.TransportMode; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.population.Leg; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.api.core.v01.population.Plan; | ||
import org.matsim.application.MATSimApplication; | ||
import org.matsim.core.network.algorithms.MultimodalNetworkCleaner; | ||
import org.matsim.core.router.TripStructureUtils; | ||
import org.matsim.core.utils.geometry.geotools.MGC; | ||
import org.matsim.core.utils.gis.ShapeFileReader; | ||
import picocli.CommandLine; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
//run --1pct --config:controller.lastIteration 1 --config:controller.overwriteFiles deleteDirectoryIfExists | ||
public class OpenBerlinCarfreeScenario extends OpenBerlinScenario { | ||
|
||
@CommandLine.Option(names = "--ban-area", | ||
defaultValue = "input/v6.3/hundekopf-shp/hundekopf-carBanArea-25832.shp", | ||
description = "Path to (single geom) shape file depicting the area where private cars are banned from. If you adjust, think about adjusting the drt area+stops file, as well!") | ||
private static String SHAPE_FILE; | ||
public OpenBerlinCarfreeScenario() { | ||
super(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
MATSimApplication.run(OpenBerlinCarfreeScenario.class, args); | ||
} | ||
@Override | ||
protected void prepareScenario(Scenario scenario) { | ||
super.prepareScenario(scenario); | ||
ShapeFileReader shpReader = new ShapeFileReader(); | ||
Collection<SimpleFeature> features = shpReader.readFileAndInitialize(SHAPE_FILE); | ||
Geometry consideredArea = (Geometry) ((SimpleFeatureImpl) ((ArrayList) features).get(0)).getDefaultGeometry(); | ||
|
||
// disallow car mode within ring (all links for which the from and to nodes are within the shape file). | ||
for (Link link : scenario.getNetwork().getLinks().values()) { | ||
if (!link.getAllowedModes().contains("pt") && MGC.coord2Point(link.getFromNode().getCoord()).within(consideredArea) && | ||
MGC.coord2Point(link.getToNode().getCoord()).within(consideredArea)) { | ||
HashSet<String> allowedModes = new HashSet<>(link.getAllowedModes()); | ||
allowedModes.remove(TransportMode.car); | ||
link.setAllowedModes(allowedModes); | ||
link.getAttributes().putAttribute("ring", true); | ||
}else { | ||
link.getAttributes().putAttribute("ring", false); | ||
} | ||
} | ||
|
||
for (Person person : scenario.getPopulation().getPersons().values()) { | ||
for (Plan plan : person.getPlans()) { | ||
for (Leg leg : TripStructureUtils.getLegs(plan)) { | ||
if (leg.getMode().equals(TransportMode.car)) { | ||
leg.setRoute(null); | ||
} | ||
} | ||
} | ||
} | ||
|
||
new MultimodalNetworkCleaner(scenario.getNetwork()).run(Set.of(TransportMode.car)); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters