Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rewertvsp committed May 22, 2024
2 parents d09a370 + 2085287 commit 5c2d845
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE config SYSTEM "http://www.matsim.org/files/dtd/config_v2.dtd">
<config>
<module name="timeAllocationMutator" >
<param name="mutationRange" value="7200.0" />
<param name="mutationRange" value="900.0" />
</module>
<module name="controller">
<param name="lastIteration" value="400"/>
Expand Down Expand Up @@ -69,22 +69,22 @@
<parameterset type="strategysettings">
<param name="strategyName" value="ChangeExpBeta"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.85"/>
<param name="weight" value="1.0"/>
</parameterset>
<parameterset type="strategysettings">
<param name="strategyName" value="ReRoute"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.10"/>
<param name="weight" value="0.15"/>
</parameterset>
<parameterset type="strategysettings">
<param name="strategyName" value="SubtourModeChoice"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.10"/>
<param name="weight" value="0.15"/>
</parameterset>
<parameterset type="strategysettings" >
<param name="strategyName" value="TimeAllocationMutator" />
<param name="subpopulation" value="person"/>
<param name="weight" value="0.05" />
<param name="weight" value="0.15" />
<param name="disableAfterIteration" value="350" />
</parameterset>
</module>
Expand All @@ -106,7 +106,7 @@
<param name="vspDefaultsCheckingLevel" value="abort" />
</module>
<module name="scoring">
<param name="fractionOfIterationsToStartScoreMSA" value="1.0" />
<param name="fractionOfIterationsToStartScoreMSA" value="0.9" />
<parameterset type="scoringParameters" >
<param name="marginalUtilityOfMoney" value="1.0"/>
<!-- car prices 2012->2022: inflation (110.2-91.7)/91.7 = 0.2017448
Expand Down Expand Up @@ -237,4 +237,24 @@
<param name="ptModes" value="pt" />
</parameterset>
</module>

<module name="ReplanningAnnealer" >
<param name="activateAnnealingModule" value="false" />
<parameterset type="AnnealingVariable" >
<param name="annealParameter" value="globalInnovationRate" />
<param name="annealType" value="sigmoid" />
<param name="defaultSubpopulation" value="person" />
<!-- this parameter enters the exponential and sigmoid formulas. May be an iteration or a share, i.e. 0.5 for halfLife at 50% of iterations. Exponential: startValue / exp(it/halfLife) -->
<param name="halfLife" value="0.5" />
<!-- sigmoid: 1/(1+e^(shapeFactor*(it - halfLife))); geometric: startValue * shapeFactor^it; msa: startValue / it^shapeFactor -->
<param name="shapeFactor" value="0.01" />
<param name="startValue" value="0.6" />
<param name="endValue" value="0.01" />
</parameterset>
</module>
<module name="strategy">
<param name="fractionOfIterationsToDisableInnovation" value="0.8"/>
<!-- Strategies are added in code -->
</module>

</config>
8 changes: 4 additions & 4 deletions src/main/R/srv.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ tt <- 17728996

persons <- read_delim("../../../../shared-svn/projects/rvr-metropole-ruhr/data/MID/MiD2017_Personen_RVR-Gebiet.csv", delim = ";",
locale = locale(decimal_mark = ",")) %>%
filter(kernwo == 2) %>%
filter(anzwege3 >= 0 & anzwege3 < 100)
filter(ST_WOTAG >= 2 & ST_WOTAG <= 4)

