Skip to content

Commit 431fba7

Browse files
authored
Chore: Moving VDF to core and some fixes (#233)
* refr: moved vdf module content to core * refr: removed unused generateNetworkEvents * fix: mutable modes set * fix: handling non PlanAgent and non HasPerson agents * feat: AdaptConfigForVDF * feat: testing VDF with DRT * chore: removed empty VDF module * fix: properly removed VDF module * fix: properly removed VDF module * fix: properly using the VDF functionality in example * fix: bringing back VDF documentation
1 parent 9644e9b commit 431fba7

28 files changed

+175
-123
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Additional topics:
2323
- How to [cut out smaller parts of existing simulations](docs/cutting.md).
2424
- How to [run a simulation with on-demand mobility services](docs/on_demand_mobility.md) (as a main mode and as a transit feeder).
2525
- How to [run the discrete mode choice model as a standalone](docs/standalone_mode_choice.md)
26+
- How to [use Volume Delay Functions for the network simulation](docs/vdf.md)
2627

2728
## Main reference
2829

core/src/main/java/org/eqasim/core/simulation/EqasimConfigurator.java

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
import org.eqasim.core.simulation.termination.EqasimTerminationConfigGroup;
2525
import org.eqasim.core.simulation.termination.EqasimTerminationModule;
2626
import org.eqasim.core.simulation.termination.mode_share.ModeShareModule;
27+
import org.eqasim.core.simulation.vdf.VDFConfigGroup;
28+
import org.eqasim.core.simulation.vdf.VDFModule;
29+
import org.eqasim.core.simulation.vdf.VDFQSimModule;
30+
import org.eqasim.core.simulation.vdf.engine.VDFEngineConfigGroup;
31+
import org.eqasim.core.simulation.vdf.engine.VDFEngineModule;
2732
import org.matsim.api.core.v01.Id;
2833
import org.matsim.api.core.v01.Scenario;
2934
import org.matsim.api.core.v01.population.Person;
@@ -95,6 +100,13 @@ public EqasimConfigurator() {
95100
new TransitWithAbstractAccessModeChoiceModule()),
96101
List.of(new TransitWithAbstractAccessQSimModule()),
97102
Collections.singletonList((controller, components) -> TransitWithAbstractAccessQSimModule.configure(components, controller.getConfig())));
103+
this.registerOptionalConfigGroup(new VDFConfigGroup(),
104+
List.of(new VDFModule()),
105+
List.of(new VDFQSimModule()));
106+
this.registerOptionalConfigGroup(new VDFEngineConfigGroup(),
107+
List.of(new VDFEngineModule()),
108+
Collections.emptyList(),
109+
Collections.singletonList((controller, components) -> components.addNamedComponent(VDFEngineModule.COMPONENT_NAME)));
98110
}
99111

