fileLines = filecontent.split('\n') for line in fileLines: # skip conditions #if 'Bus' in line: # continue if line == '': continue ## words = line.split('->') planningBus = words[0].strip() CAPEBus = words[1].strip() ManualMappingDict[CAPEBus] = [planningBus] # get a set of all neighbours in a depth of 5 of the CAPE bus which has been manually mapped for CAPEBus in ManualMappingDict.keys(): Depth5BranchDataDict = getNeighboursDepthN(CAPEBus, CAPERaw, 5) NeighbourSetDepth5 = list( set(Depth5BranchDataDict[CAPEBus].toBus) ) # convert to set to eliminate any duplicates and then convert back to list # Frontier will add only those CAPE buses which have a verified mapping #print CAPEBus frontier = Queue(maxsize=0) frontier.put(CAPEBus) autoMapDict = dict(ManualMappingDict) # get any ties of the input planning bus originPlanningBus = autoMapDict[CAPEBus][ 0] # the planning bus which is mapped to the CAPE bus given in the input file if originPlanningBus in BranchGroupDictPlanning.keys( ): # if the origin planning bus has any ties, map the set to the CAPEBus
""" Script to get path from one bus to another bus (within a prespecified depth) """ CAPERaw = 'Raw0509.raw' from getNeighboursAtCertainDepthFn import getNeighboursDepthN while True: OriginBus = raw_input('Please enter the origin bus: ').strip() endBus = raw_input('Please enter the end bus: ').strip() searchDepth = int(raw_input('Search depth: ')) tmpData = getNeighboursDepthN(OriginBus, CAPERaw, searchDepth) try: toBusInd = tmpData[OriginBus].toBus.index(endBus) print 'Path:' P = tmpData[OriginBus].Path[toBusInd] print P print '\n\n\n' except ValueError: print 'No bus found in specified searchDepth, please try again! \n'