Skip to content

feat: adding the script to run switzerland with vdf #319

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

Merged
merged 2 commits into from
Apr 4, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ included in the (note yet determined) next version number.
- Switched to MATSim 2025 (PR)
- In switzerland one can now switch off vehicles waiting to enter traffic
- In swiss module: adjusted the adapt config to allow parametrizing capacity factors and freight in config
- In swiss module: added vehicles to chonfig
- In swiss module: adding the possibility to run a simulation with VDF

**1.5.0**

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.eqasim.switzerland;

import java.util.HashSet;
import java.util.Set;

import org.eqasim.core.simulation.vdf.VDFConfigGroup;
import org.eqasim.core.simulation.vdf.engine.VDFEngineConfigGroup;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.CommandLine.ConfigurationException;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.scenario.ScenarioUtils;

public class RunVDFSimulation {
static public void main(String[] args) throws ConfigurationException {
// set preventwaitingtoentertraffic to y if you want to to prevent that waiting
// traffic has to wait for space in the link buffer
// this is especially important to avoid high waiting times when we cutout
// scenarios from a larger scenario.
CommandLine cmd = new CommandLine.Builder(args) //
.requireOptions("config-path") //
.allowPrefixes("mode-parameter", "cost-parameter", "preventwaitingtoentertraffic") //
.build();

SwitzerlandConfigurator configurator = new SwitzerlandConfigurator(cmd);
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
configurator.updateConfig(config);
cmd.applyConfiguration(config);

if (cmd.hasOption("preventwaitingtoentertraffic")) {
if (cmd.getOption("preventwaitingtoentertraffic").get().equals("y")) {
((QSimConfigGroup) config.getModules().get(QSimConfigGroup.GROUP_NAME))
.setPcuThresholdForFlowCapacityEasing(1.0);
}
}

// VDF: Add config group
config.addModule(new VDFConfigGroup());

// VDF: Set capacity factor instead (~0.1 for a 10% simulation in theory... any
// better advice?)
// we can use the same as for the queue logic
VDFConfigGroup.getOrCreate(config).setCapacityFactor(
((QSimConfigGroup) config.getModules().get(QSimConfigGroup.GROUP_NAME)).getFlowCapFactor());

// VDF: Disable queue logic
config.qsim().setFlowCapFactor(1e9);

// maybe we do not want to disable storage capacity logic
// as we might want to have some back propagation delays
config.qsim().setStorageCapFactor(1e9);

// VDF: Optional
VDFConfigGroup.getOrCreate(config).setWriteInterval(1);
VDFConfigGroup.getOrCreate(config).setWriteFlowInterval(1);

// VDF Engine: Add config group
config.addModule(new VDFEngineConfigGroup());

// VDF Engine: Decide whether to genertae link events or not
VDFEngineConfigGroup.getOrCreate(config).setGenerateNetworkEvents(false);

// VDF Engine: Remove car from main modes
Set<String> mainModes = new HashSet<>(config.qsim().getMainModes());
mainModes.remove("car");
config.qsim().setMainModes(mainModes);

Scenario scenario = ScenarioUtils.createScenario(config);
configurator.configureScenario(scenario);
ScenarioUtils.loadScenario(scenario);
configurator.adjustScenario(scenario);

Controler controller = new Controler(scenario);
configurator.configureController(controller);
controller.run();
}
}