Skip to content

Commit f3609f0

Browse files
authored
feat: ability to restrict VDF updates to a shapefile area (#247)
1 parent d36be2e commit f3609f0

4 files changed

Lines changed: 52 additions & 7 deletions

File tree

core/src/main/java/org/eqasim/core/simulation/vdf/VDFConfigGroup.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class VDFConfigGroup extends ReflectiveConfigGroup {
2626

2727
static private final String HANDLER = "handler";
2828
static private final String INPUT_FILE = "inputFile";
29+
static private final String UPDATE_AREA_SHAPEFILE = "updateAreaShapefile";
2930
static private final String WRITE_INTERVAL = "writeInterval";
3031
static private final String WRITE_FLOW_INTERVAL = "writeFlowInterval";
3132

@@ -43,6 +44,7 @@ public class VDFConfigGroup extends ReflectiveConfigGroup {
4344
private double capacityFactor = 1.0;
4445

4546
private String inputFile = null;
47+
private String updateAreaShapefile = null;
4648
private int writeInterval = 0;
4749
private int writeFlowInterval = 0;
4850

@@ -200,6 +202,16 @@ public void setInputFile(String inputFile) {
200202
this.inputFile = inputFile;
201203
}
202204

205+
@StringGetter(UPDATE_AREA_SHAPEFILE)
206+
public String getUpdateAreaShapefile() {
207+
return updateAreaShapefile;
208+
}
209+
210+
@StringSetter(UPDATE_AREA_SHAPEFILE)
211+
public void setUpdateAreaShapefile(String updateAreaShapefile) {
212+
this.updateAreaShapefile = updateAreaShapefile;
213+
}
214+
203215
@StringGetter(WRITE_INTERVAL)
204216
public int getWriteInterval() {
205217
return writeInterval;

core/src/main/java/org/eqasim/core/simulation/vdf/VDFModule.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package org.eqasim.core.simulation.vdf;
22

3+
import java.io.File;
4+
import java.io.IOException;
35
import java.net.URL;
6+
import java.util.Optional;
47

58
import org.eqasim.core.components.config.EqasimConfigGroup;
9+
import org.eqasim.core.scenario.cutter.extent.ScenarioExtent;
10+
import org.eqasim.core.scenario.cutter.extent.ShapeScenarioExtent;
611
import org.eqasim.core.simulation.vdf.handlers.VDFHorizonHandler;
712
import org.eqasim.core.simulation.vdf.handlers.VDFInterpolationHandler;
813
import org.eqasim.core.simulation.vdf.handlers.VDFTrafficHandler;
@@ -64,9 +69,10 @@ public VDFScope provideVDFScope(VDFConfigGroup config) {
6469
@Provides
6570
@Singleton
6671
public VDFTravelTime provideVDFTravelTime(VDFConfigGroup config, VDFScope scope, Network network,
67-
VolumeDelayFunction vdf, QSimConfigGroup qsimConfig, EqasimConfigGroup eqasimConfig) {
72+
VolumeDelayFunction vdf, QSimConfigGroup qsimConfig, EqasimConfigGroup eqasimConfig) throws IOException {
73+
ScenarioExtent updateExtent = config.getUpdateAreaShapefile() == null ? null : new ShapeScenarioExtent.Builder(new File(ConfigGroup.getInputFileURL(getConfig().getContext(), config.getUpdateAreaShapefile()).getPath()), Optional.empty(), Optional.empty()).build();
6874
return new VDFTravelTime(scope, config.getMinimumSpeed(), config.getCapacityFactor(),
69-
eqasimConfig.getSampleSize(), network, vdf, eqasimConfig.getCrossingPenalty());
75+
eqasimConfig.getSampleSize(), network, vdf, eqasimConfig.getCrossingPenalty(), updateExtent);
7076
}
7177

7278
@Provides

core/src/main/java/org/eqasim/core/simulation/vdf/VDFUpdateListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void notifyStartup(StartupEvent event) {
8585

8686
IdMap<Link, List<Double>> data = handler.aggregate();
8787
scope.verify(data, "Wrong flow format");
88-
travelTime.update(data);
88+
travelTime.update(data, true);
8989

9090
logger.info(" Done");
9191
}

core/src/main/java/org/eqasim/core/simulation/vdf/travel_time/VDFTravelTime.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.apache.logging.log4j.LogManager;
99
import org.apache.logging.log4j.Logger;
10+
import org.eqasim.core.scenario.cutter.extent.ScenarioExtent;
1011
import org.eqasim.core.simulation.vdf.VDFScope;
1112
import org.eqasim.core.simulation.vdf.travel_time.function.VolumeDelayFunction;
1213
import org.matsim.api.core.v01.Id;
@@ -27,18 +28,25 @@ public class VDFTravelTime implements TravelTime {
2728

2829
private final Network network;
2930
private final VolumeDelayFunction vdf;
31+
private final ScenarioExtent updateAreaExtent;
3032

3133
private final IdMap<Link, List<Double>> travelTimes = new IdMap<>(Link.class);
3234

3335
private final Logger logger = LogManager.getLogger(VDFTravelTime.class);
3436

35-
public VDFTravelTime(VDFScope scope, double minimumSpeed, double capacityFacotor, double samplingRate,
36-
Network network, VolumeDelayFunction vdf, double crossingPenalty) {
37+
public VDFTravelTime(VDFScope scope, double minimumSpeed, double capacityFactor, double samplingRate,
38+
Network network, VolumeDelayFunction vdf, double crossingPenalty) {
39+
this(scope, minimumSpeed, capacityFactor, samplingRate, network, vdf, crossingPenalty, null);
40+
}
41+
42+
public VDFTravelTime(VDFScope scope, double minimumSpeed, double capacityFactor, double samplingRate,
43+
Network network, VolumeDelayFunction vdf, double crossingPenalty, ScenarioExtent updateAreaExtent) {
3744
this.scope = scope;
3845
this.network = network;
3946
this.vdf = vdf;
47+
this.updateAreaExtent = updateAreaExtent;
4048
this.minimumSpeed = minimumSpeed;
41-
this.capacityFactor = capacityFacotor;
49+
this.capacityFactor = capacityFactor;
4250
this.samplingRate = samplingRate;
4351
this.crossingPenalty = crossingPenalty;
4452

@@ -57,13 +65,32 @@ public double getLinkTravelTime(Link link, double time, Person person, Vehicle v
5765
}
5866

5967
public void update(IdMap<Link, List<Double>> counts) {
60-
logger.info(String.format("Updating VDFTravelTime ..."));
68+
update(counts, false);
69+
}
70+
71+
public void update(IdMap<Link, List<Double>> counts, boolean forceUpdateAllLinks) {
72+
String logMessage = "Updating VDFTravelTime ";
73+
if(updateAreaExtent != null && !forceUpdateAllLinks) {
74+
logMessage += " using update extent ...";
75+
} else {
76+
logMessage += " ...";
77+
}
78+
logger.info(logMessage);
6179

6280
long totalCount = counts.size() * scope.getIntervals();
6381
long nonFreespeedCount = 0;
6482

6583
for (Map.Entry<Id<Link>, List<Double>> entry : counts.entrySet()) {
6684
Link link = network.getLinks().get(entry.getKey());
85+
if(link == null) {
86+
continue;
87+
}
88+
89+
if(updateAreaExtent != null && !forceUpdateAllLinks) {
90+
if(!updateAreaExtent.isInside(link.getFromNode().getCoord()) || !updateAreaExtent.isInside(link.getToNode().getCoord())) {
91+
continue;
92+
}
93+
}
6794

6895
List<Double> linkCounts = entry.getValue();
6996
List<Double> linkTravelTimes = travelTimes.get(entry.getKey());

0 commit comments

Comments
 (0)