Skip to content

Commit

Permalink
Update to MATSim 2025 (#178)
Browse files Browse the repository at this point in the history
* fixing imports

* update IdF emission to matsim 15 (#175)

* update workflow version

* update to a recent PR of MATSim 16

* MATSim 2025

* add additional test values

* add test for emission events

* ignoring test on number of lines in shapefile

* fix after merge

---------

Co-authored-by: Valentin LE BESCOND <[email protected]>
  • Loading branch information
sebhoerl and Nitnelav authored Apr 21, 2024
1 parent 35a595b commit 33badde
Show file tree
Hide file tree
Showing 37 changed files with 595 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void install(){
com.google.inject.Injector injector = Injector.createInjector(config, module );
EmissionModule emissionModule = injector.getInstance(EmissionModule.class);

final String outputDirectory = scenario.getConfig().controler().getOutputDirectory() + "/";
final String outputDirectory = scenario.getConfig().controller().getOutputDirectory() + "/";
EventWriterXML emissionEventWriter = new EventWriterXML( outputDirectory + "output_emissions_events.xml.gz" ) ;
emissionModule.getEmissionEventsManager().addHandler(emissionEventWriter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(String[] args) throws CommandLine.ConfigurationException

Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), configGroups);
cmd.applyConfiguration(config);
final String outputDirectory = config.controler().getOutputDirectory() + "/";
final String outputDirectory = config.controller().getOutputDirectory() + "/";

Network network = NetworkUtils.createNetwork();
new MatsimNetworkReader(network).readFile(outputDirectory + "output_network.xml.gz");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void main(String[] args) throws CommandLine.ConfigurationException

Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), configGroups);
cmd.applyConfiguration(config);
final String outputDirectory = config.controler().getOutputDirectory() + "/";
final String outputDirectory = config.controller().getOutputDirectory() + "/";

