Skip to content

Commit

Permalink
Merge branch 'develop' into feat/separate-travel-time-recording
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Nov 2, 2024
2 parents a833083 + cd8c1dd commit 2e8372d
Show file tree
Hide file tree
Showing 35 changed files with 330 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ static public void run(String[] args, EqasimConfigurator configurator, ConfigAda
.requireOptions("input-path", "output-path", "prefix") //
.build();

Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("input-path"), configurator.getConfigGroups());
configurator.addOptionalConfigGroups(config);
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("input-path"));
configurator.updateConfig(config);
adapter.accept(config, cmd.getOptionStrict("prefix"));

new ConfigWriter(config).write(cmd.getOptionStrict("output-path"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.eqasim.core.components.emissions;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
Expand All @@ -13,7 +12,6 @@
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Injector;
Expand All @@ -39,9 +37,9 @@ public static void main(String[] args) throws CommandLine.ConfigurationException
configurator = new EqasimConfigurator();
}

ConfigGroup[] configGroups = ArrayUtils.addAll(configurator.getConfigGroups(), new EmissionsConfigGroup());

Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), configGroups);
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
configurator.registerConfigGroup(new EmissionsConfigGroup(), false);
configurator.updateConfig(config);
cmd.applyConfiguration(config);

EmissionsConfigGroup emissionsConfig = (EmissionsConfigGroup) config.getModules().get("emissions");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.eqasim.core.components.emissions;

import org.apache.commons.lang3.ArrayUtils;
import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
import org.geotools.api.feature.simple.SimpleFeature;
import org.locationtech.jts.geom.Geometry;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.emissions.analysis.EmissionGridAnalyzer;
import org.matsim.contrib.emissions.utils.EmissionsConfigGroup;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.io.MatsimNetworkReader;
Expand All @@ -32,9 +29,8 @@ public static void main(String[] args) throws CommandLine.ConfigurationException
configurator = new EqasimConfigurator();
}

ConfigGroup[] configGroups = ArrayUtils.addAll(configurator.getConfigGroups(), new EmissionsConfigGroup());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;
import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
import org.geotools.api.feature.simple.SimpleFeature;
Expand All @@ -19,11 +18,9 @@
import org.matsim.contrib.emissions.analysis.EmissionsByPollutant;
import org.matsim.contrib.emissions.analysis.EmissionsOnLinkEventHandler;
import org.matsim.contrib.emissions.events.EmissionEventsReader;
import org.matsim.contrib.emissions.utils.EmissionsConfigGroup;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.events.EventsUtils;
import org.matsim.core.network.NetworkUtils;
Expand All @@ -49,9 +46,8 @@ public static void main(String[] args) throws CommandLine.ConfigurationException
configurator = new EqasimConfigurator();
}

ConfigGroup[] configGroups = ArrayUtils.addAll(configurator.getConfigGroups(), new EmissionsConfigGroup());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ static public void main(String[] args) throws ConfigurationException {
.build();

EqasimConfigurator configurator = new EqasimConfigurator();
Config config = ConfigUtils.createConfig(configurator.getConfigGroups());
Config config = ConfigUtils.createConfig();
configurator.updateConfig(config);

String prefix = cmd.getOptionStrict("prefix");
double sampleSize = Double.parseDouble(cmd.getOptionStrict("sample-size"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eqasim.core.scenario.validation.VehiclesValidator;
import org.eqasim.core.simulation.EqasimConfigurator;
import org.eqasim.core.simulation.mode_choice.AbstractEqasimExtension;
import org.eqasim.core.simulation.termination.EqasimTerminationModule;
import org.eqasim.core.simulation.termination.EqasimTerminationConfigGroup;
import org.matsim.api.core.v01.Scenario;
import org.matsim.contribs.discrete_mode_choice.modules.DiscreteModeChoiceModule;
import org.matsim.core.config.CommandLine;
Expand Down Expand Up @@ -71,9 +71,9 @@ static public void main(String[] args) throws ConfigurationException, IOExceptio

// Load scenario
EqasimConfigurator configurator = new EqasimConfigurator();
configurator.getModules().removeIf(m -> m instanceof EqasimTerminationModule);

Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), configurator.getConfigGroups());
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
configurator.updateConfig(config);
config.removeModule(EqasimTerminationConfigGroup.GROUP_NAME);
cmd.applyConfiguration(config);

VehiclesValidator.validate(config);
Expand Down Expand Up @@ -111,7 +111,7 @@ static public void main(String[] args) throws ConfigurationException, IOExceptio

// Cut population
Injector populationCutterInjector = new InjectorBuilder(scenario) //
.addOverridingModules(configurator.getModules().stream()
.addOverridingModules(configurator.getModules(config).stream()
.filter(module -> !(module instanceof AbstractEqasimExtension) && !(module instanceof DiscreteModeChoiceModule)).toList()) //
.addOverridingModule(
new PopulationCutterModule(extent, numberOfThreads, 40, cmd.getOption("events-path"))) //
Expand Down Expand Up @@ -162,14 +162,15 @@ static public void main(String[] args) throws ConfigurationException, IOExceptio

// "Cut" config
// (we need to reload it, because it has become locked at this point)
config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), configurator.getConfigGroups());
config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
configurator.updateConfig(config);
cmd.applyConfiguration(config);
ConfigCutter configCutter = new ConfigCutter(prefix);
configCutter.run(config);

