Skip to content

Commit 2f5e3c3

Browse files
authored
RunStandaloneModeChoice can now use travel times recorded by VDF (#262)
1 parent dc15b31 commit 2f5e3c3

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

core/src/main/java/org/eqasim/core/standalone_mode_choice/RunStandaloneModeChoice.java

+21-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.List;
1616
import java.util.Optional;
1717

18+
import org.apache.logging.log4j.LogManager;
19+
import org.apache.logging.log4j.Logger;
1820
import org.eqasim.core.analysis.DistanceUnit;
1921
import org.eqasim.core.analysis.PersonAnalysisFilter;
2022
import org.eqasim.core.analysis.pt.PublicTransportLegItem;
@@ -26,10 +28,11 @@
2628
import org.eqasim.core.components.travel_time.RecordedTravelTime;
2729
import org.eqasim.core.misc.ClassUtils;
2830
import org.eqasim.core.misc.InjectorBuilder;
29-
import org.eqasim.core.scenario.routing.RunPopulationRouting;
3031
import org.eqasim.core.scenario.validation.ScenarioValidator;
3132
import org.eqasim.core.scenario.validation.VehiclesValidator;
3233
import org.eqasim.core.simulation.EqasimConfigurator;
34+
import org.eqasim.core.simulation.vdf.VDFConfigGroup;
35+
import org.eqasim.core.simulation.vdf.VDFUpdateListener;
3336
import org.matsim.api.core.v01.Scenario;
3437
import org.matsim.api.core.v01.network.Link;
3538
import org.matsim.api.core.v01.population.Person;
@@ -46,10 +49,8 @@
4649
import org.matsim.pt.transitSchedule.api.TransitSchedule;
4750
import org.matsim.vehicles.Vehicle;
4851

49-
import com.google.inject.Key;
5052
import com.google.inject.Provides;
5153
import com.google.inject.Singleton;
52-
import com.google.inject.name.Names;
5354

5455
/**
5556
* This class offers the functionality of running the discrete mode choice model on the whole population without having to go through the whole iterative MATSim process. It is also possible to filter-out the persons that do not have a valid alternative.
@@ -131,6 +132,8 @@ public double getLinkTravelTime(Link link, double time, Person person, Vehicle v
131132
}
132133

133134

135+
private static final Logger logger = LogManager.getLogger(RunStandaloneModeChoice.class);
136+
134137
public static final String CMD_WRITE_INPUT_CSV = "write-input-csv-trips";
135138
public static final String CMD_WRITE_OUTPUT_CSV = "write-output-csv-trips";
136139
public static final String CMD_SIMULATE_AFTER = "simulate-after";
@@ -224,6 +227,16 @@ RecordedTravelTime provideRecordedTravelTime() {
224227
}
225228
}));
226229

230+
boolean usingVdfTravelTime = false;
231+
if(config.getModules().containsKey(VDFConfigGroup.GROUP_NAME) && VDFConfigGroup.getOrCreate(config).getInputFile() != null) {
232+
String usedTravelTimeArg = recordedTravelTimesPath.isPresent() ? CMD_RECORDED_TRAVEL_TIMES_PATH : travelTimesFactorsPath.isPresent() ? CMD_TRAVEL_TIMES_FACTORS_PATH : null;
233+
if(usedTravelTimeArg == null) {
234+
usingVdfTravelTime = true;
235+
} else {
236+
logger.warn(String.format("Using '%s', the input file for the '%s' config group will not be considered", usedTravelTimeArg, VDFConfigGroup.GROUP_NAME));
237+
}
238+
}
239+
227240
com.google.inject.Injector injector = injectorBuilder.build();
228241

229242

@@ -240,6 +253,11 @@ RecordedTravelTime provideRecordedTravelTime() {
240253
}
241254
});
242255

256+
if(usingVdfTravelTime) {
257+
VDFUpdateListener vdfUpdateListener = injector.getInstance(VDFUpdateListener.class);
258+
vdfUpdateListener.notifyStartup(null);
259+
}
260+
243261
StandaloneModeChoicePerformer modeChoicePerformer = injector.getInstance(StandaloneModeChoicePerformer.class);
244262

245263
modeChoicePerformer.run();

core/src/main/java/org/eqasim/core/standalone_mode_choice/StandaloneModeChoiceConfigurator.java

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.eqasim.core.analysis.PersonAnalysisFilter;
55
import org.eqasim.core.simulation.EqasimConfigurator;
66
import org.eqasim.core.simulation.termination.EqasimTerminationModule;
7+
import org.eqasim.core.simulation.vdf.VDFConfigGroup;
8+
import org.eqasim.core.simulation.vdf.VDFModule;
79
import org.matsim.core.config.CommandLine;
810
import org.matsim.core.config.Config;
911
import org.matsim.core.config.ConfigGroup;
@@ -27,6 +29,8 @@ public StandaloneModeChoiceConfigurator(Config config, CommandLine commandLine)
2729
this.config = config;
2830
this.commandLine = commandLine;
2931
this.optionalModules = new LinkedHashMap<>();
32+
33+
this.registerOptionalModule(new VDFConfigGroup(), new VDFModule());
3034
}
3135

3236
public Config getConfig() {

core/src/test/java/org/eqasim/TestSimulationPipeline.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public void testTransitWithAbstractAccess() throws CommandLine.ConfigurationExce
369369
runMelunSimulation("melun_test/input/config_abstract_access.xml", "melun_test/output_abstract_access");
370370
}
371371

372-
public void runVdf() throws CommandLine.ConfigurationException, IOException {
372+
public void runVdf() throws CommandLine.ConfigurationException, IOException, InterruptedException {
373373
AdaptConfigForVDF.main(new String[] {
374374
"--input-config-path", "melun_test/input/config.xml",
375375
"--output-config-path", "melun_test/input/config_vdf.xml",
@@ -380,6 +380,14 @@ public void runVdf() throws CommandLine.ConfigurationException, IOException {
380380

381381
runMelunSimulation("melun_test/input/config_vdf.xml", "melun_test/output_vdf");
382382

383+
RunStandaloneModeChoice.main(new String[]{
384+
"--config-path", "melun_test/input/config_vdf.xml",
385+
"--config:standaloneModeChoice.outputDirectory", "melun_test/output_mode_choice_vdf",
386+
"--config:eqasim:vdf.inputFile", "../output_vdf/vdf.bin", // Relative to the config file
387+
"--mode-choice-configurator-class", TestModeChoiceConfigurator.class.getName(),
388+
"--simulate-after", TestRunSimulation.class.getName()
389+
});
390+
383391
CreateDrtVehicles.main(new String[]{
384392
"--network-path", "melun_test/input/network.xml.gz",
385393
"--output-vehicles-path", "melun_test/input/drt_vehicles.xml.gz",

docs/standalone_mode_choice.md

+5
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ More parameters can be supplied via the command line:
2727
In order to fully use it in your own use case, you need to implement a class extending the `StandaloneModeChoiceModule` class, your extension must have a constructor that matches the signature of the constructor present in the base class (taking a `Config` and a `CommandLine` as parameters).
2828
Then, override the `getSpecificModeChoiceModules` to return the modules necessary to configure the mode choice model only.
2929

30+
**Note: Using travel times recorded by the VDFModule**
31+
32+
If your scenario has been simulated before using the VDF functionality and want to use the travel times recorded by the VDFModule (usually in a vdf.bin file), you need to call the `RunStandaloneModeCHoice` with a config file where the `eqasim:vdf` module is configured with the `inputFile` pointing to the file you want to use. Moreover, you must not pass `travel-times-factors-path` or `recorded-travel-times-path` arguments.
33+
34+
3035
For more details, you can check how this functionality is used in `org.eqasim.TestSimulationPipeline#TestPipeline()` and in `org.eqasim.ile_de_france.TestCorisica#testCorsicaPipeline()`.

0 commit comments

Comments
 (0)