@@ -126,7 +126,7 @@ def __call__(
126126 RunTitle ,
127127 TrafficClasses ,
128128 ):
129- print ("starting ..." )
129+ print ("Starting STTA ..." )
130130 # ---1 Set up Scenario
131131 Scenario = _m .Modeller ().emmebank .scenario (ScenarioNumber )
132132 if Scenario is None :
@@ -150,7 +150,6 @@ def __call__(
150150 tc ["TollWeightList" ] = [float (x ) for x in tc ["TollWeightList" ].split ("," )]
151151
152152 try :
153- print ("Starting assignment." )
154153 self ._execute (
155154 Scenario ,
156155 IntervalLengthList ,
@@ -171,7 +170,7 @@ def __call__(
171170 RunTitle ,
172171 Parameters ,
173172 )
174- print ("Assignment complete." )
173+ print ("STTA complete." )
175174 except Exception as e :
176175 raise Exception (_util .formatReverseStack ())
177176
@@ -212,12 +211,12 @@ def _execute(
212211 IntervalLengthList ,
213212 tc ["DemandMatrixNumber" ],
214213 "demand_matrix" ,
215- [("cost_matrix" , tc ["CostMatrixNumber" ]), ("time_matrix" , tc ["TimeMatrixNumber" ]), ( "toll_matrix" , tc [ "TollMatrixNumber" ]) ],
214+ [("cost_matrix" , tc ["CostMatrixNumber" ]), ("time_matrix" , tc ["TimeMatrixNumber" ])],
216215 )
217216 allMatrixDictsList .append (all_matrix_dict )
218217 # load all time dependent output matrices
219218 self ._load_input_matrices (allMatrixDictsList , "demand_matrix" )
220- self ._load_output_matrices (allMatrixDictsList , ["cost_matrix" , "time_matrix" , "toll_matrix" ])
219+ self ._load_output_matrices (allMatrixDictsList , ["cost_matrix" , "time_matrix" ])
221220
222221 with _m .logbook_trace (
223222 name = "%s (%s v%s)" % (self .RunTitle , self .__class__ .__name__ , self .version ),
@@ -237,7 +236,6 @@ def _execute(
237236 # initialize output matrices
238237 self ._init_output_matrices (allMatrixDictsList , temporaryMatrixList , outputMatrixName = "cost_matrix" , description = "" )
239238 self ._init_output_matrices (allMatrixDictsList , temporaryMatrixList , outputMatrixName = "time_matrix" , description = "" )
240- self ._init_output_matrices (allMatrixDictsList , temporaryMatrixList , outputMatrixName = "toll_matrix" , description = "" )
241239 self ._init_analysis_matrices (Parameters , len (IntervalLengthList ))
242240 with self .temporaryAttributeManager (Scenario ) as tempAttributeList :
243241 timeDependentVolumeAttributeLists = []
@@ -267,40 +265,39 @@ def _execute(
267265 self ._tracker .completeSubtask ()
268266 # Assign traffic to road network per time period
269267 with _trace ("Running Road Assignments." ):
270- completed_path_analysis = False
271- if completed_path_analysis is False :
272- modeList = self ._loadModeList (Parameters )
273- stta_spec = self ._get_primary_STTA_spec (
274- allMatrixDictsList ,
275- modeList ,
276- volumeAttributeLists ,
277- costAttributeLists ,
278- IntervalLengthList ,
279- StartTime ,
280- ExtraTimeInterval ,
281- NumberOfExtraTimeIntervals ,
282- InnerIterations ,
283- OuterIterations ,
284- CoarseRGap ,
285- FineRGap ,
286- CoarseBRGap ,
287- FineBRGap ,
288- NormalizedGap ,
289- Parameters ,
290- PerformanceFlag ,
291- linkComponentAttributeList ,
292- CreateLinkComponentAttribute ,
293- LinkComponentAttribute ,
294- StartIndex ,
295- timeResultAttributeList ,
296- )
297- report = self ._tracker .runTool (trafficAssignmentTool , stta_spec , scenario = Scenario )
268+ modeList = self ._loadModeList (Parameters )
269+ stta_spec = self ._get_primary_STTA_spec (
270+ allMatrixDictsList ,
271+ modeList ,
272+ volumeAttributeLists ,
273+ costAttributeLists ,
274+ IntervalLengthList ,
275+ StartTime ,
276+ ExtraTimeInterval ,
277+ NumberOfExtraTimeIntervals ,
278+ InnerIterations ,
279+ OuterIterations ,
280+ CoarseRGap ,
281+ FineRGap ,
282+ CoarseBRGap ,
283+ FineBRGap ,
284+ NormalizedGap ,
285+ Parameters ,
286+ PerformanceFlag ,
287+ linkComponentAttributeList ,
288+ CreateLinkComponentAttribute ,
289+ LinkComponentAttribute ,
290+ StartIndex ,
291+ timeResultAttributeList ,
292+ )
293+ report = self ._tracker .runTool (trafficAssignmentTool , stta_spec , scenario = Scenario )
298294 checked = self ._load_stopping_criteria (report )
299295 number = checked [0 ]
300296 stopping_criterion = checked [1 ]
301297 value = checked [2 ]
302298 print ("Primary assignment complete at %s iterations." % number )
303299 print ("Stopping criterion was %s with a value of %s." % (stopping_criterion , value ))
300+ self .correct_cost_matrices (Parameters , len (IntervalLengthList ))
304301
305302 def _load_atts (self , Scenario , run_title , max_outer_iterations , max_inner_iterations , traffic_classes , modeller_namespace ):
306303 time_matrix_ids = ["mf" + str (mtx ["TimeMatrixNumber" ]) for mtx in traffic_classes ]
@@ -420,7 +417,7 @@ def _init_input_matrices(self, allMatrixDictsList, temporaryMatrixList, inputMat
420417 for matrix_list in allMatrixDictsList :
421418 for i , mtx in enumerate (matrix_list [inputMatrixName ]):
422419 if mtx == None :
423- mtx = _util .initializeMatrix (matrix_type = "FULL" )
420+ mtx = _util .initializeMatrix (matrix_type = "FULL" , default = 0.00000001 )
424421 temporaryMatrixList .append (mtx )
425422 matrix_list [inputMatrixName ][i ] = mtx
426423
@@ -519,7 +516,7 @@ def _process_traffic_attribute(self, Scenario, traffic_attrib_id, attribute_type
519516 def _calculate_applied_toll_factor (self , Parameters ):
520517 applied_toll_factor_list = []
521518 for tc in Parameters ["TrafficClasses" ]:
522- if len (tc ["TollWeightList" ]) != 0 :
519+ if len (tc ["TollWeightList" ]) > 0 :
523520 try :
524521 toll_weight_list = [60 / weight for weight in tc ["TollWeightList" ]]
525522 applied_toll_factor_list .append (toll_weight_list )
@@ -596,6 +593,7 @@ def _get_primary_STTA_spec(
596593 number_of_processors = multiprocessing .cpu_count ()
597594 else :
598595 number_of_processors = max (multiprocessing .cpu_count () - 1 , 1 )
596+
599597 # Generic Spec for STTA
600598 STTA_spec = {
601599 "type" : "SPACE_TIME_TRAFFIC_ASSIGNMENT" ,
@@ -634,10 +632,9 @@ def convert_bound(bound_str):
634632 return None if bound_str == "None" else float (bound_str )
635633
636634 def append_path_analyes (stta_class , parameters , i ):
637- tc = Parameters ['TrafficClasses' ]
635+ tc = Parameters ['TrafficClasses' ][ i ]
638636 if not ('PathAnalyses' in tc ):
639637 return
640-
641638 path = tc ['PathAnalyses' ]
642639 analysis = {
643640 "link_component" : path ['AttributeId' ],
@@ -691,7 +688,7 @@ def append_traversal_analysis(stta_class, parameters, i):
691688 "demand" : matrix_dict ["demand_matrix" ][0 ].id ,
692689 "generalized_cost" : {
693690 "link_costs" : costAttributeLists [i ][0 ].id ,
694- "od_fixed_cost" : None ,
691+ "od_fixed_cost" : matrix_dict [ "cost_matrix" ][ 0 ]. id ,
695692 },
696693 "results" : {
697694 "link_volumes" : volumeAttributeLists [i ][0 ],
@@ -732,6 +729,27 @@ def _load_stopping_criteria(self, report):
732729 else :
733730 value = "undefined"
734731 return number , stopping_criterion , value
732+
733+ def correct_cost_matrices (self , parameters , number_of_intervals ):
734+ for tc in parameters ['TrafficClasses' ]:
735+ first_cost = int (tc ['CostMatrixNumber' ])
736+ # If this isn't temporary then we need to adjust these matrices
737+ if first_cost <= 0 :
738+ continue
739+
740+ for i in range (number_of_intervals ):
741+ matrix_number = first_cost + i
742+ perception = 60 / tc ['TollWeightList' ][i ]
743+ spec = {
744+ "expression" : "mf%s/%f" % (matrix_number , perception ),
745+ "result" : "mf%s" % matrix_number ,
746+ "constraint" : {"by_value" : None , "by_zone" : None },
747+ "aggregation" : {"origins" : None , "destinations" : None },
748+ "type" : "MATRIX_CALCULATION" ,
749+ }
750+ matrixCalcTool (spec )
751+
752+ return
735753
736754 @contextmanager
737755 def temporaryMatricesManager (self ):
0 commit comments