Skip to content

Commit

Permalink
update config and added number of missing short distance trips
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Oct 24, 2023
1 parent 730bca7 commit 5cb712a
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 42 deletions.
27 changes: 13 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ input/plans-longHaulFreight.xml.gz: input/$V/$N-$V-network.xml.gz
--network ../public-svn/matsim/scenarios/countries/de/german-wide-freight/v2/germany-europe-network.xml.gz\
--input-crs $(CRS)\
--target-crs $(CRS)\
--shp $(shared)/data/shp/$N.shp --shp-crs $(CRS)\
--shp input/shp/lausitz.shp --shp-crs $(CRS)\
--cut-on-boundary\
--output $@

Expand All @@ -104,19 +104,20 @@ input/$V/prepare-100pct.plans.xml.gz:
input/$V/prepare-100pct.plans.xml.gz\
--input-crs $(CRS)\
--grid-resolution 300\
--landuse ../shared-svn/projects/matsim-germany/landuse/landuse.shp\
--landuse $(germany)/landuse/landuse.shp\
--output $@

input/$V/$N-$V-100pct.plans.xml.gz: input/plans-longHaulFreight.xml.gz input/$V/prepare-100pct.plans.xml.gz
input/$V/$N-$V-100pct.plans-initial.xml.gz: input/plans-longHaulFreight.xml.gz input/$V/prepare-100pct.plans.xml.gz

$(sc) prepare generate-short-distance-trips\
--population input/$V/prepare-100pct.plans.xml.gz\
--input-crs $(CRS)\
--shp $(shared)/data/shp/$N.shp --shp-crs $(CRS)\
--num-trips 1 # TODO
--shp input/shp/lausitz.shp --shp-crs $(CRS)\
--range 1500\
--num-trips 795513

$(sc) prepare adjust-activity-to-link-distances input/$V/prepare-100pct.plans-with-trips.xml.gz\
--shp $(shared)/data/shp/$N.shp --shp-crs $(CRS)\
--shp input/shp/lausitz.shp --shp-crs $(CRS)\
--scale 1.15\
--input-crs $(CRS)\
--network input/$V/$N-$V-network.xml.gz\
Expand All @@ -126,13 +127,11 @@ input/$V/$N-$V-100pct.plans.xml.gz: input/plans-longHaulFreight.xml.gz input/$V/

$(sc) prepare merge-populations $@ $< --output $@

# TODO: set home coordinates attributes

$(sc) prepare extract-home-coordinates $@ --output $@ --csv input/$V/$N-$V-homes.csv

$(sc) prepare downsample-population $@\
--sample-size 1\
--samples 0.25 0.01\
--samples 0.25 0.1 0.01\

input/$V/$N-$V-counts-car-bast.xml.gz: input/2019_A_S.zip input/2019_B_S.zip input/Jawe2019.csv input/$V/$N-$V-network-with-pt.xml.gz

Expand All @@ -142,22 +141,22 @@ input/$V/$N-$V-counts-car-bast.xml.gz: input/2019_A_S.zip input/2019_B_S.zip inp
--primary-data input/2019_B_S.zip\
--station-data input/Jawe2019.csv\
--year 2019\
--shp $(shared)/data/shp/$N.shp --shp-crs $(CRS)\
--shp input/shp/lausitz.shp --shp-crs $(CRS)\
--car-output $@\
--freight-output $(subst car,freight,$@)

check: input/$V/$N-$V-100pct.plans.xml.gz
check: input/$V/$N-$V-100pct.plans-initial.xml.gz
$(sc) analysis commuter\
--population $<\
--input-crs $(CRS)\
--shp ../shared-svn/projects/matsim-germany/vg5000/vg5000_ebenen_0101/VG5000_GEM.shp\
--shp $(germany)/vg5000/vg5000_ebenen_0101/VG5000_GEM.shp\
--attr ARS\
--output input/$V/$N-$V-commuter.csv

$(sc) analysis check-population $<\
--input-crs $(CRS)\
--shp $(shared)/data/shp/$N.shp --shp-crs $(CRS)
--shp input/shp/lausitz.shp --shp-crs $(CRS)