# Avg. number of trips per person per day
per_day <- weighted.mean(persons$anzwege3, persons$gew_pers)
Expand All @@ -62,8 +61,9 @@ order_modes_im <- c("walk", "bike", "pt", "ride", "car", "pt_w_bike_used", "pt_w

# Filter invalid modes and trip distances, also filter for weekdays
relevant <- trips %>%
filter(kernwo == 2) %>%
filter(wegkm < 1000) %>%
filter(ST_WOTAG >= 2 & ST_WOTAG <= 4) %>%
filter(wegkm < 9994) %>%
filter(wegmin < 9994) %>%
filter(hvm < 9) %>%
mutate(dist=wegkm * 1000) %>%
mutate(dist_group = cut(dist, breaks=breaks, labels=levels))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.matsim.dashboard;

import org.matsim.core.config.Config;
import org.matsim.simwrapper.Dashboard;
import org.matsim.simwrapper.DashboardProvider;
import org.matsim.simwrapper.SimWrapper;
import org.matsim.simwrapper.dashboard.TripDashboard;

import java.util.List;

/**
* Provider for default dashboards in the scenario.
* Declared in META-INF/services
*/
public class MetropoleRuhrDashboardProvider implements DashboardProvider {

@Override
public List<Dashboard> getDashboards(Config config, SimWrapper simWrapper) {

TripDashboard trips = new TripDashboard("mode_share_ref.csv", "mode_share_per_dist_ref.csv", "mode_users_ref.csv");

return List.of(trips);
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/matsim/run/RunMetropoleRuhrScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
@MATSimApplication.Prepare({AdjustDemand.class})
public class RunMetropoleRuhrScenario extends MATSimApplication {

public static final String VERSION = "v1.4";
public static final String VERSION = "v2.0";

private static final Logger log = LogManager.getLogger(RunMetropoleRuhrScenario.class);

Expand Down
53 changes: 16 additions & 37 deletions src/main/python/calibrate.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

import pandas as pd
import geopandas as gpd
import numpy as np

try:
# Use the matsim package if available
from matsim import calibration
except:
# Alternatively, import calibration.py from same directory
import calibration

# %%

if os.path.exists("mid.csv"):
srv = pd.read_csv("mid.csv")
sim = pd.read_csv("sim.csv")

_, adj = calibration.calc_adjusted_mode_share(sim, srv)

print(srv.groupby("mode").sum())

print("Adjusted")
print(adj.groupby("mode").sum())

adj.to_csv("mid_adj.csv", index=False)
from matsim.calibration import create_calibration, ASCCalibrator, utils

# %%

Expand All @@ -44,11 +20,11 @@

# Modal split target
target = {
"walk": 0.205397,
"bike": 0.097191,
"pt": 0.120314,
"car": 0.456896,
"ride": 0.120203
"walk": 0.232118,
"bike": 0.098503,
"pt": 0.116146,
"car": 0.424297,
"ride": 0.128936
}

region = gpd.read_file("../scenarios/metropole-ruhr-v1.0/shape/dilutionArea.shp").set_crs("EPSG:25832")
Expand All @@ -70,13 +46,16 @@ def adjust_trips(df):
return df


study, obj = calibration.create_mode_share_study("calib", "matsim-metropole-ruhr-1.4.1-136d8aa.jar",
"../scenarios/metropole-ruhr-v1.0/input/metropole-ruhr-v1.0-10pct.config.xml",
modes, target,
initial_asc=initial,
args="--10pct",
jvm_args="-Xmx68G -Xmx68G -XX:+AlwaysPreTouch",
person_filter=f, map_trips=adjust_trips, chain_runs=True)
study, obj = create_calibration(
"calib",
ASCCalibrator(modes, initial, target, lr=utils.linear_scheduler(start=0.3, interval=8)),
"matsim-metropole-ruhr-1.4.1-136d8aa.jar",
"../scenarios/metropole-ruhr-v1.0/input/metropole-ruhr-v1.0-10pct.config.xml",
args="--10pct",
jvm_args="-Xmx68G -Xmx68G -XX:+AlwaysPreTouch",
transform_persons=f, transform_trips=adjust_trips,
chain_runs=utils.default_chain_scheduler, debug=False
)

# %%

Expand Down
20 changes: 13 additions & 7 deletions src/main/python/create_ref.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

from matsim.scenariogen.data import TripMode, run_create_ref_data


def person_filter(df):
""" Default person filter for reference data. """
return df[df.reporting_day <= 5]
# Tuesday to Thursday
return df[(df.reporting_day >= 2) & (df.reporting_day <= 4)]


def trip_filter(df):
# Motorcycles are counted as cars
df.loc[df.main_mode == TripMode.MOTORCYCLE, "main_mode"] = TripMode.CAR

# Other modes are ignored in the total share
# Long distance mode are ignored as well
return df[(df.main_mode != "other") & (df.gis_length < 100)]
return df[df.main_mode != "other"]


if __name__ == "__main__":
person, trips, share = run_create_ref_data.create("../../../../shared-svn/projects/NaMAV/data/SrV_2018",
person_filter, trip_filter,
run_create_ref_data.InvalidHandling.REMOVE_PERSONS)
result = run_create_ref_data.create("../../../../shared-svn/projects/rvr-metropole-ruhr/data/MID",
person_filter, trip_filter,
dist_groups=[0, 1000, 2000, 5000, 10000, 20000, 50000, np.inf],
invalid_trip_handling=run_create_ref_data.InvalidHandling.REMOVE_TRIPS)

print(result.persons)
print(result.trips)

print(share)
print(result.share)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.matsim.dashboard.MetropoleRuhrDashboardProvider
36 changes: 36 additions & 0 deletions src/main/resources/mode_share_per_dist_ref.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
dist_group,main_mode,share
0 - 1000,bike,0.08922756652897382
0 - 1000,car,0.14920930393728898
0 - 1000,pt,0.01141689518127269
0 - 1000,ride,0.05266112251043193
0 - 1000,walk,0.6974851118420325
1000 - 2000,bike,0.1412980387219933
1000 - 2000,car,0.2893394369807224
1000 - 2000,pt,0.07355118760590791
1000 - 2000,ride,0.14803247616603515
1000 - 2000,walk,0.3477788605253412
2000 - 5000,bike,0.17022654579538898
2000 - 5000,car,0.4199284767872729
2000 - 5000,pt,0.15407708873488477
2000 - 5000,ride,0.1477080914190836
2000 - 5000,walk,0.10805979726336983
5000 - 10000,bike,0.051336571850878795
5000 - 10000,car,0.5939631205574252
5000 - 10000,pt,0.1551416574021224
5000 - 10000,ride,0.16658004372932197
5000 - 10000,walk,0.03297860646025174
10000 - 20000,bike,0.020809262401952737
10000 - 20000,car,0.6675803912060924
10000 - 20000,pt,0.1356469565014502
10000 - 20000,ride,0.159567475292094
10000 - 20000,walk,0.016395914598410645
20000 - 50000,bike,0.016706269387170403
20000 - 50000,car,0.6492250405860016
20000 - 50000,pt,0.22408126032827708
20000 - 50000,ride,0.09851721323716982
20000 - 50000,walk,0.011470216461381298
50000+,bike,0.04024152153627648
50000+,car,0.6660439494130431
50000+,pt,0.16140958352218981
50000+,ride,0.13230494552849048
50000+,walk,0.0
36 changes: 36 additions & 0 deletions src/main/resources/mode_share_ref.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
dist_group,main_mode,share
0 - 1000,bike,0.018274383327818906
0 - 1000,car,0.030559031499997773
0 - 1000,pt,0.0023382540516596684
0 - 1000,ride,0.010785338843869218
0 - 1000,walk,0.14284946676326818
1000 - 2000,bike,0.02105728428475822
1000 - 2000,car,0.043119514144725465
1000 - 2000,pt,0.010961144831928345
1000 - 2000,ride,0.022060900223378015
1000 - 2000,walk,0.051828591539901575
2000 - 5000,bike,0.046015457211230064
2000 - 5000,car,0.11351461527397798
2000 - 5000,pt,0.04164995330653673
2000 - 5000,ride,0.03992829278587998
2000 - 5000,walk,0.02921060845118482
5000 - 10000,bike,0.008688445624977822
5000 - 10000,car,0.10052514396940579
5000 - 10000,pt,0.026256912098118687
5000 - 10000,ride,0.028192799011838694
5000 - 10000,walk,0.0055814562345485996
10000 - 20000,bike,0.0023225644244755732
10000 - 20000,car,0.07451001564319057
10000 - 20000,pt,0.015139834818416709
10000 - 20000,ride,0.017809652944835996
10000 - 20000,walk,0.0018299816311333934
20000 - 50000,bike,0.0011909299394746936
20000 - 50000,car,0.04628092127404028
20000 - 50000,pt,0.015973948199656557
20000 - 50000,ride,0.007022938280156049
20000 - 50000,walk,0.0008176705331116503
50000+,bike,0.0009538829674380032
50000+,car,0.01578787169708562
50000+,pt,0.0038260445088857597
50000+,ride,0.00313614965909456
50000+,walk,0.0
6 changes: 6 additions & 0 deletions src/main/resources/mode_users_ref.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
main_mode,user
pt,0.1630445040891789
car,0.3870760553176311
ride,0.16700096730641525
walk,0.3177808474256387
bike,0.11064980061817771
Loading

0 comments on commit 5c2d845

Please sign in to comment.