|
| 1 | +#---LICENSE---------------------- |
| 2 | +''' |
| 3 | + Copyright 2021 Travel Modelling Group, Department of Civil Engineering, University of Toronto |
| 4 | +
|
| 5 | + This file is part of the TMG Toolbox. |
| 6 | +
|
| 7 | + The TMG Toolbox is free software: you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License as published by |
| 9 | + the Free Software Foundation, either version 3 of the License, or |
| 10 | + (at your option) any later version. |
| 11 | +
|
| 12 | + The TMG Toolbox is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + GNU General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU General Public License |
| 18 | + along with the TMG Toolbox. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +''' |
| 20 | +#---METADATA--------------------- |
| 21 | +''' |
| 22 | +[TITLE] |
| 23 | +
|
| 24 | + Authors: JamesVaughan |
| 25 | +
|
| 26 | + Latest revision by: JamesVaughan |
| 27 | + |
| 28 | + |
| 29 | + [Description] |
| 30 | + |
| 31 | +''' |
| 32 | +#---VERSION HISTORY |
| 33 | +''' |
| 34 | + 0.0.1 Created on 2021-07-03 by JamesVaughan |
| 35 | +''' |
| 36 | + |
| 37 | +import inro.modeller as _m |
| 38 | +import traceback as _traceback |
| 39 | +from contextlib import contextmanager |
| 40 | +from contextlib import nested |
| 41 | +_MODELLER = _m.Modeller() #Instantiate Modeller once. |
| 42 | +_util = _MODELLER.module('tmg.common.utilities') |
| 43 | +_tmgTPB = _MODELLER.module('tmg.common.TMG_tool_page_builder') |
| 44 | + |
| 45 | +class StrategyBasedAnalysis(_m.Tool()): |
| 46 | + |
| 47 | + version = '0.0.1' |
| 48 | + tool_run_msg = "" |
| 49 | + number_of_tasks = 1 # For progress reporting, enter the integer number of tasks here |
| 50 | + |
| 51 | + xtmf_ScenarioNumber = _m.Attribute(int) |
| 52 | + xtmf_ClassName = _m.Attribute(str) |
| 53 | + xtmf_DemandMatrixNumber = _m.Attribute(int) |
| 54 | + xtmf_sub_path_combination_operator = _m.Attribute(str) |
| 55 | + xtmf_StrategyValuesMatrixNumber = _m.Attribute(int) |
| 56 | + |
| 57 | + xtmf_in_vehicle_trip_component = _m.Attribute(str) |
| 58 | + |
| 59 | + def __init__(self): |
| 60 | + #---Init internal variables |
| 61 | + self.TRACKER = _util.ProgressTracker(self.number_of_tasks) #init the ProgressTracker |
| 62 | + |
| 63 | + def page(self): |
| 64 | + pb = _m.ToolPageBuilder(self, title="Strategy Based Analysis", |
| 65 | + description="Cannot be called from Modeller.", |
| 66 | + runnable=False, |
| 67 | + branding_text="XTMF") |
| 68 | + return pb.render() |
| 69 | + |
| 70 | + def __call__(self, xtmf_ScenarioNumber, xtmf_ClassName, xtmf_DemandMatrixNumber, xtmf_sub_path_combination_operator, xtmf_StrategyValuesMatrixNumber, xtmf_in_vehicle_trip_component): |
| 71 | + if xtmf_ClassName == '': |
| 72 | + xtmf_ClassName = None |
| 73 | + if xtmf_in_vehicle_trip_component == '': |
| 74 | + xtmf_in_vehicle_trip_component = None |
| 75 | + database = _MODELLER.emmebank |
| 76 | + tool = _MODELLER.tool('inro.emme.transit_assignment.extended.strategy_based_analysis') |
| 77 | + strategyValuesMatrixNumber = self.InitializeMatrix(database, xtmf_StrategyValuesMatrixNumber) |
| 78 | + spec = { |
| 79 | + "trip_components": |
| 80 | + { |
| 81 | + "boarding": None, |
| 82 | + "in_vehicle": xtmf_in_vehicle_trip_component, |
| 83 | + "aux_transit": None, |
| 84 | + "alighting": None |
| 85 | + }, |
| 86 | + "sub_path_combination_operator": xtmf_sub_path_combination_operator, |
| 87 | + "sub_strategy_combination_operator": "average", |
| 88 | + "selected_demand_and_transit_volumes": |
| 89 | + { |
| 90 | + "sub_strategies_to_retain": "ALL", |
| 91 | + "selection_threshold": { "lower": -999999, "upper": 999999 } |
| 92 | + }, |
| 93 | + "analyzed_demand": "mf" + str(xtmf_DemandMatrixNumber), |
| 94 | + "constraint": None, |
| 95 | + "results": |
| 96 | + { |
| 97 | + "strategy_values": strategyValuesMatrixNumber.id, |
| 98 | + "selected_demand": None, |
| 99 | + "transit_volumes": None, |
| 100 | + "aux_transit_volumes": None, |
| 101 | + "total_boardings": None, |
| 102 | + "total_alightings": None |
| 103 | + }, |
| 104 | + "type": "EXTENDED_TRANSIT_STRATEGY_ANALYSIS" |
| 105 | + } |
| 106 | + tool(spec, database.scenario(xtmf_ScenarioNumber), class_name=xtmf_ClassName, num_processors='max') |
| 107 | + |
| 108 | + def InitializeMatrix(self, database, matrixNumber): |
| 109 | + matrix_name = "mf" + str(matrixNumber) |
| 110 | + matrix = database.matrix(matrix_name) |
| 111 | + if matrix is None: |
| 112 | + matrix = database.create_matrix(matrix_name) |
| 113 | + return matrix |
0 commit comments