// Final routing
Injector routingInjector = new InjectorBuilder(scenario) //
.addOverridingModules(configurator.getModules().stream()
.addOverridingModules(configurator.getModules(config).stream()
.filter(module -> !(module instanceof AbstractEqasimExtension) && !(module instanceof DiscreteModeChoiceModule)).toList()) //
.addOverridingModule(new PopulationRouterModule(numberOfThreads, 100, false)) //
.addOverridingModule(new CutterTravelTimeModule(travelTime)) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ static public void main(String[] args)
String outputPath = cmd.getOptionStrict("output-path");

EqasimConfigurator eqasimConfigurator = new EqasimConfigurator();
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), eqasimConfigurator.getConfigGroups());
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
eqasimConfigurator.updateConfig(config);
cmd.applyConfiguration(config);
eqasimConfigurator.addOptionalConfigGroups(config);

if(!config.getModules().containsKey(VDFConfigGroup.GROUP_NAME) || !config.getModules().containsKey(VDFEngineConfigGroup.GROUP_NAME)) {
throw new IllegalStateException(String.format("This scenario cutter only works with configs where both '%s' and '%s' modules are used", VDFConfigGroup.GROUP_NAME, VDFEngineConfigGroup.GROUP_NAME));
Expand Down Expand Up @@ -126,9 +126,9 @@ static public void main(String[] args)

// "Cut" config
// (we need to reload it, because it has become locked at this point)
config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), eqasimConfigurator.getConfigGroups());
config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
eqasimConfigurator.updateConfig(config);
cmd.applyConfiguration(config);
eqasimConfigurator.addOptionalConfigGroups(config);
ConfigCutter configCutter = new ConfigCutter(prefix);
configCutter.run(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ static public void main(String[] args) throws ConfigurationException, Interrupte
.build();

EqasimConfigurator configurator = new EqasimConfigurator();
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), configurator.getConfigGroups());
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
configurator.updateConfig(config);
config.getModules().remove(EqasimTerminationConfigGroup.GROUP_NAME);
configurator.addOptionalConfigGroups(config);
cmd.applyConfiguration(config);
config.replanning().clearStrategySettings();
VehiclesValidator.validate(config);
Expand Down Expand Up @@ -59,7 +59,7 @@ static public void main(String[] args) throws ConfigurationException, Interrupte
}

Injector injector = new InjectorBuilder(scenario) //
.addOverridingModules(configurator.getModules().stream()
.addOverridingModules(configurator.getModules(config).stream()
.filter(module -> !(module instanceof AbstractEqasimExtension)) //
.filter(module -> !(module instanceof DiscreteModeChoiceModule)).toList()) //
.addOverridingModule(new PopulationRouterModule(numberOfThreads, batchSize, true, modes)) //
Expand Down
Loading

0 comments on commit 2e8372d

Please sign in to comment.