100112
public ConfigGroup[] getConfigGroups() {

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

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package org.eqasim.vdf;
1+
package org.eqasim.core.simulation.vdf;
22

33
import java.util.Arrays;
4+
import java.util.HashSet;
45
import java.util.Set;
56

67
import org.matsim.api.core.v01.TransportMode;
@@ -27,8 +28,6 @@ public class VDFConfigGroup extends ReflectiveConfigGroup {
2728
static private final String INPUT_FILE = "inputFile";
2829
static private final String WRITE_INTERVAL = "writeInterval";
2930
static private final String WRITE_FLOW_INTERVAL = "writeFlowInterval";
30-
31-
static private final String GENERATE_NETWORK_EVENTS = "generateNetworkEvents";
3231

3332
private double startTime = 0.0 * 3600.0;
3433
private double endTime = 24.0 * 3600.0;
@@ -39,15 +38,13 @@ public class VDFConfigGroup extends ReflectiveConfigGroup {
3938
private double bprFactor = 0.15;
4039
private double bprExponent = 4.0;
4140

42-
private Set<String> modes = Set.of(TransportMode.car, "car_passenger");
41+
private Set<String> modes = new HashSet<>(Set.of(TransportMode.car, "car_passenger"));
4342

4443
private double capacityFactor = 1.0;
4544

4645
private String inputFile = null;
4746
private int writeInterval = 0;
4847
private int writeFlowInterval = 0;
49-
50-
private boolean generateNetworkEvents = true;
5148

5249
public enum HandlerType {
5350
Horizon, Interpolation
@@ -222,16 +219,6 @@ public int getWriteFlowInterval() {
222219
public void setWriteFlowInterval(int val) {
223220
this.writeFlowInterval = val;
224221
}
225-
226-
@StringGetter(GENERATE_NETWORK_EVENTS)
227-
public boolean getNetworkEvents() {
228-
return generateNetworkEvents;
229-
}
230-
231-
@StringSetter(GENERATE_NETWORK_EVENTS)
232-
public void setNetworkEvents(boolean val) {
233-
this.generateNetworkEvents = val;
234-
}
235222

236223
public static VDFConfigGroup getOrCreate(Config config) {
237224
VDFConfigGroup group = (VDFConfigGroup) config.getModules().get(GROUP_NAME);

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package org.eqasim.vdf;
1+
package org.eqasim.core.simulation.vdf;
22

33
import java.net.URL;
44

55
import org.eqasim.core.components.config.EqasimConfigGroup;
6-
import org.eqasim.vdf.handlers.VDFHorizonHandler;
7-
import org.eqasim.vdf.handlers.VDFInterpolationHandler;
8-
import org.eqasim.vdf.handlers.VDFTrafficHandler;
9-
import org.eqasim.vdf.travel_time.VDFTravelTime;
10-
import org.eqasim.vdf.travel_time.function.BPRFunction;
11-
import org.eqasim.vdf.travel_time.function.VolumeDelayFunction;
6+
import org.eqasim.core.simulation.vdf.handlers.VDFHorizonHandler;
7+
import org.eqasim.core.simulation.vdf.handlers.VDFInterpolationHandler;
8+
import org.eqasim.core.simulation.vdf.handlers.VDFTrafficHandler;
9+
import org.eqasim.core.simulation.vdf.travel_time.VDFTravelTime;
10+
import org.eqasim.core.simulation.vdf.travel_time.function.BPRFunction;
11+
import org.eqasim.core.simulation.vdf.travel_time.function.VolumeDelayFunction;
1212
import org.matsim.api.core.v01.network.Network;
1313
import org.matsim.core.config.ConfigGroup;
1414
import org.matsim.core.config.groups.QSimConfigGroup;

vdf/src/main/java/org/eqasim/vdf/VDFQSimModule.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/VDFQSimModule.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package org.eqasim.vdf;
1+
package org.eqasim.core.simulation.vdf;
22

3-
import org.eqasim.vdf.travel_time.VDFLinkSpeedCalculator;
4-
import org.eqasim.vdf.travel_time.VDFTravelTime;
3+
import org.eqasim.core.simulation.vdf.travel_time.VDFLinkSpeedCalculator;
4+
import org.eqasim.core.simulation.vdf.travel_time.VDFTravelTime;
55
import org.matsim.api.core.v01.Scenario;
66
import org.matsim.api.core.v01.population.Population;
77
import org.matsim.core.api.experimental.events.EventsManager;

vdf/src/main/java/org/eqasim/vdf/VDFScope.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/VDFScope.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf;
1+
package org.eqasim.core.simulation.vdf;
22

33
import java.util.List;
44

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf;
1+
package org.eqasim.core.simulation.vdf;
22

33
import java.io.File;
44
import java.io.IOException;
@@ -7,9 +7,9 @@
77

88
import org.apache.logging.log4j.LogManager;
99
import org.apache.logging.log4j.Logger;
10-
import org.eqasim.vdf.analysis.FlowWriter;
11-
import org.eqasim.vdf.handlers.VDFTrafficHandler;
12-
import org.eqasim.vdf.travel_time.VDFTravelTime;
10+
import org.eqasim.core.simulation.vdf.analysis.FlowWriter;
11+
import org.eqasim.core.simulation.vdf.handlers.VDFTrafficHandler;
12+
import org.eqasim.core.simulation.vdf.travel_time.VDFTravelTime;
1313
import org.matsim.api.core.v01.IdMap;
1414
import org.matsim.api.core.v01.network.Link;
1515
import org.matsim.api.core.v01.network.Network;

vdf/src/main/java/org/eqasim/vdf/analysis/FlowWriter.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/analysis/FlowWriter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.analysis;
1+
package org.eqasim.core.simulation.vdf.analysis;
22

33
import java.io.BufferedWriter;
44
import java.io.File;
@@ -8,7 +8,7 @@
88
import java.util.List;
99
import java.util.Map;
1010

11-
import org.eqasim.vdf.VDFScope;
11+
import org.eqasim.core.simulation.vdf.VDFScope;
1212
import org.matsim.api.core.v01.Id;
1313
import org.matsim.api.core.v01.IdMap;
1414
import org.matsim.api.core.v01.network.Link;

vdf/src/main/java/org/eqasim/vdf/engine/VDFEngine.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/engine/VDFEngine.java

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package org.eqasim.vdf.engine;
1+
package org.eqasim.core.simulation.vdf.engine;
22

33
import java.util.ArrayList;
44
import java.util.Collection;
55
import java.util.Comparator;
66
import java.util.List;
77
import java.util.PriorityQueue;
88

9-
import org.eqasim.vdf.handlers.VDFTrafficHandler;
10-
import org.eqasim.vdf.travel_time.VDFTravelTime;
9+
import org.eqasim.core.simulation.vdf.handlers.VDFTrafficHandler;
10+
import org.eqasim.core.simulation.vdf.travel_time.VDFTravelTime;
1111
import org.matsim.api.core.v01.Id;
1212
import org.matsim.api.core.v01.events.LinkEnterEvent;
1313
import org.matsim.api.core.v01.events.LinkLeaveEvent;
@@ -56,9 +56,8 @@ public VDFEngine(Collection<String> modes, VDFTravelTime travelTime, Network net
5656

5757
@Override
5858
public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> linkId) {
59-
Leg leg = (Leg) ((PlanAgent) agent).getCurrentPlanElement();
60-
61-
if (!modes.contains(leg.getMode())) {
59+
String legMode = agent.getMode();
60+
if(!modes.contains(legMode)) {
6261
return false;
6362
}
6463

@@ -74,13 +73,19 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> linkId) {
7473
traversal.agent = (MobsimDriverAgent) agent;
7574
traversal.linkId = agent.getCurrentLinkId();
7675
traversal.arrivalTime = now + getTraversalTime(now, linkId, driverAgent);
77-
traversal.modeIndex = modes.indexOf(leg.getMode());
76+
traversal.modeIndex = modes.indexOf(legMode);
7877
traversals.add(traversal);
7978

8079
eventsManager.processEvent(new VehicleEntersTrafficEvent(now, traversal.agent.getId(), traversal.linkId,
8180
Id.createVehicleId(agent.getId()), modes.get(traversal.modeIndex), 1.0));
8281
} else { // We have a handler and register traversals directly
83-
NetworkRoute route = (NetworkRoute) leg.getRoute();
82+
NetworkRoute route;
83+
if(agent instanceof PlanAgent planAgent) {
84+
Leg leg = (Leg) planAgent.getCurrentPlanElement();
85+
route = (NetworkRoute) leg.getRoute();
86+
} else {
87+
throw new IllegalStateException("generateNetworkEvents is set to false while some agents to be processed by the VDF engine are not planAgent instances. Set generateNetworkEvents to false to fix this");
88+
}
8489
now += getTraversalTime(now, route.getStartLinkId(), driverAgent);
8590

8691
for (Id<Link> nextLinkId : route.getLinkIds()) {
@@ -92,7 +97,7 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> linkId) {
9297
traversal.agent = (MobsimDriverAgent) agent;
9398
traversal.linkId = route.getEndLinkId();
9499
traversal.arrivalTime = now;
95-
traversal.modeIndex = modes.indexOf(leg.getMode());
100+
traversal.modeIndex = modes.indexOf(legMode);
96101
traversal.distance = route.getDistance();
97102
traversals.add(traversal);
98103
}
@@ -161,7 +166,12 @@ public void afterSim() {
161166
}
162167

163168
double getTraversalTime(double now, Id<Link> linkId, MobsimDriverAgent agent) {
164-
Person person = ((HasPerson) agent).getPerson();
169+
// The current VDF travel time does not need a person object.
170+
// We just pass one to respect the interface.
171+
Person person = null;
172+
if(agent instanceof HasPerson hasPerson) {
173+
person = hasPerson.getPerson();
174+
}
165175
Vehicle vehicle = null; // agent.getVehicle().getVehicle();
166176
Link link = network.getLinks().get(linkId);
167177

vdf/src/main/java/org/eqasim/vdf/engine/VDFEngineConfigGroup.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/engine/VDFEngineConfigGroup.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package org.eqasim.vdf.engine;
1+
package org.eqasim.core.simulation.vdf.engine;
22

33
import java.util.Arrays;
4+
import java.util.HashSet;
45
import java.util.Set;
56

67
import org.matsim.api.core.v01.TransportMode;
@@ -13,7 +14,7 @@ public class VDFEngineConfigGroup extends ReflectiveConfigGroup {
1314
static private final String MODES = "modes";
1415
static private final String GENERATE_NETWORK_EVENTS = "generateNetworkEvents";
1516

16-
private Set<String> modes = Set.of(TransportMode.car);
17+
private Set<String> modes = new HashSet<>(Set.of(TransportMode.car));
1718

1819
private boolean generateNetworkEvents = true;
1920

vdf/src/main/java/org/eqasim/vdf/engine/VDFEngineModule.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/engine/VDFEngineModule.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package org.eqasim.vdf.engine;
1+
package org.eqasim.core.simulation.vdf.engine;
22

3-
import org.eqasim.vdf.handlers.VDFTrafficHandler;
4-
import org.eqasim.vdf.travel_time.VDFTravelTime;
3+
import org.eqasim.core.simulation.vdf.handlers.VDFTrafficHandler;
4+
import org.eqasim.core.simulation.vdf.travel_time.VDFTravelTime;
55
import org.matsim.api.core.v01.network.Network;
66
import org.matsim.core.controler.AbstractModule;
77
import org.matsim.core.mobsim.qsim.AbstractQSimModule;

vdf/src/main/java/org/eqasim/vdf/handlers/VDFHorizonHandler.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/handlers/VDFHorizonHandler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.handlers;
1+
package org.eqasim.core.simulation.vdf.handlers;
22

33
import java.io.DataInputStream;
44
import java.io.DataOutputStream;
@@ -15,9 +15,9 @@
1515

1616
import org.apache.logging.log4j.LogManager;
1717
import org.apache.logging.log4j.Logger;
18-
import org.eqasim.vdf.VDFScope;
19-
import org.eqasim.vdf.io.VDFReaderInterface;
20-
import org.eqasim.vdf.io.VDFWriterInterface;
18+
import org.eqasim.core.simulation.vdf.VDFScope;
19+
import org.eqasim.core.simulation.vdf.io.VDFReaderInterface;
20+
import org.eqasim.core.simulation.vdf.io.VDFWriterInterface;
2121
import org.matsim.api.core.v01.Id;
2222
import org.matsim.api.core.v01.IdMap;
2323
import org.matsim.api.core.v01.events.LinkEnterEvent;

vdf/src/main/java/org/eqasim/vdf/handlers/VDFInterpolationHandler.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/handlers/VDFInterpolationHandler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.handlers;
1+
package org.eqasim.core.simulation.vdf.handlers;
22

33
import java.io.DataInputStream;
44
import java.io.DataOutputStream;
@@ -10,9 +10,9 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212

13-
import org.eqasim.vdf.VDFScope;
14-
import org.eqasim.vdf.io.VDFReaderInterface;
15-
import org.eqasim.vdf.io.VDFWriterInterface;
13+
import org.eqasim.core.simulation.vdf.VDFScope;
14+
import org.eqasim.core.simulation.vdf.io.VDFReaderInterface;
15+
import org.eqasim.core.simulation.vdf.io.VDFWriterInterface;
1616
import org.matsim.api.core.v01.Id;
1717
import org.matsim.api.core.v01.IdMap;
1818
import org.matsim.api.core.v01.events.LinkEnterEvent;

vdf/src/main/java/org/eqasim/vdf/handlers/VDFTrafficHandler.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/handlers/VDFTrafficHandler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package org.eqasim.vdf.handlers;
1+
package org.eqasim.core.simulation.vdf.handlers;
22

33
import java.util.List;
44

5-
import org.eqasim.vdf.io.VDFReaderInterface;
6-
import org.eqasim.vdf.io.VDFWriterInterface;
5+
import org.eqasim.core.simulation.vdf.io.VDFReaderInterface;
6+
import org.eqasim.core.simulation.vdf.io.VDFWriterInterface;
77
import org.matsim.api.core.v01.Id;
88
import org.matsim.api.core.v01.IdMap;
99
import org.matsim.api.core.v01.network.Link;

vdf/src/main/java/org/eqasim/vdf/io/VDFReaderInterface.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/io/VDFReaderInterface.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.io;
1+
package org.eqasim.core.simulation.vdf.io;
22

33
import java.net.URL;
44

vdf/src/main/java/org/eqasim/vdf/io/VDFWriterInterface.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/io/VDFWriterInterface.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.io;
1+
package org.eqasim.core.simulation.vdf.io;
22

33
import java.io.File;
44

vdf/src/main/java/org/eqasim/vdf/travel_time/VDFLinkSpeedCalculator.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/travel_time/VDFLinkSpeedCalculator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.travel_time;
1+
package org.eqasim.core.simulation.vdf.travel_time;
22

33
import org.matsim.api.core.v01.network.Link;
44
import org.matsim.api.core.v01.population.Person;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.travel_time;
1+
package org.eqasim.core.simulation.vdf.travel_time;
22

33
import java.util.ArrayList;
44
import java.util.Collections;
@@ -7,8 +7,8 @@
77

88
import org.apache.logging.log4j.LogManager;
99
import org.apache.logging.log4j.Logger;
10-
import org.eqasim.vdf.VDFScope;
11-
import org.eqasim.vdf.travel_time.function.VolumeDelayFunction;
10+
import org.eqasim.core.simulation.vdf.VDFScope;
11+
import org.eqasim.core.simulation.vdf.travel_time.function.VolumeDelayFunction;
1212
import org.matsim.api.core.v01.Id;
1313
import org.matsim.api.core.v01.IdMap;
1414
import org.matsim.api.core.v01.network.Link;

vdf/src/main/java/org/eqasim/vdf/travel_time/function/BPRFunction.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/travel_time/function/BPRFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.travel_time.function;
1+
package org.eqasim.core.simulation.vdf.travel_time.function;
22

33
import org.matsim.api.core.v01.network.Link;
44

vdf/src/main/java/org/eqasim/vdf/travel_time/function/VolumeDelayFunction.java renamed to core/src/main/java/org/eqasim/core/simulation/vdf/travel_time/function/VolumeDelayFunction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.eqasim.vdf.travel_time.function;
1+
package org.eqasim.core.simulation.vdf.travel_time.function;
22

33
import org.matsim.api.core.v01.network.Link;
44

0 commit comments

Comments
 (0)