3
3
import java .io .BufferedReader ;
4
4
import java .io .File ;
5
5
import java .io .IOException ;
6
+ import java .util .HashSet ;
7
+ import java .util .Set ;
6
8
7
9
import org .apache .logging .log4j .LogManager ;
8
10
import org .apache .logging .log4j .Logger ;
11
13
import org .eqasim .core .simulation .policies .PolicyFactory ;
12
14
import org .eqasim .core .simulation .policies .PolicyPersonFilter ;
13
15
import org .eqasim .core .simulation .policies .config .PoliciesConfigGroup ;
14
- import org .eqasim .core .simulation .policies .routing .FactorRoutingPenalty ;
16
+ import org .eqasim .core .simulation .policies .routing .FixedRoutingPenalty ;
15
17
import org .eqasim .core .simulation .policies .routing .PolicyLinkFinder ;
18
+ import org .eqasim .core .simulation .policies .routing .PolicyLinkFinder .PolicyLinks ;
16
19
import org .eqasim .core .simulation .policies .routing .PolicyLinkFinder .Predicate ;
17
20
import org .matsim .api .core .v01 .Id ;
18
21
import org .matsim .api .core .v01 .IdSet ;
@@ -26,7 +29,8 @@ public class LimitedTrafficZonePolicyFactory implements PolicyFactory {
26
29
private static final Logger logger = LogManager .getLogger (LimitedTrafficZonePolicyFactory .class );
27
30
28
31
static public final String POLICY_NAME = "limitedTrafficZone" ;
29
- private final double insideFactor = 3600.0 ;
32
+ private final double routingPenalty = 7200.0 ;
33
+ private final double utilityPenalty = 1000.0 ;
30
34
31
35
private final Config config ;
32
36
private final Network network ;
@@ -60,33 +64,33 @@ private Policy createPolicy(LimitedTrafficZoneConfigGroup ltzConfig, PolicyPerso
60
64
"Only one of perimetersPath and linkListPath can be set for policy " + ltzConfig .policyName );
61
65
}
62
66
63
- final IdSet < Link > linkIds ;
67
+ PolicyLinks links ;
64
68
if (!ltzConfig .perimetersPath .isEmpty ()) {
65
69
logger .info (" Perimeters: " + ltzConfig .perimetersPath );
66
70
67
- linkIds = PolicyLinkFinder
71
+ links = PolicyLinkFinder
68
72
.create (new File (
69
73
ConfigGroup .getInputFileURL (config .getContext (), ltzConfig .perimetersPath ).getPath ()))
70
- .findLinks (network , Predicate .Inside , true );
71
-
72
- logger .info (" Affected inside links: " + linkIds .size ());
74
+ .findLinks (network , Predicate .Crossing );
73
75
} else if (!ltzConfig .linkListPath .isEmpty ()) {
74
76
logger .info (" Link list: " + ltzConfig .linkListPath );
75
77
76
- linkIds = loadLinkList (ConfigGroup .getInputFileURL (config .getContext (), ltzConfig .linkListPath ).getPath (),
78
+ links = loadLinkList (ConfigGroup .getInputFileURL (config .getContext (), ltzConfig .linkListPath ).getPath (),
77
79
network , ltzConfig .policyName );
78
-
79
- logger .info (" Affected links: " + linkIds .size ());
80
80
} else {
81
81
throw new IllegalStateException (
82
82
"One of perimetersPath and linkListPath must be set for policy " + ltzConfig .policyName );
83
83
}
84
84
85
- return new DefaultPolicy (new FactorRoutingPenalty (linkIds , insideFactor , personFilter ), null );
85
+ logger .info (" Affected active links (penalized): " + links .active ().size ());
86
+ logger .info (" Affected connecting links (forbidden as origin/destination): " + links .connecting ().size ());
87
+
88
+ return new DefaultPolicy (new FixedRoutingPenalty (links .active (), routingPenalty , personFilter ),
89
+ new LimitedTrafficZoneUtilityPenalty (utilityPenalty , links .connecting (), personFilter ));
86
90
}
87
91
88
- private static IdSet < Link > loadLinkList (String path , Network network , String policy ) {
89
- IdSet <Link > linkList = new IdSet <>(Link .class );
92
+ private static PolicyLinks loadLinkList (String path , Network network , String policy ) {
93
+ IdSet <Link > area = new IdSet <>(Link .class );
90
94
91
95
try {
92
96
BufferedReader reader = IOUtils .getBufferedReader (path );
@@ -103,7 +107,7 @@ private static IdSet<Link> loadLinkList(String path, Network network, String pol
103
107
+ " which is not included in network" );
104
108
}
105
109
106
- linkList .add (link .getId ());
110
+ area .add (link .getId ());
107
111
}
108
112
}
109
113
@@ -112,6 +116,30 @@ private static IdSet<Link> loadLinkList(String path, Network network, String pol
112
116
throw new RuntimeException (e );
113
117
}
114
118
115
- return linkList ;
119
+ // Now find all links that consitute the edge
120
+ IdSet <Link > active = new IdSet <>(Link .class );
121
+
122
+ for (Id <Link > currentId : area ) {
123
+ Link currentLink = network .getLinks ().get (currentId );
124
+
125
+ Set <Id <Link >> incoming = new HashSet <>(currentLink .getFromNode ().getInLinks ().keySet ());
126
+ Set <Id <Link >> outgoing = new HashSet <>(currentLink .getToNode ().getOutLinks ().keySet ());
127
+
128
+ int totalIncoming = incoming .size ();
129
+ int totalOutgoing = outgoing .size ();
130
+
131
+ incoming .removeIf (area ::contains );
132
+ outgoing .removeIf (area ::contains );
133
+
134
+ // this link can only be reached and only leads to the policy area, hence, it is
135
+ // not an edge
136
+ boolean isInternal = incoming .size () == totalIncoming && outgoing .size () == totalOutgoing ;
137
+
138
+ if (!isInternal ) {
139
+ active .add (currentId );
140
+ }
141
+ }
142
+
143
+ return new PolicyLinks (active , PolicyLinkFinder .findConnectingLinks (active , network ));
116
144
}
117
145
}
0 commit comments