int timeBinSize = Integer.parseInt(cmd.getOption("time-bin-size").orElse("3600"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.LinkSpeedCalculator;

public class EqasimLinkSpeedCalculator implements LinkSpeedCalculator {
final private LinkSpeedCalculator delegate;
final private double crossingPenalty;

public EqasimLinkSpeedCalculator(LinkSpeedCalculator delegate, double crossingPenalty) {
this.delegate = delegate;
public EqasimLinkSpeedCalculator(double crossingPenalty) {
this.crossingPenalty = crossingPenalty;
}

Expand All @@ -23,10 +21,12 @@ public double getMaximumVelocity(QVehicle vehicle, Link link, double time) {
}
}

double maximumVelocity = Math.min(vehicle.getMaximumVelocity(), link.getFreespeed(time));

if (isMajor || link.getToNode().getInLinks().size() == 1) {
return delegate.getMaximumVelocity(vehicle, link, time);
return maximumVelocity;
} else {
double travelTime = link.getLength() / delegate.getMaximumVelocity(vehicle, link, time);
double travelTime = link.getLength() / maximumVelocity;
travelTime += crossingPenalty;
return link.getLength() / travelTime;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
package org.eqasim.core.components.traffic;

import org.eqasim.core.components.config.EqasimConfigGroup;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.mobsim.qsim.AbstractQSimModule;
import org.matsim.core.mobsim.qsim.qnetsimengine.ConfigurableQNetworkFactory;
import org.matsim.core.mobsim.qsim.qnetsimengine.QNetworkFactory;
import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.DefaultLinkSpeedCalculator;
import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.LinkSpeedCalculator;

import com.google.inject.Provides;
import com.google.inject.Singleton;

public class EqasimTrafficQSimModule extends AbstractQSimModule {
@Override
protected void configureQSim() {

}

@Provides
@Singleton
public QNetworkFactory provideQNetworkFactory(EventsManager events, Scenario scenario,
EqasimLinkSpeedCalculator linkSpeedCalculator) {
ConfigurableQNetworkFactory networkFactory = new ConfigurableQNetworkFactory(events, scenario);
networkFactory.setLinkSpeedCalculator(linkSpeedCalculator);
return networkFactory;
bind(LinkSpeedCalculator.class).to(EqasimLinkSpeedCalculator.class);
}

@Provides
@Singleton
public EqasimLinkSpeedCalculator provideBaselineLinkSpeedCalculator(EqasimConfigGroup eqasimConfig) {
DefaultLinkSpeedCalculator delegate = new DefaultLinkSpeedCalculator();
return new EqasimLinkSpeedCalculator(delegate, eqasimConfig.getCrossingPenalty());
return new EqasimLinkSpeedCalculator(eqasimConfig.getCrossingPenalty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.CommandLine.ConfigurationException;
import org.matsim.core.config.Config;
import org.matsim.core.config.groups.ControlerConfigGroup.RoutingAlgorithmType;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ActivityParams;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ModeParams;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup.AccessEgressType;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup.ModeRoutingParams;
import org.matsim.core.config.groups.ControllerConfigGroup.RoutingAlgorithmType;
import org.matsim.core.config.groups.PlansConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup.AccessEgressType;
import org.matsim.core.config.groups.RoutingConfigGroup.TeleportedModeParams;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams;
import org.matsim.core.config.groups.ScoringConfigGroup.ModeParams;
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;

public class GenerateConfig {
Expand Down Expand Up @@ -61,17 +61,17 @@ public GenerateConfig(CommandLine cmd, String prefix, double sampleSize, int ran
protected void adaptConfiguration(Config config) {
// General settings

config.controler().setFirstIteration(0);
config.controler().setLastIteration(DEFAULT_ITERATIONS);
config.controler().setWriteEventsInterval(DEFAULT_ITERATIONS);
config.controler().setWritePlansInterval(DEFAULT_ITERATIONS);
config.controler().setOutputDirectory("simulation_output");
config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setFirstIteration(0);
config.controller().setLastIteration(DEFAULT_ITERATIONS);
config.controller().setWriteEventsInterval(DEFAULT_ITERATIONS);
config.controller().setWritePlansInterval(DEFAULT_ITERATIONS);
config.controller().setOutputDirectory("simulation_output");
config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);

config.global().setRandomSeed(randomSeed);
config.global().setNumberOfThreads(threads);

config.controler().setRoutingAlgorithmType(RoutingAlgorithmType.FastAStarLandmarks);
config.controller().setRoutingAlgorithmType(RoutingAlgorithmType.SpeedyALT);

config.transit().setUseTransit(true);

Expand All @@ -92,7 +92,7 @@ protected void adaptConfiguration(Config config) {
terminationConfig.setModes(MODES);

// Scoring config
PlanCalcScoreConfigGroup scoringConfig = config.planCalcScore();
ScoringConfigGroup scoringConfig = config.scoring();

scoringConfig.setMarginalUtilityOfMoney(0.0);
scoringConfig.setMarginalUtlOfWaitingPt_utils_hr(0.0);
Expand All @@ -102,7 +102,7 @@ protected void adaptConfiguration(Config config) {

if (activityParams == null) {
activityParams = new ActivityParams(activityType);
config.planCalcScore().addActivityParams(activityParams);
config.scoring().addActivityParams(activityParams);
}

activityParams.setScoringThisActivityAtAll(false);
Expand All @@ -121,22 +121,22 @@ protected void adaptConfiguration(Config config) {
}

// Routing configuration
PlansCalcRouteConfigGroup routingConfig = config.plansCalcRoute();
RoutingConfigGroup routingConfig = config.routing();

config.plansCalcRoute().setNetworkModes(NETWORK_MODES);
config.routing().setNetworkModes(NETWORK_MODES);

config.plansCalcRoute().setAccessEgressType(AccessEgressType.accessEgressModeToLink);
config.plansCalcRoute().setRoutingRandomness(0.0);
config.routing().setAccessEgressType(AccessEgressType.accessEgressModeToLink);
config.routing().setRoutingRandomness(0.0);

ModeRoutingParams outsideParams = routingConfig.getOrCreateModeRoutingParams("outside");
TeleportedModeParams outsideParams = routingConfig.getOrCreateModeRoutingParams("outside");
outsideParams.setBeelineDistanceFactor(1.0);
outsideParams.setTeleportedModeSpeed(1000.0);

ModeRoutingParams bikeParams = routingConfig.getOrCreateModeRoutingParams(TransportMode.bike);
TeleportedModeParams bikeParams = routingConfig.getOrCreateModeRoutingParams(TransportMode.bike);
bikeParams.setBeelineDistanceFactor(1.4);
bikeParams.setTeleportedModeSpeed(3.1); // 11.6 km/h

ModeRoutingParams walkParams = routingConfig.getOrCreateModeRoutingParams(TransportMode.walk);
TeleportedModeParams walkParams = routingConfig.getOrCreateModeRoutingParams(TransportMode.walk);
walkParams.setBeelineDistanceFactor(1.3);
walkParams.setTeleportedModeSpeed(1.2); // 4.32 km/h

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -19,7 +20,6 @@
import org.matsim.core.network.io.MatsimNetworkReader;
import org.matsim.core.network.io.NetworkWriter;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.UncheckedIOException;

public class RunNetworkCutter {
static public void main(String[] args) throws MalformedURLException, IOException, InterruptedException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Population;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup.ModeRoutingParams;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup.TeleportedModeParams;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.events.EventsUtils;
import org.matsim.core.events.MatsimEventsReader;
Expand Down Expand Up @@ -77,12 +77,12 @@ PopulationCutter providePopulationCutter(Provider<PlanCutter> planCutterProvider
return new PopulationCutter(planCutterProvider, population.getFactory(), numberOfThreads, batchSize);
}

private Collection<String> getTeleportedModes(PlansCalcRouteConfigGroup routingConfig) {
private Collection<String> getTeleportedModes(RoutingConfigGroup routingConfig) {
Collection<String> teleportedModes = new HashSet<>();

for (Map.Entry<String, ModeRoutingParams> entry : routingConfig.getModeRoutingParams().entrySet()) {
for (Map.Entry<String, TeleportedModeParams> entry : routingConfig.getTeleportedModeParams().entrySet()) {
String mode = entry.getKey();
ModeRoutingParams params = entry.getValue();
TeleportedModeParams params = entry.getValue();

if (params.getTeleportedModeFreespeedFactor() != null) {
throw new IllegalStateException("Cutter does not support teleportedModeFreespeedFactor yet!");
Expand Down Expand Up @@ -113,7 +113,7 @@ private boolean checkDisjoint(Collection<String> a, Collection<String> b) {
}

@Provides
public ModeAwareTripProcessor provideModeAwareTripProcessor(PlansCalcRouteConfigGroup routingConfig,
public ModeAwareTripProcessor provideModeAwareTripProcessor(RoutingConfigGroup routingConfig,
TransitConfigGroup transitConfig, ScenarioExtent extent,
TeleportationTripProcessor teleportationTripProcessor, NetworkTripProcessor networkTripProcessor,
TransitTripProcessor transitTripProcessor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static public void main(String[] args) throws ConfigurationException, Interrupte
config.getModules().remove(EqasimTerminationConfigGroup.GROUP_NAME);
configurator.addOptionalConfigGroups(config);
cmd.applyConfiguration(config);
config.strategy().clearStrategySettings();
config.replanning().clearStrategySettings();

int batchSize = cmd.getOption("batch-size").map(Integer::parseInt).orElse(100);
int numberOfThreads = cmd.getOption("threads").map(Integer::parseInt)
Expand Down Expand Up @@ -90,7 +90,7 @@ static public void insertVehicles(Config config, Scenario scenario) {
for (Person person : scenario.getPopulation().getPersons().values()) {
Map<String, Id<Vehicle>> personVehicles = new HashMap<>();

for (String mode : config.plansCalcRoute().getNetworkModes()) {
for (String mode : config.routing().getNetworkModes()) {
Vehicle vehicle = factory.createVehicle(Id.createVehicleId(person.getId().toString() + ":" + mode),
VehicleUtils.getDefaultVehicleType());
vehicles.addVehicle(vehicle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.router.AnalysisMainModeIdentifier;
import org.matsim.core.router.RoutingModeMainModeIdentifier;
import org.matsim.pt.transitSchedule.api.TransitSchedule;

import com.google.inject.Provides;
Expand All @@ -31,6 +33,8 @@ public void install() {
}

install(new StuckAnalysisModule());

bind(AnalysisMainModeIdentifier.class).toInstance(new RoutingModeMainModeIdentifier());
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package org.eqasim.core.simulation.modes.drt.utils;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.eqasim.core.components.config.EqasimConfigGroup;
import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
Expand All @@ -17,16 +27,10 @@
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.utils.misc.Time;

import java.nio.file.Path;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class AdaptConfigForDrt {

public static void adapt(Config config, Map<String, String> vehiclesPathByDrtMode, Map<String, String> operationalSchemes, Map<String, String> drtUtilityEstimators, Map<String, String> drtCostModels, String qsimEndtime, String modeAvailability) {
Expand Down Expand Up @@ -86,11 +90,11 @@ public static void adapt(Config config, Map<String, String> vehiclesPathByDrtMod
eqasimConfig.setCostModel(drtMode, drtCostModels.get(drtMode));
eqasimConfig.setEstimator(drtMode, drtUtilityEstimators.get(drtMode));

PlanCalcScoreConfigGroup.ModeParams modeParams = new PlanCalcScoreConfigGroup.ModeParams(drtMode);
config.planCalcScore().addModeParams(modeParams);
ScoringConfigGroup.ModeParams modeParams = new ScoringConfigGroup.ModeParams(drtMode);
config.scoring().addModeParams(modeParams);
}

DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfigGroup, config.planCalcScore(), config.plansCalcRoute());
DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfigGroup, config.scoring(), config.routing());

// Additional requirements
config.qsim().setStartTime(0.0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package org.eqasim.core.simulation.modes.feeder_drt.utils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eqasim.core.components.config.EqasimConfigGroup;
import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
Expand All @@ -15,11 +22,9 @@
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.pt.config.TransitConfigGroup;

import java.util.*;

public class AdaptConfigForFeederDrt {

public static void adapt(Config config, Map<String, String> basePtModes, Map<String, String> baseDrtModes, Map<String, String> utilityEstimators, Map<String, String> accessEgressTransitStopModes, String modeAvailability) {
Expand Down Expand Up @@ -79,8 +84,8 @@ public static void adapt(Config config, Map<String, String> basePtModes, Map<Str

eqasimConfigGroup.setEstimator(feederDrtMode, utilityEstimators.get(feederDrtMode));

PlanCalcScoreConfigGroup.ActivityParams activityParams = new PlanCalcScoreConfigGroup.ActivityParams(feederDrtMode + " interaction");
config.planCalcScore().addActivityParams(activityParams);
ScoringConfigGroup.ActivityParams activityParams = new ScoringConfigGroup.ActivityParams(feederDrtMode + " interaction");
config.scoring().addActivityParams(activityParams);
activityParams.setTypicalDuration(1);
activityParams.setScoringThisActivityAtAll(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Map;

import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.groups.ControlerConfigGroup;
import org.matsim.core.config.groups.ControllerConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.controler.TerminationCriterion;
Expand All @@ -29,7 +29,7 @@ public void install() {

@Provides
@Singleton
EqasimTerminationCriterion provideEqasimTerminationCriterion(ControlerConfigGroup controllerConfig,
EqasimTerminationCriterion provideEqasimTerminationCriterion(ControllerConfigGroup controllerConfig,
Map<String, TerminationIndicatorSupplier> indicators, Map<String, TerminationCriterionCalculator> criteria,
TerminationWriter writer) {
EqasimTerminationConfigGroup terminationConfig = EqasimTerminationConfigGroup.getOrCreate(getConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static public void main(String[] args) throws ConfigurationException, Interrupte
EqasimConfigurator configurator = new EqasimConfigurator();
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), configurator.getConfigGroups());
cmd.applyConfiguration(config);
config.strategy().clearStrategySettings();
config.replanning().clearStrategySettings();

int batchSize = cmd.getOption("batch-size").map(Integer::parseInt).orElse(100);
int numberOfThreads = cmd.getOption("threads").map(Integer::parseInt)
Expand Down
Loading

0 comments on commit 33badde

Please sign in to comment.