# Aggregated target
prepare: input/$V/$N-$V-100pct.plans.xml.gz input/$V/$N-$V-network-with-pt.xml.gz input/$V/$N-$V-counts-car-bast.xml.gz
prepare: input/$V/$N-$V-100pct.plans-initial.xml.gz input/$V/$N-$V-network-with-pt.xml.gz input/$V/$N-$V-counts-car-bast.xml.gz
echo "Done"
1 change: 1 addition & 0 deletions input/shp/lausitz.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added input/shp/lausitz.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions input/shp/lausitz.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ETRS89_UTM_zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
1 change: 1 addition & 0 deletions input/shp/lausitz.qpj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ETRS89 / UTM zone 32N",GEOGCS["ETRS89",DATUM["European_Terrestrial_Reference_System_1989",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6258"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4258"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","25832"]]
Binary file added input/shp/lausitz.shp
Binary file not shown.
Binary file added input/shp/lausitz.shx
Binary file not shown.
55 changes: 37 additions & 18 deletions input/v1.0/lausitz-v1.0-100pct.config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</module>

<module name="controler">
<param name="lastIteration" value="700"/>
<param name="lastIteration" value="600"/>
<param name="overwriteFiles" value="failIfDirectoryExists"/>
<param name="runId" value="lausitz-25pct"/>
<param name="runId" value="lausitz-100pct"/>
<param name="outputDirectory" value="./output/output-lausitz-100pct"/>
<param name="writeEventsInterval" value="100"/>
<param name="writePlansInterval" value="100"/>
Expand All @@ -23,28 +23,30 @@
</module>

<module name="network">
<param name="inputNetworkFile" value="lausitz-v1.0-network-with-pt.xml.gz"/>
<param name="inputNetworkFile" value="./lausitz-v1.0-network-with-pt.xml.gz"/>
<param name="laneDefinitionsFile" value="null"/>
</module>

<module name="plans">
<param name="inputPlansFile"
value="lausitz-v1.0-100pct.plans.xml.gz"/>
value="./lausitz-v1.0-100pct.plans-initial.xml.gz"/>
<param name="removingUnnecessaryPlanAttributes" value="true"/>
</module>

<module name="vehicles">
<param name="vehiclesFile" value="vehicle-types.xml"/>
<param name="vehiclesFile" value="./vehicle-types.xml"/>
</module>

<module name="transit">
<param name="transitScheduleFile"
value="lausitz-v1.0-transitSchedule.xml.gz"/>
<param name="vehiclesFile"
value="lausitz-v1.0-transitVehicles.xml.gz"/>
<param name="transitScheduleFile" value="./lausitz-v1.0-transitSchedule.xml.gz"/>
<param name="vehiclesFile" value="./lausitz-v1.0-transitVehicles.xml.gz"/>
<param name="useTransit" value="true"/>
</module>

<module name="counts">
<param name="inputCountsFile" value="./lausitz-v1.0-counts-car-bast.xml.gz"/>
</module>

<module name="planscalcroute">
<!-- Some typical teleportation routing params are set by default, such as for walk and bike. Setting this switch to "true" will clear them. Note that this will also clear settings for helper modes such as for non_network_walk -->
<param name="clearDefaultTeleportedModeParams" value="true"/>
Expand All @@ -60,7 +62,7 @@
<param name="endTime" value="36:00:00"/>
<param name="flowCapacityFactor" value="1"/>
<param name="storageCapacityFactor" value="1"/>
<param name="mainMode" value="car,freight"/>
<param name="mainMode" value="car,bike,freight"/>
<param name="numberOfThreads" value="12"/>
<param name="startTime" value="00:00:00"/>
<param name="stuckTime" value="30.0"/>
Expand All @@ -72,6 +74,20 @@
<param name="insertingWaitingVehiclesBeforeDrivingVehicles" value="true"/>
</module>

<module name="ReplanningAnnealer" >
<param name="activateAnnealingModule" value="true" />
<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.45" />
<param name="endValue" value="0.01" />
</parameterset>
</module>
<module name="strategy">
<param name="fractionOfIterationsToDisableInnovation" value="0.9"/>
<parameterset type="strategysettings">
Expand All @@ -87,12 +103,12 @@
<parameterset type="strategysettings">
<param name="strategyName" value="SubtourModeChoice"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.1"/>
<param name="weight" value="0.10"/>
</parameterset>
<parameterset type="strategysettings">
<param name="strategyName" value="TimeAllocationMutator"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.025"/>
<param name="weight" value="0.10"/>
</parameterset>

<parameterset type="strategysettings">
Expand Down Expand Up @@ -136,25 +152,28 @@
</module>

<module name="vspExperimental">
<param name="vspDefaultsCheckingLevel" value="warn"/>
<param name="vspDefaultsCheckingLevel" value="abort"/>
</module>

<module name="planCalcScore">
<param name="fractionOfIterationsToStartScoreMSA" value="1.0"/>
<param name="fractionOfIterationsToStartScoreMSA" value="0.9"/>
<parameterset type="scoringParameters">
<!-- Inflation adjusted -->
<param name="performing" value="6.67"/>

