Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: external inlinks for LTZ policy #295

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading