Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAL 2023 Remote work #436

Draft
wants to merge 17 commits into
base: olusanya
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Scripts/assignment/emme_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def aggregate_results(self, resultdata):
linktypes.add(param.roadtypes[linktype])
linklengths = pandas.Series(0.0, linktypes)
soft_modes = param.transit_classes + ("bike",)
attr_names = self.day_scenario.attributes("LINK")
resultdata.print_line("Link\t" + "\t".join(attr_names), "links")
network = self.day_scenario.get_network()
for link in network.links():
linktype = link.type % 100
Expand All @@ -197,6 +199,10 @@ def aggregate_results(self, resultdata):
linklengths[param.railtypes[linktype]] += link.length
else:
linklengths[param.roadtypes[vdf]] += link.length / 2
wkt = "LINESTRING ({} {}, {} {})".format(
link.i_node.x, link.i_node.y, link.j_node.x, link.j_node.y)
attrs = "\t".join([str(link[attr]) for attr in attr_names])
resultdata.print_line(wkt + "\t" + attrs, "links")
if faulty_kela_code_nodes:
s = "Municipality KELA code not found for nodes: " + ", ".join(
faulty_kela_code_nodes)
Expand Down
5 changes: 5 additions & 0 deletions Scripts/assignment/emme_bindings/mock_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ def __init__(self, idx):
def zone_numbers(self):
return sorted(self._network._centroids)

def attributes(self, attr_type):
network = self.get_network()
# TODO Return other attributes except extra attributes
return list(network._extra_attr[attr_type])

def extra_attribute(self, idx):
network = self.get_network()
for attr_type in network._extra_attr:
Expand Down
14 changes: 14 additions & 0 deletions Scripts/helmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def main(args):
results_path, ass_model, args.scenario_name)
log_extra["status"]["results"] = model.mode_share

model.cdm.set_car_growth(constant=args.car_growth_constant,
factor=args.car_growth_factor)

# Run traffic assignment simulation for N iterations,
# on last iteration model-system will save the results
log_extra["status"]["state"] = "preparing"
Expand Down Expand Up @@ -247,6 +250,17 @@ def main(args):
action="store_true",
default=config.USE_FIXED_TRANSIT_COST,
help="Using this flag activates use of pre-calculated (fixed) transit costs."),
# MAL 2023 input data
parser.add_argument(
"--car-growth-constant",
type=float,
default=0.0,
help="Car ownership growth constant. To increase, try 0.1."),
parser.add_argument(
"--car-growth-factor",
type=float,
default=1.0,
help="Car ownership growth factor. To decrease, try 0.8."),
args = parser.parse_args()

log.initialize(args)
Expand Down
20 changes: 18 additions & 2 deletions Scripts/models/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,24 @@ def __init__(self, zone_data_base, zone_data_forecast, bounds, resultdata):
out=numpy.array(forecast_sh_detached), where=pop_growth!=0)
self.zone_data._values["share_detached_houses_new"] = pandas.Series(
share_detached_new, self.zone_data.zone_numbers[self.bounds])

self.set_car_growth()

def set_car_growth(self, constant=0.0, factor=1.0):
"""Set extra car ownership growth for sensitivity analyses.

Parameters
----------
constant : float (optional)
Constant to add to prediction
factor : float (optional)
Factor to multiply prediction by
"""
self._growth_constant = constant
self._growth_factor = factor

def predict(self):
"""Get car ownership prediction for zones.

Return
------
pandas.Series
Expand All @@ -108,6 +122,8 @@ def predict(self):
.clip(upper=1.0))
prediction = (self.pop_growth_share * prediction
+ (1-self.pop_growth_share) * base_car_density)
prediction += self._growth_constant
prediction *= self._growth_factor
self.print_results(prediction)
return prediction

Expand Down
1 change: 1 addition & 0 deletions Scripts/parameters/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
40: RoadClass("collector", "any", 5, 900, 36, 0.833),
41: RoadClass("local", "any", 5, 600, 30, 1.000),
42: RoadClass("local", "any", 5, 500, 23, 1.304),
43: RoadClass("collector", "any", 5, 750, 30, 0.833),
}
connector_link_types = (84, 85, 86, 87, 88, 98, 99)
connector = RoadClass("connector", "any", 99, 0, 0, 0)
Expand Down
60 changes: 32 additions & 28 deletions Scripts/parameters/tour_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
3: 1.05446538,
4: 1.2455917 + 0.1043963,
}
MUULITAR_CONSTANT_ZERO = 0.0
MUULITAR_CONSTANT_HW = -0.3
MUULITAR_CONSTANT_HO = 0.38
MUULITAR_CONSTANT_HU = -0.08
# Tour combinations (calibrated)
tour_combinations = {
# utility function 1
0: {
() : {
"constant": 0.000000000,
"constant": 0.000000000 + MUULITAR_CONSTANT_ZERO,
"individual_dummy": {
"age_50-64": -0.305509545 ,
"age_65-99": 0.597976527
Expand All @@ -25,7 +29,7 @@
},
1: {
("hw",) : {
"constant": 0.000000000 + 0.0210,
"constant": 0.000000000 + 0.0210 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 2.306249018 + 0.1065,
"age_30-49": 2.977241136 - 0.3498,
Expand All @@ -48,7 +52,7 @@
},
# utility function 4
("hu",) : {
"constant": 0.000000000 + 0.3000,
"constant": 0.000000000 + 0.3000 + MUULITAR_CONSTANT_HU,
"individual_dummy": {
"age_18-29": 0.000000000 + 0.0653,
"age_30-49": -1.586979829 - 0.0192,
Expand Down Expand Up @@ -76,7 +80,7 @@
},
# utility function 6
("ho",) : {
"constant": 0.811674639,
"constant": 0.811674639 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_7-17": 0.000000000 - 0.1096,
"age_18-29": 0.000000000 + 0.0679,
Expand All @@ -92,7 +96,7 @@
},
2: {
("hw", "hw") : {
"constant": -6.702389265,
"constant": -6.702389265 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 2.306249018 - 1.0022,
"age_30-49": 2.977241136 + 0.3275,
Expand All @@ -106,7 +110,7 @@
},
# utility function 8
("hw", "hu") : {
"constant": -8.418852173 + 0.2000,
"constant": -8.418852173 + 0.2000 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 2.306249018 - 0.4439,
"age_30-49": -1.586979829 + 2.977241136 + 0.4961,
Expand All @@ -121,7 +125,7 @@
},
# utility function 9
("hw", "hs") : {
"constant": -5.468303413,
"constant": -5.468303413 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 0.632156675 + 2.306249018 - 0.1900,
"age_30-49": 1.106558979 + 2.977241136 + 0.0878,
Expand All @@ -135,7 +139,7 @@
},
# utility function 10
("hw", "ho") : {
"constant": -3.969665707,
"constant": -3.969665707 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 2.306249018 + 0.0229,
"age_30-49": 2.977241136 + 0.0059,
Expand Down Expand Up @@ -182,7 +186,7 @@
},
# utility function 14
("hu", "hs") : {
"constant": -5.264912587 + 0.0736,
"constant": -5.264912587 + 0.0736 + MUULITAR_CONSTANT_HU,
"individual_dummy": {
"age_18-29": 0.632156675 - 0.0197,
"age_30-49": 1.106558979 -1.586979829 - 0.6757,
Expand All @@ -197,7 +201,7 @@
},
# utility function 15
("hu", "ho") : {
"constant": -4.133565561 + 0.0834,
"constant": -4.133565561 + 0.0834 + MUULITAR_CONSTANT_HU,
"individual_dummy": {
"age_18-29": 0.000000000 + 0.2038,
"age_30-49": -1.586979829 - 0.8545,
Expand Down Expand Up @@ -226,7 +230,7 @@
},
# utility function 17
("hs", "ho") : {
"constant": -3.615413138,
"constant": -3.615413138 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_7-17": 0.000000000 + 0.1376,
"age_18-29": 0.632156675 + 0.0695,
Expand All @@ -241,7 +245,7 @@
},
# utility function 18
("ho", "ho") : {
"constant": -2.954069138,
"constant": -2.954069138 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_7-17": 0.000000000 + 0.5035,
"age_18-29": 0.000000000 - 0.1393,
Expand All @@ -258,7 +262,7 @@
},
3: {
("hw", "hw", "ho") : {
"constant": -7.640316015,
"constant": -7.640316015 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 2.306249018 ,
"age_30-49": 2.977241136 - 0.4304,
Expand All @@ -270,7 +274,7 @@
},
# utility function 20
("hw", "hs", "hs") : {
"constant": -6.996908123,
"constant": -6.996908123 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 0.632156675 + 2.306249018 - 0.7910,
"age_30-49": 1.106558979 + 2.977241136 + 0.4528,
Expand All @@ -282,7 +286,7 @@
},
# utility function 21
("hw", "hs", "ho") : {
"constant": -6.280857590,
"constant": -6.280857590 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 0.632156675 + 2.306249018 + 0.2580,
"age_30-49": 1.106558979 + 2.977241136 + 0.1582,
Expand All @@ -294,7 +298,7 @@
},
# utility function 22
("hw", "ho", "ho") : {
"constant": -5.143814369,
"constant": -5.143814369 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 2.306249018 - 0.2782,
"age_30-49": 2.977241136 + 0.3222,
Expand Down Expand Up @@ -331,7 +335,7 @@
},
# utility function 25
("hu", "hs", "ho") : {
"constant": -11.751808160,
"constant": -11.751808160 + MUULITAR_CONSTANT_HU,
"individual_dummy": {
"age_18-29": 0.632156675 + 0.1437,
"age_30-49": 1.106558979 -1.586979829 + 0.8652,
Expand All @@ -346,7 +350,7 @@
},
# utility function 26
("hu", "ho", "ho") : {
"constant": -11.342729830,
"constant": -11.342729830 + MUULITAR_CONSTANT_HU,
"individual_dummy": {
"age_18-29": -0.000000000 + 0.1541,
"age_30-49": -1.586979829 + 0.5275,
Expand Down Expand Up @@ -375,7 +379,7 @@
},
# utility function 28
("hs", "hs", "ho") : {
"constant": -4.709369964,
"constant": -4.709369964 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_18-29": 0.632156675 - 0.7508,
"age_30-49": 1.106558979 + 0.5842,
Expand All @@ -389,7 +393,7 @@
},
# utility function 29
("hs", "ho", "ho") : {
"constant": -4.115616267,
"constant": -4.115616267 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_18-29": 0.632156675 - 0.1442,
"age_30-49": 1.106558979 ,
Expand All @@ -403,7 +407,7 @@
},
# utility function 30
("ho", "ho", "ho") : {
"constant": -4.110394781,
"constant": -4.110394781 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_30-49": 0.000000000 - 0.1750,
"age_50-64": 0.000000000 + 0.1126,
Expand All @@ -418,7 +422,7 @@
},
4: {
("hw", "hs", "hs", "ho") : {
"constant": -8.782904966,
"constant": -8.782904966 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 0.632156675 + 2.306249018 ,
"age_30-49": 1.106558979 + 2.977241136 + 0.2190,
Expand All @@ -432,7 +436,7 @@
},
# utility function 32
("hw", "hs", "ho", "ho") : {
"constant": -7.819600775,
"constant": -7.819600775 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 0.632156675 + 2.306249018 + 0.5615,
"age_30-49": 1.106558979 + 2.977241136 + 0.2939,
Expand All @@ -446,7 +450,7 @@
},
# utility function 33
("hw", "ho", "ho", "ho") : {
"constant": -6.323991971,
"constant": -6.323991971 + MUULITAR_CONSTANT_HW,
"individual_dummy": {
"age_18-29": 2.306249018 + 0.3338,
"age_30-49": 2.977241136 ,
Expand Down Expand Up @@ -474,7 +478,7 @@
},
# utility function 35
("hs", "hs", "hs", "ho") : {
"constant": -6.280534875,
"constant": -6.280534875 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_18-29": 0.632156675 - 1.3263,
"age_30-49": 1.106558979 + 0.9876,
Expand All @@ -488,7 +492,7 @@
},
# utility function 36
("hs", "hs", "ho", "ho") : {
"constant": -5.728407971,
"constant": -5.728407971 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_18-29": 0.632156675 - 0.8239,
"age_30-49": 1.106558979 + 0.4522,
Expand All @@ -502,7 +506,7 @@
},
# utility function 37
("hs", "ho", "ho", "ho") : {
"constant": -5.167664200,
"constant": -5.167664200 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_18-29": 0.632156675 - 0.8511,
"age_30-49": 1.106558979 + 0.7283,
Expand All @@ -516,7 +520,7 @@
},
# utility function 38
("ho", "ho", "ho", "ho") : {
"constant": -4.892323651,
"constant": -4.892323651 + MUULITAR_CONSTANT_HO,
"individual_dummy": {
"age_18-29": 0.000000000 - 2.0113,
"age_30-49": 0.000000000 + 0.2214,
Expand Down
3 changes: 2 additions & 1 deletion Scripts/tests/integration/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def test_models(self):
self._validate_impedances(impedance["iht"])

# Check that model result does not change
self.assertAlmostEquals(model.mode_share[0]["car"], 0.22489513375983478)
# when using Muulitar parameters
self.assertAlmostEquals(model.mode_share[0]["car"], 0.223537259813515)

print("Model system test done")

Expand Down
Loading