Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/integrateCommercial…
Browse files Browse the repository at this point in the history
…Traffic' into develop
  • Loading branch information
rewertvsp committed Jul 2, 2024
2 parents 380073b + 1822d56 commit 36e3252
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.network.Node;
import org.matsim.application.options.ShpOptions;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.utils.geometry.CoordUtils;
Expand All @@ -25,15 +26,28 @@ public class TransferRestrictions {
Transfers Restrictions from the shapefile to the given Network.
*/

private static final String ruhrNetworkPath = "D:\\Projects\\VSP\\RUHR\\commercialTraffic\\ruhr_network.xml.gz";
private static final String ruhrNetworkPath = "D:\\Projects\\VSP\\RUHR\\metropole-ruhr-v2.0.network_resolutionHigh-with-pt.xml";
private static final String restrictionPath = "D:\\Projects\\VSP\\RUHR\\commercialTraffic\\Restriktionen_RVR_20231121\\Restriktionen_RVR_20231121.shp";
private static final String outputPath = "scenarios/metropole-ruhr-v1.0/ruhr_network_with_restrictions.xml.gz";

public static void main(String[] args){
//Read in shp and xml files
Network network = NetworkUtils.readNetwork(ruhrNetworkPath);
Network network_no_pt = NetworkUtils.createNetwork();
ShpOptions shp = new ShpOptions(Path.of(restrictionPath), null, null);

//Create copy of network which only contains links, where car/freight-traffic is allowed (not pt, no bike-only-links, ...)
for(Node n : network.getNodes().values()){
if(!n.getId().toString().startsWith("pt") && !n.getId().toString().startsWith("bike")){
network_no_pt.addNode(n);
}
}
for(Link l : network.getLinks().values()){
if(l.getAllowedModes().contains("car") || l.getAllowedModes().contains("freight")){
network_no_pt.addLink(l);
}
}

// Add all freight-modes to all car-links
Collection<? extends Link> links = network.getLinks().values();
Set<String> all = new HashSet<>(Arrays.asList("truck8t", "truck18t", "truck26t", "truck40t"));
Expand All @@ -60,10 +74,17 @@ public static void main(String[] args){
//Finds the center of two nodes and searches for the link from there
if(j != 0){
Coord center = CoordUtils.getCenter(coord, coord);
Link nearestLink = NetworkUtils.getNearestLinkExactly(network, center);
Link nearestLink = NetworkUtils.getNearestLinkExactly(network_no_pt, center);
Link oppositeLink = NetworkUtils.findLinkInOppositeDirection(nearestLink);
Set<String> allowedModes = new HashSet<>(nearestLink.getAllowedModes()); // Makes a copy, because original is immutable

//Sort out links, that were assigned incorrectly
double distance = NetworkUtils.getEuclideanDistance(nearestLink.getFromNode().getCoord(), center);
double links_euclidean_length = NetworkUtils.getEuclideanDistance(nearestLink.getFromNode().getCoord(), nearestLink.getToNode().getCoord());
if(distance > links_euclidean_length+20){
continue;
}

//Get value if numeric
float value = -1;
try{
Expand Down

0 comments on commit 36e3252

Please sign in to comment.