def getAgvStop(stop): curStop = "01-112-3" if stop > 0: if 4000 <= stop: # charge stop stopStr = ("{}".format(stop)).zfill(4) curStop = "01-{}-1".format(stopStr) print(curStop) elif 50 > stop: # main stop stopStr = ("{}".format(stop)).zfill(2) curStop = "{}-0000".format(stopStr) print(curStop) elif 100 > stop: # connection area stopStr = ("{}".format(stop)).zfill(4) curStop = "01-{}-1".format(stopStr) print(curStop) else: subStop = int(stop / 100) if 1 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "01-{}-1".format(stopStr) print(curStop) elif 2 == subStop or 3 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "02-{}-1".format(stopStr) print(curStop) elif 4 == subStop or 5 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "03-{}-1".format(stopStr) print(curStop) elif 6 == subStop or 7 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "04-{}-1".format(stopStr) print(curStop) elif 8 == subStop or 9 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "05-{}-1".format(stopStr) print(curStop) elif 10 == subStop or 11 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "06-{}-1".format(stopStr) print(curStop) elif 12 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "07-{}-1".format(stopStr) print(curStop) elif 14 == subStop or 15 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "08-{}-1".format(stopStr) print(curStop) elif 16 == subStop or 17 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "09-{}-1".format(stopStr) print(curStop) elif 18 == subStop or 19 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "10-{}-1".format(stopStr) print(curStop) elif 20 == subStop or 21 == subStop: stopStr = ("{}".format(stop)).zfill(4) curStop = "11-{}-1".format(stopStr) print(curStop) return curStop ''' start = "01-0112-3" end = "02-0311-2" ''' def genPath(start, end): print("start {}, end {}".format(start, end)) startParts = start.split("-") endParts = end.split("-") if endParts[0] != startParts[0]: #cross stop startMainStop = int(startParts[0]) stopMainStop = int(endParts[0]) startMain = [startMainStop, stopMainStop] # startMain = [] # if startMainStop > stopMainStop: # startMain = [x for x in range(startMainStop, stopMainStop - 1, -1)] # else: # startMain = [x for x in range(startMainStop, stopMainStop + 1)] startStop = int(startParts[1]) if startStop >= 5000: halfPath1 = [startStop, 5003, 5002, 5001, 5000] elif startStop >= 4000: halfPath1 = [startStop, 4000] #charge Stop 01 -> 4000 -> 4001 -> 4002 # halfPath1 = [x for x in range(startStop, 3999, -1)] elif 50 < startStop and 100 > startStop: halfPath1 = [startStop, 63, 62, 61, 60] #connection area stop number start from 60 to 68 # halfPath1 = [x for x in range(startStop, 59, -1)] elif startStop > 0: crossStop1 = int(startStop / 100)*100 + 10 # halfPath1 = [x for x in range(startStop, crossStop1 - 1, -1)] halfPath1 = [startStop, crossStop1] else: halfPath1 = [] endStop = int(endParts[1]) if endStop >= 5000: #charge Stop 01 -> 4000 -> 4001 -> 4002 # halfPath2 = [x for x in range(4000, endStop + 1)] halfPath2 = [5000, 5001, 5002, 5003, endStop] elif endStop >= 4000: #charge Stop 01 -> 4000 -> 4001 -> 4002 # halfPath2 = [x for x in range(4000, endStop + 1)] halfPath2 = [4000, 4001, endStop] elif 50 < endStop and 100 > endStop: #connection area stop number start from 60 to 68 # halfPath2 = [x for x in range(60, endStop + 1)] halfPath2 = [60, 61, 62, 63, endStop] elif endStop > 0: crossStop2 = int(endStop / 100)*100 + 10 # halfPath2 = [x for x in range(crossStop2, endStop + 1)] halfPath2 = [crossStop2, endStop] else: halfPath2 = [] return halfPath1 + startMain + halfPath2 elif endParts[0] == startParts[0]: # in same passway endStop = int(endParts[1]) startStop = int(startParts[1]) if endStop == startStop and 0 != startStop: # need to be done #same stop return [startStop] elif endStop == startStop and 0 == startStop: return [ int(startParts[0]) ] else: if abs( endStop - startStop ) < 100 and endStop > 100 and startStop > 100: #don't include connection area # in same line if endStop > startStop: # return [x for x in range(startStop, endStop + 1)] return [startStop, endStop] else: # return [x for x in range(startStop, endStop - 1, -1)] return [startStop, endStop] elif abs( endStop - startStop ) < 100 and endStop < 100 and endStop > 50 and startStop < 100 and startStop > 50: #connection area # in same line if endStop > startStop > 63: # return [x for x in range(startStop, endStop + 1)] return [startStop, endStop] elif endStop > startStop: return [x for x in range(startStop, endStop + 1)] elif 63 < endStop < startStop: # return [x for x in range(startStop, endStop - 1, -1)] return [startStop, endStop] elif endStop < startStop: return [x for x in range(startStop, endStop - 1, -1)] elif abs( endStop - startStop ) < 100 and endStop >= 4000 and startStop >= 4000: #Charge stop # in same line if endStop > startStop: # return [x for x in range(startStop, endStop + 1)] return [startStop, endStop] else: # return [x for x in range(startStop, endStop - 1, -1)] return [startStop, endStop] else: if startStop >= 5000: #charge stop # halfPath1 = [x for x in range(startStop, 3999, -1)] halfPath1 = [startStop, 5003, 5002, 5001, 5000] elif startStop >= 4000: #charge stop # halfPath1 = [x for x in range(startStop, 3999, -1)] halfPath1 = [startStop, 4000] elif 50 < startStop and 100 > startStop: #connection area stop number start from 60 to 68 # halfPath1 = [x for x in range(startStop, 59, -1)] halfPath1 = [startStop, 63, 62, 61, 60] elif startStop > 0: # cross line crossStop1 = int(startStop / 100)*100 + 10 # halfPath1 = [x for x in range(startStop, crossStop1 - 1, -1)] halfPath1 = [startStop, crossStop1] else: halfPath1 = [] if endStop >= 5000: #charge stop # halfPath2 = [x for x in range(4000, endStop + 1)] halfPath2 = [5000, 5001, 5002, 5003, endStop] elif endStop >= 4000: #charge stop # halfPath2 = [x for x in range(4000, endStop + 1)] halfPath2 = [4000, endStop] elif 50 < endStop and 100 > endStop: #connection area stop number start from 60 to 68 # halfPath2 = [x for x in range(60, endStop + 1)] halfPath2 = [60, 61, 62, 63, endStop] elif endStop > 0: crossStop2 = int(endStop / 100)*100 + 10 # halfPath2 = [x for x in range(crossStop2, endStop + 1)] halfPath2 = [crossStop2, endStop] else: halfPath2 = [] # print("halfPath1 {}, startParts[0] {}, halfPath2 {}".format(halfPath1, startParts[0], halfPath2)) return halfPath1 + [ int(startParts[0]) ] + halfPath2