Skip to content

Commit

Permalink
adding features useful for intersections
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed May 14, 2024
1 parent eed7ff1 commit 8e570e8
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.matsim.contrib.sumo;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.apache.commons.csv.CSVPrinter;
import org.matsim.contrib.osm.networkReader.LinkProperties;

Expand Down Expand Up @@ -116,7 +118,10 @@ public List<String> getHeader() {
return List.of("linkId", "highway_type", "speed", "length", "num_lanes", "change_num_lanes", "change_speed", "num_to_links", "num_conns",
"num_response", "num_foes", "dir_multiple_s", "dir_l", "dir_r", "dir_s", "dir_exclusive", "curvature",
"junction_type", "junction_inc_lanes", "priority_higher", "priority_equal", "priority_lower",
"is_secondary_or_higher", "is_primary_or_higher", "is_motorway", "is_link", "has_merging_link", "is_merging_into");
"is_secondary_or_higher", "is_primary_or_higher", "is_motorway",
"is_link", "has_merging_link", "is_merging_into",
"num_connections", "num_left", "num_right", "num_straight"
);
}

public void print(CSVPrinter out) {
Expand Down Expand Up @@ -157,12 +162,18 @@ public void print(CSVPrinter out, String linkId, SumoNetworkHandler.Edge edge) t
Set<Character> dirs = new HashSet<>();
boolean multipleDirS = false;
boolean exclusiveDirs = true;

// Number of connections per direction
Object2IntMap<Character> numConnections = new Object2IntOpenHashMap<>();

for (SumoNetworkHandler.Connection c : connections) {

Set<Character> d = directionSet(c);
if (dirs.contains('s') && d.contains('s'))
multipleDirS = true;

d.forEach(dir -> numConnections.mergeInt(dir, 1, Integer::sum));

Set<Character> intersection = new HashSet<>(dirs); // use the copy constructor
intersection.retainAll(d);
if (!intersection.isEmpty())
Expand Down Expand Up @@ -233,6 +244,10 @@ public void print(CSVPrinter out, String linkId, SumoNetworkHandler.Edge edge) t
out.print(bool(highwayType.contains("link")));
out.print(bool(merging));
out.print(mergingHighest);
out.print(connections.size());
out.print(numConnections.getInt('l'));
out.print(numConnections.getInt('r'));
out.print(numConnections.getInt('s'));

out.println();
}
Expand Down

0 comments on commit 8e570e8

Please sign in to comment.