Skip to content

Commit

Permalink
Merge pull request #15 from matsim-scenarios/update-matsim-version
Browse files Browse the repository at this point in the history
Update matsim version
  • Loading branch information
simei94 authored Oct 21, 2024
2 parents 89add22 + 5b46dba commit 47e7210
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!--<version>14.0-PR1452</version>-->

<!-- snapshot == not recommended: rather use PR-labelled release!-->
<version>2025.0-PR3496</version>
<version>2025.0-PR3515</version>
</parent>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public List<Dashboard> getDashboards(Config config, SimWrapper simWrapper) {
.setAnalysisArgs("--person-filter", "subpopulation=person");

return List.of(trips,
new EmissionsDashboard()
new EmissionsDashboard(config.global().getCoordinateSystem())
// the NoiseAnalysis is not run here because it needs more RAM than the entire simulation,
// which leads to VM crashes and prevents other analysis to run. We have to run it separately (e.g. with LausitzSimWrapperRunner)
);
Expand Down
45 changes: 41 additions & 4 deletions src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.application.ApplicationUtils;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.ShpOptions;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.run.prepare.PrepareNetwork;
import org.matsim.run.scenarios.LausitzScenario;
import org.matsim.simwrapper.Dashboard;
import org.matsim.simwrapper.SimWrapper;
import org.matsim.simwrapper.SimWrapperConfigGroup;
import org.matsim.simwrapper.dashboard.EmissionsDashboard;
import org.matsim.simwrapper.dashboard.NoiseDashboard;
import org.matsim.simwrapper.dashboard.TripDashboard;
import org.matsim.vehicles.MatsimVehicleWriter;
import picocli.CommandLine;

import java.io.IOException;
Expand All @@ -57,6 +64,8 @@ public final class LausitzSimWrapperRunner implements MATSimAppCommand {
private boolean noise;
@CommandLine.Option(names = "--trips", defaultValue = "false", description = "create trips dashboard")
private boolean trips;
@CommandLine.Option(names = "--emissions", defaultValue = "false", description = "create emission dashboard")
private boolean emissions;


public LausitzSimWrapperRunner(){
Expand All @@ -66,15 +75,15 @@ public LausitzSimWrapperRunner(){
@Override
public Integer call() throws Exception {

if (!noise && !trips){
if (!noise && !trips && !emissions){
throw new IllegalArgumentException("you have not configured any dashboard to be created! Please use command line parameters!");
}

for (Path runDirectory : inputPaths) {
log.info("Running on {}", runDirectory);

Path configPath = ApplicationUtils.matchInput("config.xml", runDirectory);
Config config = ConfigUtils.loadConfig(configPath.toString());
String configPath = ApplicationUtils.matchInput("config.xml", runDirectory).toString();
Config config = ConfigUtils.loadConfig(configPath);
SimWrapper sw = SimWrapper.create(config);

SimWrapperConfigGroup simwrapperCfg = ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class);
Expand All @@ -87,7 +96,7 @@ public Integer call() throws Exception {
//add dashboards according to command line parameters
// if more dashboards are to be added here, we need to check if noise==true before adding noise dashboard here
if (noise) {
sw.addDashboard(Dashboard.customize(new NoiseDashboard()).context("noise"));
sw.addDashboard(Dashboard.customize(new NoiseDashboard(config.global().getCoordinateSystem())).context("noise"));
}

if (trips) {
Expand All @@ -99,6 +108,34 @@ public Integer call() throws Exception {
.withDistanceDistribution("lausitz_mode_share_distance_distribution.csv"));
}

if (emissions) {
sw.addDashboard(Dashboard.customize(new EmissionsDashboard(config.global().getCoordinateSystem())).context("emissions"));

LausitzScenario.setEmissionsConfigs(config);
ConfigUtils.writeConfig(config, configPath);

Config dummyConfig = new Config();

String networkPath = ApplicationUtils.matchInput("output_network.xml.gz", runDirectory).toString();
String vehiclesPath = ApplicationUtils.matchInput("output_vehicles.xml.gz", runDirectory).toString();
String transitVehiclesPath = ApplicationUtils.matchInput("output_transitVehicles.xml.gz", runDirectory).toString();

dummyConfig.network().setInputFile(networkPath);
dummyConfig.vehicles().setVehiclesFile(vehiclesPath);
dummyConfig.transit().setVehiclesFile(transitVehiclesPath);

Scenario scenario = ScenarioUtils.loadScenario(dummyConfig);

// adapt network and veh types for emissions analysis like in LausitzScenario base run class
PrepareNetwork.prepareEmissionsAttributes(scenario.getNetwork());
LausitzScenario.prepareVehicleTypesForEmissionAnalysis(scenario);

// overwrite outputs with adapted files
NetworkUtils.writeNetwork(scenario.getNetwork(), networkPath);
new MatsimVehicleWriter(scenario.getVehicles()).writeFile(vehiclesPath);
new MatsimVehicleWriter(scenario.getTransitVehicles()).writeFile(transitVehiclesPath);
}


try {
sw.generate(runDirectory, true);
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/org/matsim/run/scenarios/LausitzScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.matsim.contrib.vsp.pt.fare.PtFareConfigGroup;
import org.matsim.contrib.vsp.pt.fare.PtFareModule;
import org.matsim.contrib.vsp.scenario.SnzActivities;
import org.matsim.contrib.vsp.scoring.RideScoringParamsFromCarParams;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.ReplanningConfigGroup;
Expand Down Expand Up @@ -135,15 +136,11 @@ public Config prepareConfig(Config config) {
scoringConfigGroup.setPathSizeLogitBeta(0.);

// set ride scoring params dependent from car params
ScoringConfigGroup.ModeParams rideParams = scoringConfigGroup.getOrCreateModeParams(TransportMode.ride);
ScoringConfigGroup.ModeParams carParams = scoringConfigGroup.getModes().get(TransportMode.car);
// 2.0 + 1.0 = alpha + 1
// ride cost = alpha * car cost
// ride marg utility of traveling = (alpha + 1) * marg utility travelling car + alpha * beta perf
double alpha = 2;
rideParams.setMarginalUtilityOfTraveling((alpha + 1) * carParams.getMarginalUtilityOfTraveling() - alpha * config.scoring().getPerforming_utils_hr());
rideParams.setDailyMonetaryConstant(0.);
rideParams.setMonetaryDistanceRate(carParams.getMonetaryDistanceRate() * 2);
RideScoringParamsFromCarParams.setRideScoringParamsBasedOnCarParams(scoringConfigGroup, alpha);

config.qsim().setUsingTravelTimeCheckInTeleportation(true);
config.qsim().setUsePersonIdForMissingVehicleId(false);
Expand Down Expand Up @@ -172,13 +169,7 @@ public Config prepareConfig(Config config) {

if (emissions == EmissionAnalysisHandling.PERFORM_EMISSIONS_ANALYSIS) {
// set hbefa input files for emission analysis
EmissionsConfigGroup eConfig = ConfigUtils.addOrGetModule(config, EmissionsConfigGroup.class);
eConfig.setDetailedColdEmissionFactorsFile(HBEFA_FILE_COLD_DETAILED);
eConfig.setDetailedWarmEmissionFactorsFile(HBEFA_FILE_WARM_DETAILED);
eConfig.setAverageColdEmissionFactorsFile(HBEFA_FILE_COLD_AVERAGE);
eConfig.setAverageWarmEmissionFactorsFile(HBEFA_FILE_WARM_AVERAGE);
eConfig.setHbefaTableConsistencyCheckingLevel(EmissionsConfigGroup.HbefaTableConsistencyCheckingLevel.consistent);
eConfig.setDetailedVsAverageLookupBehavior(EmissionsConfigGroup.DetailedVsAverageLookupBehavior.tryDetailedThenTechnologyAverageThenAverageTable);
setEmissionsConfigs(config);
}
return config;
}
Expand Down Expand Up @@ -262,7 +253,20 @@ public static void prepareCommercialTrafficConfig(Config config) {
}
}

private static void prepareVehicleTypesForEmissionAnalysis(Scenario scenario) {
public static void setEmissionsConfigs(Config config) {
EmissionsConfigGroup eConfig = ConfigUtils.addOrGetModule(config, EmissionsConfigGroup.class);
eConfig.setDetailedColdEmissionFactorsFile(HBEFA_FILE_COLD_DETAILED);
eConfig.setDetailedWarmEmissionFactorsFile(HBEFA_FILE_WARM_DETAILED);
eConfig.setAverageColdEmissionFactorsFile(HBEFA_FILE_COLD_AVERAGE);
eConfig.setAverageWarmEmissionFactorsFile(HBEFA_FILE_WARM_AVERAGE);
eConfig.setHbefaTableConsistencyCheckingLevel(EmissionsConfigGroup.HbefaTableConsistencyCheckingLevel.consistent);
eConfig.setDetailedVsAverageLookupBehavior(EmissionsConfigGroup.DetailedVsAverageLookupBehavior.tryDetailedThenTechnologyAverageThenAverageTable);
}

/**
* Prepare vehicle types with necessary HBEFA information for emission analysis.
*/
public static void prepareVehicleTypesForEmissionAnalysis(Scenario scenario) {
for (VehicleType type : scenario.getVehicles().getVehicleTypes().values()) {
EngineInformation engineInformation = type.getEngineInformation();

Expand Down

0 comments on commit 47e7210

Please sign in to comment.