def _LoadClassInfo(self): if not self.Scenario.has_transit_results: return [] configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %self.Scenario if not exists(configPath): return [] with open(configPath) as reader: config = _parsedict(reader.read()) classes = [] i = 0 for info in config['strat_files']: className = info['name'] if(info['data'] is not None): if not 'alpha' in info['data']: if(config['data']['alphas'] is not None): alpha = config['data']['alphas'][i] i += 1 else: alpha = 0.0 else: alpha = info['data']['alpha'] classes.append((className, alpha)) return classes
def DetermineAnalyzedTransitDemandId(EMME_VERSION, scenario): configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %scenario with open(configPath) as reader: config = _parsedict(reader.read()) data = config['data'] if 'multi_class' in data: if data['multi_class'] == True: multiclass = "yes" else: multiclass = "no" else: multiclass = "no" strat = config['strat_files'] demandMatrices = {} if data['type'] == "MULTICLASS_TRANSIT_ASSIGNMENT": # multiclass extended transit assignment for i in range(len(strat)): demandMatrices[strat[i]["name"]] = strat[i]["data"]["demand"] return demandMatrices elif multiclass == "yes": # multiclass congested assignment for i in range(len(data["classes"])): demandMatrices[data["classes"][i] ["name"]] = data["classes"][i]["demand"] return demandMatrices else: #non multiclass congested strats = scenario.transit_strategies return strats.data["demand"]
def _GetAssignmentType(self): if not self.Scenario.has_transit_results: return None configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %self.Scenario if not exists(configPath): return self.Scenario.transit_assignment_type with open(configPath) as reader: config = _parsedict(reader.readline()) data = config['data'] return data['type']
def _GetMulticlass(self): if not self.Scenario.has_transit_results: return None configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %self.Scenario if not exists(configPath): return self.Scenario.transit_assignment_type with open(configPath) as reader: config = _parsedict(reader.read()) data = config['data'] if 'multi_class' in data: return data['multi_class'] else: return False
def DetermineAnalyzedTransitDemandId(EMME_VERSION, scenario): configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %scenario with open(configPath) as reader: config = _parsedict(reader.readline()) data = config['data'] if 'multi_class' in data: multiclass = "yes" else: multiclass = "no" dataType = data['type'] strat = config['strat_files'] if dataType == "MULTICLASS_TRANSIT_ASSIGNMENT" or multiclass == "yes": if len(strat) > 1: raise Exception() else: return strat[0]['data']['demand'] else: strats = scenario.transit_strategies return strats.data["demand"]
def _LoadClassInfo(self): if not self.Scenario.has_transit_results: return [] configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %self.Scenario if not exists(configPath): return [] with open(configPath) as reader: config = _parsedict(reader.readline()) classes = [] for info in config['strat_files']: className = info['name'] if not 'alpha' in info['data']: alpha = 0.0 else: alpha = info['data']['alpha'] classes.append((className, alpha)) return classes
def _LoadClassNames(self): if not self.Scenario.has_transit_results: return [] configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %self.Scenario if not exists(configPath): return [] with open(configPath) as reader: config = _parsedict(reader.readline()) classes = [] if self._GetAssignmentType() == 'MULTICLASS_TRANSIT_ASSIGNMENT': for classz in config['strat_files']: className = classz['name'] classes.append(className) else: info = config['data'] for classz in info['classes']: className = classz['name'] classes.append(className) return classes
def _Execute(self): with _m.logbook_trace(name="{classname} v{version}".format( classname=(self.__class__.__name__), version=self.version), attributes=self._GetAtts()): self.AccessStationRangeSplit = self.AccessStationRange.split('-') self.ZoneCentroidRangeSplit = self.ZoneCentroidRange.split('-') if len(self.ZoneCentroidRangeSplit) == 1: self.ZoneCentroidRangeSplit = [ int(self.ZoneCentroidRangeSplit[0]), int(self.ZoneCentroidRangeSplit[0]) ] if len(self.AccessStationRangeSplit) == 1: self.AccessStationRangeSplit = [ int(self.AccessStationRangeSplit[0]), int(self.AccessStationRangeSplit[0]) ] with nested(_util.tempExtraAttributeMANAGER(self.Scenario, 'TRANSIT_LINE', description= 'Line Flag'), _util.tempExtraAttributeMANAGER(self.Scenario, 'LINK', description= 'Flagged Line Aux Tr Volumes'), _util.tempExtraAttributeMANAGER(self.Scenario, 'TRANSIT_SEGMENT', description= 'Flagged Line Tr Volumes'), _util.tempExtraAttributeMANAGER(self.Scenario, 'LINK', description= 'Flagged Line Aux Tr Volumes'), _util.tempExtraAttributeMANAGER(self.Scenario, 'TRANSIT_SEGMENT', description= 'Flagged Line Tr Volumes'), _util.tempMatrixMANAGER(description="Origin Probabilities", matrix_type='FULL'), _util.tempMatrixMANAGER(description="Destinations Probabilities", matrix_type='FULL'), _util.tempMatrixMANAGER(description="DAT Origin Aggregation", matrix_type='ORIGIN'), _util.tempMatrixMANAGER(description="DAT Destination Aggregation", matrix_type='DESTINATION'), _util.tempMatrixMANAGER(description="Full Auto Origin Matrix", matrix_type='FULL'), _util.tempMatrixMANAGER(description="Full Auto Destination Matrix", matrix_type='FULL'), _util.tempMatrixMANAGER(description="Temp DAT Demand", matrix_type='FULL'), _util.tempMatrixMANAGER(description="Temp DAT Demand Secondary", matrix_type='FULL')) \ as (lineFlag, auxTransitVolumes, transitVolumes, auxTransitVolumesSecondary, transitVolumesSecondary, origProbMatrix, destProbMatrix, tempDatOrig, tempDatDest,autoOrigMatrix, autoDestMatrix, tempDatDemand, tempDatDemandSecondary): demandMatrixId = _util.DetermineAnalyzedTransitDemandId( EMME_VERSION, self.Scenario) configPath = dirname(_MODELLER.desktop.project_file_name( )) + "/Database/STRATS_s%s/config" % self.Scenario.id with open(configPath) as reader: config = _parsedict(reader.read()) data = config['data'] if 'multi_class' in data: if data['multi_class'] == True: multiclass = True else: multiclass = False else: multiclass = False strat = config['strat_files'] if data['type'] == "MULTICLASS_TRANSIT_ASSIGNMENT": multiclass = True className = strat[0]["name"] elif multiclass == True: className = data["classes"][0]["name"] dataType = data['type'] with _m.logbook_trace("Flagging chosen lines"): networkCalculation(self._BuildNetCalcSpec(lineFlag.id), scenario=self.Scenario) with _m.logbook_trace("Running strategy analysis"): if multiclass == True: report = stratAnalysis(self._BuildStratSpec( lineFlag.id, demandMatrixId[className], self.ZoneCentroidRangeSplit[0], self.ZoneCentroidRangeSplit[1]), scenario=self.Scenario, class_name=className) else: report = stratAnalysis(self._BuildStratSpec( lineFlag.id, demandMatrixId, self.ZoneCentroidRangeSplit[0], self.ZoneCentroidRangeSplit[1]), scenario=self.Scenario) with _m.logbook_trace("Calculating DAT demand"): if self.AccessStationRangeSplit[1] != 0: if multiclass == True: pathAnalysis(self._BuildPathSpec( lineFlag.id, self.ZoneCentroidRangeSplit, self.AccessStationRangeSplit, transitVolumes.id, auxTransitVolumes.id, tempDatDemand.id, demandMatrixId[className]), scenario=self.Scenario, class_name=className) pathAnalysis(self._BuildPathSpec( lineFlag.id, self.AccessStationRangeSplit, self.ZoneCentroidRangeSplit, transitVolumesSecondary.id, auxTransitVolumesSecondary.id, tempDatDemandSecondary.id, demandMatrixId[className]), scenario=self.Scenario, class_name=className) else: pathAnalysis(self._BuildPathSpec( lineFlag.id, self.ZoneCentroidRangeSplit, self.AccessStationRangeSplit, transitVolumes.id, auxTransitVolumes.id, tempDatDemand.id, demandMatrixId), scenario=self.Scenario) pathAnalysis(self._BuildPathSpec( lineFlag.id, self.AccessStationRangeSplit, self.ZoneCentroidRangeSplit, transitVolumesSecondary.id, auxTransitVolumesSecondary.id, tempDatDemandSecondary.id, demandMatrixId), scenario=self.Scenario) with _m.logbook_trace("Calculating WAT demand"): if multiclass == True: matrixCalc(self._ExpandStratFractions( demandMatrixId[className]), scenario=self.Scenario) else: matrixCalc(self._ExpandStratFractions(demandMatrixId), scenario=self.Scenario) with _m.logbook_trace("Sum transit demands"): matrixCalc(self._BuildSimpleMatrixCalcSpec( self.LineODMatrixId, " + ", tempDatDemand.id, self.LineODMatrixId), scenario=self.Scenario) matrixCalc(self._BuildSimpleMatrixCalcSpec( self.LineODMatrixId, " + ", tempDatDemandSecondary.id, self.LineODMatrixId), scenario=self.Scenario) with _m.logbook_trace("Aggregating transit matrices"): matrixAgg(self.LineODMatrixId, self.AggOriginMatrixId, agg_op="+", scenario=self.Scenario) matrixAgg(self.LineODMatrixId, self.AggDestinationMatrixId, agg_op="+", scenario=self.Scenario) with _m.logbook_trace("Copying auto matrices"): matrixCopy(self.AutoODMatrixId, autoOrigMatrix.id, matrix_name="autoOrigFull", matrix_description="", scenario=self.Scenario) matrixCopy(self.AutoODMatrixId, autoDestMatrix.id, matrix_name="autoDestFull", matrix_description="", scenario=self.Scenario) with _m.logbook_trace("Building probability matrices"): network = self.Scenario.get_network() nodes = range( 9700, 9999) #consider allowing user inputted range later on #Create a dictionary of origin/destination probabilities for the line group for all selected nodes stationProbs = self._CalcODProbabilities( network, nodes, auxTransitVolumes.id, auxTransitVolumesSecondary.id) #Convert the dictionary in an origin and a destination probability matrix self._ApplyODProbabilities(stationProbs, origProbMatrix, 'ORIGIN') self._ApplyODProbabilities(stationProbs, destProbMatrix, 'DESTINATION') #Multiply the probability matrices by the auto demand matrix to yield origin and destination DAT demands for the selected nodes #if EMME_VERSION >= (4,2,1): # matrixCalc(self._BuildSimpleMatrixCalcSpec(origProbMatrix.id, " * ", autoOrigMatrix.id, autoOrigMatrix.id), self.Scenario, # num_processors=self.NumberOfProcessors) # matrixCalc(self._BuildSimpleMatrixCalcSpec(destProbMatrix.id, " * ", autoDestMatrix.id, autoDestMatrix.id), self.Scenario, # num_processors=self.NumberOfProcessors) #else: matrixCalc( self._BuildSimpleMatrixCalcSpec( origProbMatrix.id, " * ", autoOrigMatrix.id, autoOrigMatrix.id), self.Scenario) matrixCalc( self._BuildSimpleMatrixCalcSpec( destProbMatrix.id, " * ", autoDestMatrix.id, autoDestMatrix.id), self.Scenario) with _m.logbook_trace( "Aggregating DAT demand and producing final O & D matrices" ): #Aggregate the adjusted DAT matrices matrixAgg(autoOrigMatrix.id, tempDatOrig.id, agg_op="+", scenario=self.Scenario) matrixAgg(autoDestMatrix.id, tempDatDest.id, agg_op="+", scenario=self.Scenario) #Find the total O & D matrices #if EMME_VERSION >= (4,2,1): # matrixCalc(self._BuildSimpleMatrixCalcSpec(autoOrigMatrix.id, " + ", self.AggOriginMatrixId, self.AggOriginMatrixId), self.Scenario, # num_processors=self.NumberOfProcessors) # matrixCalc(self._BuildSimpleMatrixCalcSpec(autoDestMatrix.id, " + ", self.AggDestinationMatrixId, self.AggDestinationMatrixId), self.Scenario, # num_processors=self.NumberOfProcessors) #else: matrixCalc( self._BuildSimpleMatrixCalcSpec( tempDatOrig.id, " + ", self.AggOriginMatrixId, self.AggOriginMatrixId), self.Scenario) matrixCalc( self._BuildSimpleMatrixCalcSpec( tempDatDest.id, " + ", self.AggDestinationMatrixId, self.AggDestinationMatrixId), self.Scenario) _MODELLER.desktop.refresh_needed( True) #Tell the desktop app that a data refresh is required
def __call__(self, xtmf_ScenarioNumber, xtmf_OutputPathFile, xtmf_ODdist): self.ScenarioNumber = int(xtmf_ScenarioNumber) self.scenario = _m.Modeller().emmebank.scenario(self.ScenarioNumber) if (self.scenario == None): raise Exception("Scenario %s was not found!" % xtmf_ScenarioNumber) if not self.scenario.has_transit_results: raise Exception( "Scenario %s does not have transit assignment results" % xtmf_ScenarioNumber) self.OutputPathFile = xtmf_OutputPathFile self.ODdist = xtmf_ODdist self.NumberOfProcessors = cpu_count() '''self.ClassName = xtmf_ClassName self.IterationNumber = xtmf_IterationNumber''' self.demandMatrices = _util.DetermineAnalyzedTransitDemandId( EMME_VERSION, self.scenario) configPath = dirname(_MODELLER.desktop.project_file_name()) \ + "/Database/STRATS_s%s/config" %self.ScenarioNumber with open(configPath) as reader: config = _parsedict(reader.readline()) data = config['data'] if 'multi_class' in data: if data['multi_class'] == True: self.Multiclass = True else: self.Multiclass = False else: if data['type'] == "MULTICLASS_TRANSIT_ASSIGNMENT": self.Multiclass = True else: self.Multiclass = False '''if self.Multiclass == True: self.AnalyzedDemandMatrixID = demandMatrices[self.ClassName] else: self.AnalyzedDemandMatrixID = demandMatrices self.SelectedPaths = xtmf_SelectedPaths self.SelectPathsBy = xtmf_SelectPathsBy self.SelectedPathsCriteria = xtmf_SelectedPathsCriteria self.SelectedPathsThresholdLower = xtmf_SelectedPathsThresholdLower self.SelectedPathsThresholdUpper = xtmf_SelectedPathsThresholdUpper self.PathDetail = xtmf_PathsDetails.split(',') #self.PathsToOutput = self._VerifyNonNullWithError(self.PathDetail[0],"Paths to Output must be specfied") self.TotalImpedenceDetails = self._ConvertToBool(self.PathDetail[0]) self.AverageBoardingDetails = self._ConvertToBool(self.PathDetail[1]) self.DistanceDetails = self._ConvertToBool(self.PathDetail[2]) self.TimesAndCostsType = self._VerifyNonNullWithError(self.PathDetail[3],"Times and cost type must be defined") self.FirstWaitingTime = self._ConvertToBool(self.PathDetail[4]) self.TotalWaitingTime = self._ConvertToBool(self.PathDetail[5]) self.FirstBoardingTime = self._ConvertToBool(self.PathDetail[6]) self.TotalBoardingTime = self._ConvertToBool(self.PathDetail[7]) self.InVehicleTime = self._ConvertToBool(self.PathDetail[8]) self.AuxTransitTime = self._ConvertToBool(self.PathDetail[9]) self.FirstBoardingCost = self._ConvertToBool(self.PathDetail[10]) self.TotalBoardingCost = self._ConvertToBool(self.PathDetail[11]) self.InVehicleCost = self._ConvertToBool(self.PathDetail[12]) self.AuxTransitCost = self._ConvertToBool(self.PathDetail[13]) self.ZonesDetails = self._ConvertToBool(self.PathDetail[14]) self.PathNumberDetails =self._ConvertToBool(self.PathDetail[15]) self.ProportionDetails = self._ConvertToBool(self.PathDetail[16]) self.SelectedVolumeDetails = self._ConvertToBool(self.PathDetail[17]) self.VolumeDetails = self._ConvertToBool(self.PathDetail[18]) self.PathValueDetails = self._ConvertToBool(self.PathDetail[19]) self.PathItemDetails = self._ConvertToBool(self.PathDetail[20]) self.NodesDetails = self._ConvertToBool(self.PathDetail[21]) self.ModeDetails = self._ConvertToBool(self.PathDetail[22]) self.TransitLineDetails = self._ConvertToBool(self.PathDetail[23]) self.AuxTransitSubPathDetails = self._ConvertToBool(self.PathDetail[24]) self.SubPathDetails = self._ConvertToBool(self.PathDetail[25]) self.ODZoneDetails = self._ConvertToBool(self.PathDetail[26]) self.ODPathStatDetails = self._ConvertToBool(self.PathDetail[27]) self.ODPathNumberDetails = self._ConvertToBool(self.PathDetail[28]) self.ODSelectedDemandDetails = self._ConvertToBool(self.PathDetail[29]) self.ODDemandDetails = self._ConvertToBool(self.PathDetail[30]) self.ODAggPathValue = self._ConvertToBool(self.PathDetail[31]) self.ODDetails = self._ConvertToBool(self.PathDetail[32])''' try: self._Execute() except Exception, e: msg = str(e) + "\n" + _traceback.format_exc(e) raise Exception(msg)