Skip to content

Commit

Permalink
fix: external inlinks for LTZ policy
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Jan 21, 2025
1 parent ccbc69d commit abcc903
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private Policy createPolicy(CityTaxConfigGroup enterConfig, PolicyPersonFilter p
IdSet<Link> linkIds = PolicyLinkFinder
.create(new File(
ConfigGroup.getInputFileURL(config.getContext(), enterConfig.perimetersPath).getPath()))
.findLinks(network, Predicate.Entering);
.findLinks(network, Predicate.Entering, false);

logger.info(" Affected entering links: " + linkIds.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private Policy createPolicy(LimitedTrafficZoneConfigGroup ltzConfig, PolicyPerso
linkIds = PolicyLinkFinder
.create(new File(
ConfigGroup.getInputFileURL(config.getContext(), ltzConfig.perimetersPath).getPath()))
.findLinks(network, Predicate.Inside);
.findLinks(network, Predicate.Inside, true);

logger.info(" Affected inside links: " + linkIds.size());
} else if (!ltzConfig.linkListPath.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.IdSet;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.network.Node;

public class PolicyLinkFinder {
private final static GeometryFactory geometryFactory = new GeometryFactory();
Expand All @@ -31,7 +33,7 @@ public enum Predicate {
Entering, Exiting, Crossing, Inside
}

public IdSet<Link> findLinks(Network network, Predicate predicate) {
public IdSet<Link> findLinks(Network network, Predicate predicate, boolean includeConnecting) {
IdSet<Link> linkIds = new IdSet<>(Link.class);

for (Link link : network.getLinks().values()) {
Expand All @@ -58,6 +60,38 @@ public IdSet<Link> findLinks(Network network, Predicate predicate) {
}
}

if (includeConnecting) {
boolean continueNextRound = true;
while (continueNextRound) {
continueNextRound = false;

for (Link link : network.getLinks().values()) {
if (linkIds.contains(link.getId())) {
continue; // skip tagged links
}

Node toNode = link.getToNode();

boolean allConnectionsTagged = true;
for (Id<Link> outlinkId : toNode.getOutLinks().keySet()) {
if (outlinkId.equals(link.getId())) {
continue; // skip self loops
}

if (!linkIds.contains(outlinkId)) {
allConnectionsTagged = false;
break;
}
}

if (allConnectionsTagged) {
continueNextRound = true;
linkIds.add(link.getId());
}
}
}
}

return linkIds;
}

Expand Down

0 comments on commit abcc903

Please sign in to comment.