<parameterset type="modeParams">
<param name="constant" value="-1.4"/>
<param name="marginalUtilityOfTraveling_util_hr" value="-0.5"/>
<param name="mode" value="car"/>
<param name="monetaryDistanceRate" value="-0.0002"/>
<param name="dailyMonetaryConstant" value="-5.3"/>
<param name="monetaryDistanceRate" value="-0.00025"/>
<param name="dailyMonetaryConstant" value="-13.22"/>
</parameterset>
<parameterset type="modeParams">
<param name="constant" value="-0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="-0.5"/>
<!-- #(2.0+1.0)*6+(2.0+1)*0.5 -->
<param name="marginalUtilityOfTraveling_util_hr" value="-19.5"/>
<param name="mode" value="ride"/>
<param name="monetaryDistanceRate" value="-0.0002"/>
<param name="monetaryDistanceRate" value="-0.0005"/>
<param name="dailyMonetaryConstant" value="-0.0"/>
</parameterset>
<parameterset type="modeParams">
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/org/matsim/run/RunLausitzScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import org.matsim.application.prepare.pt.CreateTransitScheduleFromGtfs;
import org.matsim.contrib.vsp.scenario.SnzActivities;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.VspExperimentalConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.run.analysis.CommuterAnalysis;
import org.matsim.simwrapper.SimWrapperConfigGroup;
import org.matsim.simwrapper.SimWrapperModule;
import picocli.CommandLine;

Expand All @@ -41,10 +42,10 @@
})
public class RunLausitzScenario extends MATSimApplication {

static final String VERSION = "1.0";
public static final String VERSION = "1.0";

@CommandLine.Mixin
private final SampleOptions sample = new SampleOptions(100, 25, 1);
private final SampleOptions sample = new SampleOptions(100, 25, 10, 1);


public RunLausitzScenario(@Nullable Config config) {
Expand All @@ -66,14 +67,22 @@ protected Config prepareConfig(Config config) {
// Add all activity types with time bins
SnzActivities.addScoringParams(config);

config.controller().setOutputDirectory(sample.adjustName(config.controller().getOutputDirectory()));
config.plans().setInputFile(sample.adjustName(config.plans().getInputFile()));
config.controller().setRunId(sample.adjustName(config.controller().getRunId()));
SimWrapperConfigGroup simWrapper = ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class);

config.qsim().setFlowCapFactor(sample.getSize() / 100.0);
config.qsim().setStorageCapFactor(sample.getSize() / 100.0);
// Path is relative to config
simWrapper.defaultParams().shp = "../shp/lausitz.shp";
simWrapper.defaultParams().mapCenter = "14.3463,51.5626";
simWrapper.defaultParams().mapZoomLevel = 9.0;

if (sample.isSet()) {
config.controller().setOutputDirectory(sample.adjustName(config.controller().getOutputDirectory()));
config.plans().setInputFile(sample.adjustName(config.plans().getInputFile()));
config.controller().setRunId(sample.adjustName(config.controller().getRunId()));

config.qsim().setFlowCapFactor(sample.getSize() / 100.0);
config.qsim().setStorageCapFactor(sample.getSize() / 100.0);
}

config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.info);
config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink);

// TODO: Config options
Expand Down
20 changes: 19 additions & 1 deletion src/main/python/create_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# -*- coding: utf-8 -*-

import geopandas as gpd

import pandas as pd
from matsim.scenariogen.data import run_create_ref_data
from matsim.scenariogen.data.preparation import calc_needed_short_distance_trips


def person_filter(df):
Expand All @@ -29,3 +30,20 @@ def trip_filter(df):
print("Filtered %s trips" % len(trips))

print(share)

# Simulated trips
sim_persons = pd.read_csv("../../../output/output-lausitz-100pct/lausitz-100pct.output_persons.csv.gz",
delimiter=";", dtype={"person": "str"})
sim_persons = sim_persons[sim_persons.subpopulation == "person"]
sim_persons = gpd.GeoDataFrame(sim_persons,
geometry=gpd.points_from_xy(sim_persons.home_x, sim_persons.home_y)).set_crs("EPSG:25832")

sim_persons = gpd.sjoin(sim_persons, region, how="inner", predicate="intersects")

sim = pd.read_csv("../../../output/output-lausitz-100pct/lausitz-100pct.output_trips.csv.gz",
delimiter=";", dtype={"person": "str"})

sim = pd.merge(sim, sim_persons, how="inner", left_on="person", right_on="person")

share, add_trips = calc_needed_short_distance_trips(trips, sim, max_dist=1500)
print("Short distance trip missing: ", add_trips)

0 comments on commit 5cb712a

Please sign in to comment.