1414import org .locationtech .jts .geom .GeometryFactory ;
1515import org .locationtech .jts .geom .Point ;
1616import org .matsim .api .core .v01 .Coord ;
17+ import org .matsim .api .core .v01 .Id ;
1718import org .matsim .api .core .v01 .IdSet ;
1819import org .matsim .api .core .v01 .network .Link ;
1920import org .matsim .api .core .v01 .network .Network ;
21+ import org .matsim .api .core .v01 .network .Node ;
2022
2123public class PolicyLinkFinder {
2224 private final static GeometryFactory geometryFactory = new GeometryFactory ();
@@ -31,7 +33,7 @@ public enum Predicate {
3133 Entering , Exiting , Crossing , Inside
3234 }
3335
34- public IdSet <Link > findLinks (Network network , Predicate predicate ) {
36+ public IdSet <Link > findLinks (Network network , Predicate predicate , boolean includeConnecting ) {
3537 IdSet <Link > linkIds = new IdSet <>(Link .class );
3638
3739 for (Link link : network .getLinks ().values ()) {
@@ -58,6 +60,38 @@ public IdSet<Link> findLinks(Network network, Predicate predicate) {
5860 }
5961 }
6062
63+ if (includeConnecting ) {
64+ boolean continueNextRound = true ;
65+ while (continueNextRound ) {
66+ continueNextRound = false ;
67+
68+ for (Link link : network .getLinks ().values ()) {
69+ if (linkIds .contains (link .getId ())) {
70+ continue ; // skip tagged links
71+ }
72+
73+ Node toNode = link .getToNode ();
74+
75+ boolean allConnectionsTagged = true ;
76+ for (Id <Link > outlinkId : toNode .getOutLinks ().keySet ()) {
77+ if (outlinkId .equals (link .getId ())) {
78+ continue ; // skip self loops
79+ }
80+
81+ if (!linkIds .contains (outlinkId )) {
82+ allConnectionsTagged = false ;
83+ break ;
84+ }
85+ }
86+
87+ if (allConnectionsTagged ) {
88+ continueNextRound = true ;
89+ linkIds .add (link .getId ());
90+ }
91+ }
92+ }
93+ }
94+
6195 return linkIds ;
6296 }
6397
0 commit comments