diff --git a/docs/mmitss-deployment/mmitss-build-docker-image.docx b/docs/mmitss-deployment/mmitss-build-docker-image.docx index 3f8b1181..56943e5b 100644 Binary files a/docs/mmitss-deployment/mmitss-build-docker-image.docx and b/docs/mmitss-deployment/mmitss-build-docker-image.docx differ diff --git a/docs/mmitss-deployment/mmitss-field-deployment.docx b/docs/mmitss-deployment/mmitss-field-deployment.docx index 5c987c2d..b0ba0411 100644 Binary files a/docs/mmitss-deployment/mmitss-field-deployment.docx and b/docs/mmitss-deployment/mmitss-field-deployment.docx differ diff --git a/src/mrp/priority-request-solver/Test/PriorityRequestSender/priorityRequest.json b/src/mrp/priority-request-solver/Test/PriorityRequestSender/priorityRequest.json index 9415f650..d6f30d02 100644 --- a/src/mrp/priority-request-solver/Test/PriorityRequestSender/priorityRequest.json +++ b/src/mrp/priority-request-solver/Test/PriorityRequestSender/priorityRequest.json @@ -4,11 +4,11 @@ "intersectionID": 44383, "minuteOfYear": 487593, "msOfMinute": 21000, - "noOfRequest": 1, + "noOfRequest": 2, "regionalID": 0, "requestorInfo": [ { - "ETA": 38.0, + "ETA": 35.0, "ETA_Duration": 4.0, "basicVehicleRole": 9, "elevation_Meter": 0.0, @@ -17,10 +17,25 @@ "latitude_DecimalDegree": 0.0, "longitude_DecimalDegree": 0.0, "priorityRequestStatus": 0, - "requestedSignalGroup": 8, - "speed_MeterPerSecond": 0.0, + "requestedSignalGroup": 4, + "speed_MeterPerSecond": 14.5, "vehicleID": 601, "vehicleType": 9 + }, + { + "ETA": 25.0, + "ETA_Duration": 4.0, + "basicVehicleRole": 16, + "elevation_Meter": 0.0, + "heading_Degree": 0.0, + "inBoundLaneID": 0, + "latitude_DecimalDegree": 0.0, + "longitude_DecimalDegree": 0.0, + "priorityRequestStatus": 0, + "requestedSignalGroup": 2, + "speed_MeterPerSecond": 15.0, + "vehicleID": 602, + "vehicleType": 6 } ] } diff --git a/src/mrp/priority-request-solver/Test/TCIMsgSender/currPhase.json b/src/mrp/priority-request-solver/Test/TCIMsgSender/currPhase.json index 00f8d665..aa093395 100644 --- a/src/mrp/priority-request-solver/Test/TCIMsgSender/currPhase.json +++ b/src/mrp/priority-request-solver/Test/TCIMsgSender/currPhase.json @@ -1,14 +1,14 @@ { "currentPhases": [ { - "Phase": 1, + "Phase": 4, "State": "green", - "ElapsedTime": 100 + "ElapsedTime": 200 }, { - "Phase": 5, + "Phase": 8, "State": "green", - "ElapsedTime": 100 + "ElapsedTime": 200 } ], "MsgType": "CurrNextPhaseStatus", diff --git a/src/mrp/priority-request-solver/Test/TCIMsgSender/signalPlan.json b/src/mrp/priority-request-solver/Test/TCIMsgSender/signalPlan.json index bef15e79..22a1e8ae 100644 --- a/src/mrp/priority-request-solver/Test/TCIMsgSender/signalPlan.json +++ b/src/mrp/priority-request-solver/Test/TCIMsgSender/signalPlan.json @@ -45,11 +45,11 @@ "Passage": [ 2.0, 5.0, - 0.0, + 2.0, 5.0, 2.0, 5.0, - 0.0, + 2.0, 5.0 ], "MaxGreen": [ @@ -65,21 +65,21 @@ "YellowChange": [ 3.0, 4.0, - 0.0, + 3.0, 3.6, 3.0, 4.0, - 0.0, + 3.0, 3.6 ], "RedClear": [ 1.0, 2.5, - 0.0, + 1.0, 3.4000000000000004, 1.0, 2.5, - 0.0, + 1.0, 3.4000000000000004 ], "PhaseRing": [ diff --git a/src/tools/time-phase-diagram/Time-Phase-Diagram.py b/src/tools/time-phase-diagram/Time-Phase-Diagram.py new file mode 100644 index 00000000..018eb649 --- /dev/null +++ b/src/tools/time-phase-diagram/Time-Phase-Diagram.py @@ -0,0 +1,572 @@ +import numpy as np +import matplotlib +import matplotlib.pyplot as plt +from matplotlib.collections import PatchCollection +import json + + +def getStartingPhases(): + """ + Get the stating phase information from the Results.txt file + """ + with open('/nojournal/bin/Results.txt') as f: + first_line = f.readline() + + startingPhase1, startingPhase2 = first_line.split() + # Converting starting phase into integar value + startingPhase1 = int(startingPhase1) + # Converting starting phase into integar value + startingPhase2 = int(startingPhase2) + + return startingPhase1, startingPhase2 + + +def phaseGroupInRing(startingPhase, ring_phases, phasesInRing): + """ + starting Phase is already appended into phasesInring list + Appending the phases which are greater than the starting phase for that ring + Appending the phases which are less than the starting phase for that ring + Repeat all the phase number by using extend method + """ + i = startingPhase + for i in ring_phases: + if i > startingPhase: + phasesInRing.append(i) + + for i in ring_phases: + if i < startingPhase: + phasesInRing.append(i) + # Extending the phases for 2nd & 3rdcycles + phasesInRing.extend(phasesInRing*1) + + return phasesInRing + + +def getInitToPhasesAndElaspedGreenTime(): + with open('/nojournal/bin/Results.txt') as f: + + for i, line in enumerate(f): + if i == 1: + break + return line + + +def getPhaseDuration(phase_Times, startingPhase, CP, RingNo): + """ + Find the phase Duration for all the planned phases. + Store the information of left and critical points based on ring number for each cycle + """ + + # Storing Left Critcial Points information + if(CP == 'Left'): + # Left Critical Points information for first cycle + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i == 2: + break + # phaseDurationOfP1K1R1 means phase duration of phase 1 (P1) in ring1 (R1) for cycle 1 (K1) + phaseDurationOfP1K1R1, phaseDurationOfP2K1R1, phaseDurationOfP3K1R1, phaseDurationOfP4K1R1, phaseDurationOfP5K1R1, phaseDurationOfP6K1R1, phaseDurationOfP7K1R1, phaseDurationOfP8K1R1 = line.split() + + if(RingNo == 'Ring1'): + left_r1_k1_Phase_Times = [float(phaseDurationOfP1K1R1), float( + phaseDurationOfP2K1R1), float(phaseDurationOfP3K1R1), float(phaseDurationOfP4K1R1)] + if startingPhase > 1: + left_r1_k1_Phase_Times = left_r1_k1_Phase_Times[startingPhase-1:] + + elif(RingNo == 'Ring2'): + left_r2_k1_Phase_Times = [float(phaseDurationOfP5K1R1), float( + phaseDurationOfP6K1R1), float(phaseDurationOfP7K1R1), float(phaseDurationOfP8K1R1)] + if startingPhase > 4: + left_r2_k1_Phase_Times = left_r2_k1_Phase_Times[startingPhase-5:] + + # Left Critical Points information for second cycle + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i == 3: + break + phaseDurationOfP1K2R1, phaseDurationOfP2K2R1, phaseDurationOfP3K2R1, phaseDurationOfP4K2R1, phaseDurationOfP5K2R1, phaseDurationOfP6K2R1, phaseDurationOfP7K2R1, phaseDurationOfP8K2R1 = line.split() + + if(RingNo == 'Ring1'): + left_r1_k2_Phase_Times = [float(phaseDurationOfP1K2R1), float( + phaseDurationOfP2K2R1), float(phaseDurationOfP3K2R1), float(phaseDurationOfP4K2R1)] + left_r1_k1_Phase_Times.extend(left_r1_k2_Phase_Times) + + elif(RingNo == 'Ring2'): + left_r2_k2_Phase_Times = [float(phaseDurationOfP5K2R1), float( + phaseDurationOfP6K2R1), float(phaseDurationOfP7K2R1), float(phaseDurationOfP8K2R1)] + left_r2_k1_Phase_Times.extend(left_r2_k2_Phase_Times) + + # Left Critical Points information for third cycle + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i == 4: + break + phaseDurationOfP1K3R1, phaseDurationOfP2K3R1, phaseDurationOfP3K3R1, phaseDurationOfP4K3R1, phaseDurationOfP5K3R1, phaseDurationOfP6K3R1, phaseDurationOfP7K3R1, phaseDurationOfP8K3R1 = line.split() + + if(RingNo == 'Ring1'): + left_r1_k3_Phase_Times = [float(phaseDurationOfP1K3R1), float( + phaseDurationOfP2K3R1), float(phaseDurationOfP3K3R1), float(phaseDurationOfP4K3R1)] + left_r1_k1_Phase_Times.extend(left_r1_k3_Phase_Times) + del left_r1_k1_Phase_Times[8:] + phase_Times = left_r1_k1_Phase_Times + + elif(RingNo == 'Ring2'): + left_r2_k3_Phase_Times = [float(phaseDurationOfP5K3R1), float( + phaseDurationOfP6K3R1), float(phaseDurationOfP7K3R1), float(phaseDurationOfP8K3R1)] + left_r2_k1_Phase_Times.extend(left_r2_k3_Phase_Times) + del left_r2_k1_Phase_Times[8:] + phase_Times = left_r2_k1_Phase_Times + + # Storing RIght Critcial Points information + if(CP == 'Right'): + # Right Critical Points information for first cycle + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i == 5: + break + + phaseDurationOfP1K1R2, phaseDurationOfP2K1R2, phaseDurationOfP3K1R2, phaseDurationOfP4K1R2, phaseDurationOfP5K1R2, phaseDurationOfP6K1R2, phaseDurationOfP7K1R2, phaseDurationOfP8K1R2 = line.split() + + if(RingNo == 'Ring1'): + right_r1_k1_Phase_Times = [float(phaseDurationOfP1K1R2), float( + phaseDurationOfP2K1R2), float(phaseDurationOfP3K1R2), float(phaseDurationOfP4K1R2)] + if startingPhase > 1: + right_r1_k1_Phase_Times = right_r1_k1_Phase_Times[startingPhase-1:] + + elif(RingNo == 'Ring2'): + right_r2_k1_Phase_Times = [float(phaseDurationOfP5K1R2), float( + phaseDurationOfP6K1R2), float(phaseDurationOfP7K1R2), float(phaseDurationOfP8K1R2)] + if startingPhase > 4: + right_r2_k1_Phase_Times = right_r2_k1_Phase_Times[startingPhase-5:] + + # # Right Critical Points information for second cycle + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i == 6: + break + phaseDurationOfP1K2R2, phaseDurationOfP2K2R2, phaseDurationOfP3K2R2, phaseDurationOfP4K2R2, phaseDurationOfP5K2R2, phaseDurationOfP6K2R2, phaseDurationOfP7K2R2, phaseDurationOfP8K2R2 = line.split() + + if(RingNo == 'Ring1'): + right_r1_k2_Phase_Times = [float(phaseDurationOfP1K2R2), float( + phaseDurationOfP2K2R2), float(phaseDurationOfP3K2R2), float(phaseDurationOfP4K2R2)] + right_r1_k1_Phase_Times.extend(right_r1_k2_Phase_Times) + + elif(RingNo == 'Ring2'): + right_r2_k2_Phase_Times = [float(phaseDurationOfP5K2R2), float( + phaseDurationOfP6K2R2), float(phaseDurationOfP7K2R2), float(phaseDurationOfP8K2R2)] + right_r2_k1_Phase_Times.extend(right_r2_k2_Phase_Times) + + # Right Critical Points information for third cycle + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i == 7: + break + phaseDurationOfP1K3R2, phaseDurationOfP2K3R2, phaseDurationOfP3K3R2, phaseDurationOfP4K3R2, phaseDurationOfP5K3R2, phaseDurationOfP6K3R2, phaseDurationOfP7K3R2, phaseDurationOfP8K3R2 = line.split() + + if(RingNo == 'Ring1'): + right_r1_k3_Phase_Times = [float(phaseDurationOfP1K3R2), float( + phaseDurationOfP2K3R2), float(phaseDurationOfP3K3R2), float(phaseDurationOfP4K3R2)] + right_r1_k1_Phase_Times.extend(right_r1_k3_Phase_Times) + del right_r1_k1_Phase_Times[8:] + phase_Times = right_r1_k1_Phase_Times + + elif(RingNo == 'Ring2'): + right_r2_k3_Phase_Times = [float(phaseDurationOfP5K3R2), float( + phaseDurationOfP6K3R2), float(phaseDurationOfP7K3R2), float(phaseDurationOfP8K3R2)] + right_r2_k1_Phase_Times.extend(right_r2_k3_Phase_Times) + del right_r2_k1_Phase_Times[8:] + phase_Times = right_r2_k1_Phase_Times + + return phase_Times + + +def getCummulativePhaseTimes(startingPhase1, startingPhase2, left_ring_Phase_Times, right_ring_Phase_Times, phasesInRing, cum_phaseInRing, ringNo): + """ + Compute cumulative phase duration using cumsum method from numpy + Appending 0 in the beiginning of the list to define the starting point of the diagram + check the special condition of starting phase (for example phase 1&6, phase 2&5, phase 3&8, phase 4&7) + Append starting in the beginning of phasesInRing list if require. For example, if Starting phase is 4 and 7 then append phase 3 in the beginning of the list + """ + cum_left_Ring_Phase_Times = [] + cum_right_Ring_Phase_Times = [] + cum_left_Ring_Phase_Times = np.cumsum(left_ring_Phase_Times) + cum_right_Ring_Phase_Times = np.cumsum(right_ring_Phase_Times) + + # First 0 is index in the list + cum_left_Ring_Phase_Times = np.insert(cum_left_Ring_Phase_Times, 0, 0) + cum_right_Ring_Phase_Times = np.insert(cum_right_Ring_Phase_Times, 0, 0) + + if ringNo == 'Ring1': + if startingPhase2-startingPhase1 == 3: # For example, if starting phase 4,7 + cum_left_Ring_Phase_Times = np.insert( + cum_left_Ring_Phase_Times, 0, 0.0) + + cum_right_Ring_Phase_Times = np.insert( + cum_right_Ring_Phase_Times, 0, 0.0) + + # If Starting phase is 4 and 7 then append phase 3 in the beginning of the list + phasesInRing = np.insert(phasesInRing, 0, startingPhase1-1) + + elif startingPhase2-startingPhase1 == 5: # starting phase 3,8 + cum_left_Ring_Phase_Times = np.insert(cum_left_Ring_Phase_Times, len( + cum_left_Ring_Phase_Times), cum_left_Ring_Phase_Times[-1]+10) + + cum_right_Ring_Phase_Times = np.insert(cum_right_Ring_Phase_Times, len( + cum_right_Ring_Phase_Times), cum_right_Ring_Phase_Times[-1]+10) + + phasesInRing = np.insert( + phasesInRing, len(phasesInRing), startingPhase1) + + x = 0 + cum_phaseInRing = [x] + length = len(cum_left_Ring_Phase_Times)-1 + for i in range(length): + x = x+10 + cum_phaseInRing.append(x) + + if ringNo == 'Ring2': + if startingPhase2-startingPhase1 == 3: + cum_left_Ring_Phase_Times = np.insert(cum_left_Ring_Phase_Times, len( + cum_left_Ring_Phase_Times), cum_left_Ring_Phase_Times[-1]+10) + + cum_right_Ring_Phase_Times = np.insert(cum_right_Ring_Phase_Times, len( + cum_right_Ring_Phase_Times), cum_right_Ring_Phase_Times[-1]+10) + + phasesInRing = np.insert( + phasesInRing, len(phasesInRing), startingPhase2) + + elif startingPhase2-startingPhase1 == 5: + cum_left_Ring_Phase_Times = np.insert( + cum_left_Ring_Phase_Times, 0, 0.0) + + cum_right_Ring_Phase_Times = np.insert( + cum_right_Ring_Phase_Times, 0, 0.0) + + phasesInRing = np.insert(phasesInRing, 0, startingPhase2 - 1) + + x = 0 + cum_phaseInRing = [x] + length = len(cum_left_Ring_Phase_Times)-1 + for i in range(length): + x = x+10 + cum_phaseInRing.append(x) + + return cum_left_Ring_Phase_Times, cum_right_Ring_Phase_Times, phasesInRing, cum_phaseInRing + + +def getPriorityRequest(): + eta = [] + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i == 14: + break + + noOfReq = line + noOfReq = int(noOfReq) + print("No of Request", noOfReq) + reqInfoLineNo = 15+noOfReq + with open('/nojournal/bin/Results.txt') as f: + for i, line in enumerate(f): + if i < 15: + continue + # elif i>=15 & i 4: + # Get the requested phases index in phasesInRing2 list + for j in range(len(phasesInRing2)): + if phasesInRing2[j] == requestedPhase: + indexPosList.append(j) + # Get the cumulative phase phaseDuration value of requested phases based on the index + for i in indexPosList: + pos = cum_phaseInRing2[i] + requestedPhasePosition.append(pos) + + # Draw the rectangles to denote priority request + patches = [] + req_phase_length = len(requestedPhasePosition) + for i in range(0, req_phase_length): + x = ETA[i] + y = requestedPhasePosition[i] + z = ETA_Duration[i] + if i == 0: + ax1.add_patch(matplotlib.patches.Rectangle( + (x, y), z, 10, angle=0.0, color='green', linewidth=2, label='Truck Priority Request')) + else: + ax1.add_patch(matplotlib.patches.Rectangle( + (x, y), z, 10, angle=0.0, color='green', linewidth=2)) + + # Requested phase of Second Type Priority Request + requestedPhasePosition = [] + indexPosList = [] + indexPos = 0 + for requestedPhase in secondPriorityRequestphases: + if requestedPhase < 5: + # Get the requested phases index in phasesInRing1 list + for j in range(len(phasesInRing1)): + if phasesInRing1[j] == requestedPhase: + indexPosList.append(j) + # Get the cumulative phase phaseDuration value of requested phases based on the index + for i in indexPosList: + pos = cum_phaseInRing1[i] + requestedPhasePosition.append(pos) + elif requestedPhase > 4: + # Get the requested phases index in phasesInRing2 list + for j in range(len(phasesInRing2)): + if phasesInRing2[j] == requestedPhase: + indexPosList.append(j) + # Get the cumulative phase phaseDuration value of requested phases based on the index + for i in indexPosList: + pos = cum_phaseInRing2[i] + requestedPhasePosition.append(pos) + + patches = [] + req_phase_length = len(requestedPhasePosition) + for i in range(0, req_phase_length): + x = secondPriorityRequestETA[i] + y = requestedPhasePosition[i] + z = secondPriorityRequestETA_Duration[i] + if i == 0: + ax1.add_patch(matplotlib.patches.Rectangle((x, y), z, 10, angle=0.0, + color='#0099FF', linewidth=2, label='Transit Priority Request')) + else: + ax1.add_patch(matplotlib.patches.Rectangle( + (x, y), z, 10, angle=0.0, color='#0099FF', linewidth=2)) + + ax1.legend(loc='upper right', bbox_to_anchor=(1, 1), prop={"size": 18}) + fig.tight_layout() # otherwise the right y-label is slightly clipped + plt.grid(color='black', linestyle='-', linewidth=2) + + plt.show() + + +def main(): + configFile = open("configuration.json", 'r') + config = (json.load(configFile)) + # Close the config file: + configFile.close() + # Defining the phases in ring 1 and ring 2 + r1_phases = [1, 2, 3, 4] + r2_phases = [5, 6, 7, 8] + # Declaration of lists to store the left and right critical points for ring 1 + left_R1_CP_phase_times = [] + right_R1_CP_phase_times = [] + # Declaration of lists to store the cumulative left and right critical points for ring 1 + cum_Left_Ring1_Phase_Times = [] + cum_Right_Ring1_Phase_Times = [] + cum_phaseInRing1 = [] + # Declaration of lists to store the left and right critical points for ring 2 + left_R2_CP_phase_times = [] + right_R2_CP_phase_times = [] + # Declaration of lists to store the cumulative left and right critical points for ring 2 + cum_Left_Ring2_Phase_Times = [] + cum_Right_Ring2_Phase_Times = [] + cum_phaseInRing2 = [] + # Declaration of lists to store the ETA, ETA_Duration and requested phases + ETA = [] + ETA_Duration = [] + req_phase = [] + + count = 0 + noOfIteration = config["NoOfRequest"] + + while (count < noOfIteration): + ETA_Val = config["ETA"][count] + ETA_Duration_Val = config["ETA_Duration"][count] + # Append the same ETA and ETA_Duration value twice for plotting two rectangles for two cycle + ETA.append(ETA_Val) + ETA.append(ETA_Val) + ETA_Duration.append(ETA_Duration_Val) + ETA_Duration.append(ETA_Duration_Val) + count = count + 1 + #print("ETA", ETA) + + count = 0 + noOfIteration = config["NoOfRequiredPhase"] + while (count < noOfIteration): + phaseVal = config["RequestedPhase"][count] + req_phase.append(phaseVal) + count = count + 1 + #print("Requested Phase", req_phase) + + # For Differentiating two types of request + secondPriorityRequestphases = [] + secondPriorityRequestETA = [] + secondPriorityRequestETA_Duration = [] + # Dilemma-Zone Information + multipleTypesOfRequest = config["MultipleTypesofRequest"] + if bool(multipleTypesOfRequest): + count = 0 + noOfIteration = config["NoOfDilemmaZoneRequest"] + + while (count < noOfIteration): + ETA_Val = config["DilemmaZoneETA"][count] + ETA_Duration_Val = config["DilemmaZoneETA_Duration"][count] + # Append the same ETA value twice for draw two rectangles for two cycle + secondPriorityRequestETA.append(ETA_Val) + secondPriorityRequestETA.append(ETA_Val) + secondPriorityRequestETA_Duration.append(ETA_Duration_Val) + secondPriorityRequestETA_Duration.append(ETA_Duration_Val) + count = count + 1 + #print("Second Requests ETA", secondPriorityRequestETA) + + count = 0 + noOfIteration = config["NoOfRequiredDilemmaZonePhase"] + while (count < noOfIteration): + phaseVal = config["DilemmaZonePhases"][count] + secondPriorityRequestphases.append(phaseVal) + count = count + 1 + #print("Second Requests' Requested Phase", secondPriorityRequestphases) + + # Get the stating phase information + startingPhase1, startingPhase2 = getStartingPhases() + + # Appending the startingPhase1 into phasesInring1 list + phasesInRing1 = [startingPhase1] + # Appending the startingPhase2 into phasesInring2 list + phasesInRing2 = [startingPhase2] + + # Obtained planned signal phase of cycle1,2,3 for ring 1. There will be 8 phases. + phasesInRing1 = phaseGroupInRing(startingPhase1, r1_phases, phasesInRing1) + print("Phases In Ring1", phasesInRing1) + + # Obtained planned signal phase of cycle1,2,3 for ring 2. There will be 8 phases + phasesInRing2 = phaseGroupInRing(startingPhase2, r2_phases, phasesInRing2) + print("Phases In Ring2", phasesInRing2) + # obtained init time and green elapssed time + init1, init2, grn1, grn2 = getInitToPhasesAndElaspedGreenTime().split() + + ################## For Ring1################## + + # Obatined ring wise phase phaseDuration for left and right critical points + left_R1_CP_phase_times = getPhaseDuration( + left_R1_CP_phase_times, startingPhase1, 'Left', 'Ring1') + right_R1_CP_phase_times = getPhaseDuration( + right_R1_CP_phase_times, startingPhase1, 'Right', 'Ring1') + print("Left Critical Points Phase Duration for Ring1 =", left_R1_CP_phase_times) + print("Right Critical Points Phase Duration for Ring1 =", + right_R1_CP_phase_times) + + # creating cumulative list + # getCummulativePhaseTimes(startingPhase1, startingPhase2, ring_Phase_Times, phasesInRing, cum_phaseInRing, ringNo) + cum_Left_Ring1_Phase_Times, cum_Right_Ring1_Phase_Times, phasesInRing1, cum_phaseInRing1 = getCummulativePhaseTimes( + startingPhase1, startingPhase2, left_R1_CP_phase_times, right_R1_CP_phase_times, phasesInRing1, cum_phaseInRing1, "Ring1") + + print("Phases In Ring1", phasesInRing1) + print("Cumulative Left Critical Points Phase times for Ring1 =", + cum_Left_Ring1_Phase_Times) + print("Cumulative Right Critical Points Phase times for Ring1 =", + cum_Right_Ring1_Phase_Times) + print("Cumulative Phases in Ring1 =", cum_phaseInRing1) + + ################## For Ring2 ################## + + left_R2_CP_phase_times = getPhaseDuration( + left_R2_CP_phase_times, startingPhase2, 'Left', 'Ring2') + right_R2_CP_phase_times = getPhaseDuration( + right_R2_CP_phase_times, startingPhase2, 'Right', 'Ring2') + print("Left Critical Points Phase times for Ring2 =", left_R2_CP_phase_times) + print("Right Critical Points Phase times for Ring2 =", right_R2_CP_phase_times) + + cum_Left_Ring2_Phase_Times, cum_Right_Ring2_Phase_Times, phasesInRing2, cum_phaseInRing2 = getCummulativePhaseTimes( + startingPhase1, startingPhase2, left_R2_CP_phase_times, right_R2_CP_phase_times, phasesInRing2, cum_phaseInRing2, "Ring2") + + print("Phases In Ring2", phasesInRing2) + print("Cumulative Left Critical Points Phase times for Ring2 =", + cum_Left_Ring2_Phase_Times) + print("Cumulative Right Critical Points Phase times for Ring2 =", + cum_Right_Ring2_Phase_Times) + print("Cumulative Phases in Ring2 =", cum_phaseInRing2) + + timePhaseDiagramMethod(startingPhase1, startingPhase2, cum_Left_Ring1_Phase_Times, cum_Right_Ring1_Phase_Times, + cum_phaseInRing1, cum_Left_Ring2_Phase_Times, cum_Right_Ring2_Phase_Times, + cum_phaseInRing2, phasesInRing1, phasesInRing2, ETA, ETA_Duration, req_phase, secondPriorityRequestphases, secondPriorityRequestETA, secondPriorityRequestETA_Duration, 'Ring1&2') + + +if __name__ == '__main__': + main() diff --git a/src/tools/time-phase-diagram/configuration.json b/src/tools/time-phase-diagram/configuration.json index 74b6419c..07a49dc4 100644 --- a/src/tools/time-phase-diagram/configuration.json +++ b/src/tools/time-phase-diagram/configuration.json @@ -1,15 +1,15 @@ { "MultipleTypesofRequest":true, - "NoOfRequest": 2, - "ETA":[0, 72], - "ETA_Duration": [4, 20], - "NoOfRequiredPhase": 2, - "RequestedPhase":[2, 2], + "NoOfRequest": 1, + "ETA":[35], + "ETA_Duration": [4], + "NoOfRequiredPhase": 1, + "RequestedPhase":[4], "NoOfDilemmaZoneRequest": 1, - "DilemmaZoneETA":[60], + "DilemmaZoneETA":[25], "DilemmaZoneETA_Duration": [4], "NoOfRequiredDilemmaZonePhase": 1, - "DilemmaZonePhases":[8], + "DilemmaZonePhases":[2], "NoOfPhasesInRing1": 8, "PhasesInRing1":[1,2,3,4,1,2,3,4], "NoOfPhasesInRing2": 8, diff --git a/src/tools/time-phase-diagram/timePhaseDiagramWithFunction.py b/src/tools/time-phase-diagram/timePhaseDiagramWithFunction.py deleted file mode 100644 index dc554905..00000000 --- a/src/tools/time-phase-diagram/timePhaseDiagramWithFunction.py +++ /dev/null @@ -1,776 +0,0 @@ -import numpy as np -import matplotlib -import matplotlib.pyplot as plt -from matplotlib.collections import PatchCollection -import json - -#Get the stating phase information -def getStartingPhases(): - with open('/nojournal/bin/Results.txt') as f: - first_line = f.readline() - return first_line - -#Appending the SP1 into phasesInring list -#Appending the phases which are greater than the starting phase for that ring -#Appending the phases which are less than the starting phase for that ring -#Repeat all the phase number -#Appending the phases which are greater than the starting phase for that ring -def phaseGroupInRing(SP, ring_phases, phasesInRing): - i = SP - for i in ring_phases: - if i > SP: - phasesInRing.append(i) - - for i in ring_phases: - if i < SP: - phasesInRing.append(i) - # Extending the phases for 2nd&3rdcycles - phasesInRing.extend(phasesInRing*1) - # for i in ring_phases: - # if i > SP: - # phasesInRing.append(i) - # # Need to delete the phases based on starting phase - # phasesInRing.pop(len(phasesInRing)-(SP-1)) - # print(phaseInRing) - return phasesInRing - - -def getInitToPhasesAndElaspedGreenTime(): - with open('/nojournal/bin/Results.txt') as f: - - for i, line in enumerate(f): - if i == 1: - break - return line - -#Find the phase duration for all the planned phases. -def getPhaseTimesForCycle1(phase_Times, SP, CP, RingNo): - if(CP == 'Left'): - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i == 2: - break - durationOfP1K1R1, durationOfP2K1R1, durationOfP3K1R1, durationOfP4K1R1, durationOfP5K1R1, durationOfP6K1R1, durationOfP7K1R1, durationOfP8K1R1 = line.split() - # print(line) - if(RingNo == 'Ring1'): - left_r1_k1_Phase_Times = [float(durationOfP1K1R1), float(durationOfP2K1R1), float(durationOfP3K1R1), float(durationOfP4K1R1)] - if SP > 1: - left_r1_k1_Phase_Times = left_r1_k1_Phase_Times[SP-1:] - - elif(RingNo == 'Ring2'): - left_r2_k1_Phase_Times = [float(durationOfP5K1R1), float(durationOfP6K1R1), float(durationOfP7K1R1), float(durationOfP8K1R1)] - if SP > 4: - left_r2_k1_Phase_Times = left_r2_k1_Phase_Times[SP-5:] - - # For cycle2 Left CP - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i == 3: - break - durationOfP1K2R1, durationOfP2K2R1, durationOfP3K2R1, durationOfP4K2R1, durationOfP5K2R1, durationOfP6K2R1, durationOfP7K2R1, durationOfP8K2R1 = line.split() - - if(RingNo == 'Ring1'): - left_r1_k2_Phase_Times = [float(durationOfP1K2R1), float(durationOfP2K2R1), float(durationOfP3K2R1), float(durationOfP4K2R1)] - left_r1_k1_Phase_Times.extend(left_r1_k2_Phase_Times) - - elif(RingNo == 'Ring2'): - left_r2_k2_Phase_Times = [float(durationOfP5K2R1), float(durationOfP6K2R1), float(durationOfP7K2R1), float(durationOfP8K2R1)] - left_r2_k1_Phase_Times.extend(left_r2_k2_Phase_Times) - - # For cycle3 Left CP - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i == 4: - break - durationOfP1K3R1, durationOfP2K3R1, durationOfP3K3R1, durationOfP4K3R1, durationOfP5K3R1, durationOfP6K3R1, durationOfP7K3R1, durationOfP8K3R1 = line.split() - - if(RingNo == 'Ring1'): - left_r1_k3_Phase_Times = [float(durationOfP1K3R1), float(durationOfP2K3R1), float(durationOfP3K3R1), float(durationOfP4K3R1)] - left_r1_k1_Phase_Times.extend(left_r1_k3_Phase_Times) - del left_r1_k1_Phase_Times[8:] - phase_Times = left_r1_k1_Phase_Times - - elif(RingNo == 'Ring2'): - left_r2_k3_Phase_Times = [float(durationOfP5K3R1), float(durationOfP6K3R1), float(durationOfP7K3R1), float(durationOfP8K3R1)] - left_r2_k1_Phase_Times.extend(left_r2_k3_Phase_Times) - del left_r2_k1_Phase_Times[8:] - phase_Times = left_r2_k1_Phase_Times - - - # # # For cycle1 Right CP - if(CP == 'Right'): - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i == 5: - break - durationOfP1K1R2, durationOfP2K1R2, durationOfP3K1R2, durationOfP4K1R2, durationOfP5K1R2, durationOfP6K1R2, durationOfP7K1R2, durationOfP8K1R2 = line.split() - # print(line) - - if(RingNo == 'Ring1'): - right_r1_k1_Phase_Times = [float(durationOfP1K1R2), float(durationOfP2K1R2), float(durationOfP3K1R2), float(durationOfP4K1R2)] - if SP > 1: - right_r1_k1_Phase_Times = right_r1_k1_Phase_Times[SP-1:] - - elif(RingNo == 'Ring2'): - right_r2_k1_Phase_Times = [float(durationOfP5K1R2), float(durationOfP6K1R2), float(durationOfP7K1R2), float(durationOfP8K1R2)] - if SP > 4: - right_r2_k1_Phase_Times = right_r2_k1_Phase_Times[SP-5:] - - - # For cycle2 Right CP - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i == 6: - break - durationOfP1K2R2, durationOfP2K2R2, durationOfP3K2R2, durationOfP4K2R2, durationOfP5K2R2, durationOfP6K2R2, durationOfP7K2R2, durationOfP8K2R2 = line.split() - - if(RingNo == 'Ring1'): - right_r1_k2_Phase_Times = [float(durationOfP1K2R2), float(durationOfP2K2R2), float(durationOfP3K2R2), float(durationOfP4K2R2)] - right_r1_k1_Phase_Times.extend(right_r1_k2_Phase_Times) - - elif(RingNo == 'Ring2'): - right_r2_k2_Phase_Times = [float(durationOfP5K2R2), float(durationOfP6K2R2), float(durationOfP7K2R2), float(durationOfP8K2R2)] - right_r2_k1_Phase_Times.extend(right_r2_k2_Phase_Times) - - # For cycle3 Right CP - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i == 7: - break - durationOfP1K3R2, durationOfP2K3R2, durationOfP3K3R2, durationOfP4K3R2, durationOfP5K3R2, durationOfP6K3R2, durationOfP7K3R2, durationOfP8K3R2 = line.split() - - if(RingNo == 'Ring1'): - right_r1_k3_Phase_Times = [float(durationOfP1K3R2), float(durationOfP2K3R2), float(durationOfP3K3R2), float(durationOfP4K3R2)] - right_r1_k1_Phase_Times.extend(right_r1_k3_Phase_Times) - del right_r1_k1_Phase_Times[8:] - phase_Times = right_r1_k1_Phase_Times - - elif(RingNo == 'Ring2'): - right_r2_k3_Phase_Times = [float(durationOfP5K3R2), float(durationOfP6K3R2), float(durationOfP7K3R2), float(durationOfP8K3R2)] - right_r2_k1_Phase_Times.extend(right_r2_k3_Phase_Times) - del right_r2_k1_Phase_Times[8:] - phase_Times = right_r2_k1_Phase_Times - - return phase_Times - - -def getCummulativePhaseTimes(ring_Phase_Times): - cum_Ring_Phase_Times = [] - cum_Ring_Phase_Times = np.cumsum(ring_Phase_Times) - - # Appending 0 in the beiginning of the list. - cum_Ring_Phase_Times = np.insert( - cum_Ring_Phase_Times, 0, 0) # First 0 is position - return cum_Ring_Phase_Times - - -def getPriorityRequest(): - eta = [] - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i == 14: - break - - - noOfReq = line - noOfReq = int(noOfReq) - print("No of Request", noOfReq) - reqInfoLineNo = 15+noOfReq - with open('/nojournal/bin/Results.txt') as f: - for i, line in enumerate(f): - if i<15: - continue - # elif i>=15 & i4: - for j in range(len(phasesInRing2)): - if phasesInRing2[j] == i: - indexPosList.append(j) - - - if i<5: - for i in indexPosList: - pos = cum_phaseInRing1[i] - requestedPhasePosition.append(pos) - elif i>4: - for i in indexPosList: - pos = cum_phaseInRing2[i] - requestedPhasePosition.append(pos) - - - - patches =[] - req_phase_length = len(requestedPhasePosition) - for i in range(0,req_phase_length): - x = ETA[i] - y = requestedPhasePosition[i] - - if i==0: - ax1.add_patch(matplotlib.patches.Rectangle((x, y),25,10,angle=0.0,color = 'green', linewidth = 2, label = 'Coordination Priority Request')) - - else: - ax1.add_patch(matplotlib.patches.Rectangle((x, y),25,10,angle=0.0,color = 'green', linewidth = 2)) - # patches.append(matplotlib.patches.Rectangle((x, y),25,10,angle=0.0,color = 'red')) - # ax1.add_collection(PatchCollection(patches)) - ax1.legend(loc='upper right', bbox_to_anchor=(.9, 1), prop={"size":18}) - fig.tight_layout() # otherwise the right y-label is slightly clipped - plt.grid() - plt.show() - - - -# Plotting time-phase diagram Method 2 -def timePhaseDiagramMethod2(SP1, SP2, cum_Left_Ring1_Phase_Times, cum_Right_Ring1_Phase_Times, cum_phaseInRing1, cum_Left_Ring2_Phase_Times, cum_Right_Ring2_Phase_Times, cum_phaseInRing2, phasesInRing1, phasesInRing2, ETA, ETA_Duration, req_phase, dilemmaZone_phases, dilemmaZone_ETA, dilemmaZone_ETA_Duration, ringNo): - fig, ax1 = plt.subplots() - if ringNo == 'Ring1&2': - #Ring1 - color = 'tab:red' - ax1.set_xlabel('Time (s)',fontsize=24, fontweight = 'bold') - ax1.set_ylabel('Ring 1', color=color, fontsize=28,fontweight = 'bold') - ax1.plot(cum_Left_Ring1_Phase_Times, cum_phaseInRing1, color=color,linewidth = 4) - ax1.plot(cum_Right_Ring1_Phase_Times, cum_phaseInRing1, color=color,linewidth = 4) - plt.xticks(np.arange(cum_Right_Ring1_Phase_Times[0], cum_Right_Ring1_Phase_Times[-1], 20),fontsize = 24) - ax1.set_yticks(ticks=np.arange(cum_phaseInRing1[0], cum_phaseInRing1[-1], 10)) - ax1.set_yticklabels(phasesInRing1) - ax1.tick_params(axis='y', labelcolor=color, labelsize=18) - for axis in ['top','bottom','left','right']: - ax1.spines[axis].set_linewidth(4) - - - #Ring2 - ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis - color = 'tab:blue' - ax2.set_ylabel('Ring 2', color=color, fontsize=28, fontweight = 'bold') - ax2.plot(cum_Left_Ring2_Phase_Times, cum_phaseInRing2, color=color,linewidth = 4) - ax2.plot(cum_Right_Ring2_Phase_Times, cum_phaseInRing2, color=color, linewidth = 4) - ax2.set_yticks(ticks=np.arange(cum_phaseInRing2[0], cum_phaseInRing2[-1], 10)) - ax2.set_yticklabels(phasesInRing2) - ax2.tick_params(axis='y', labelcolor=color,labelsize=24) - - elif ringNo == 'Ring1': - color = 'tab:red' - ax1.set_xlabel('time (s)', fontsize=20) - ax1.set_ylabel('Ring 1', color=color, fontsize=20) - ax1.plot(cum_Left_Ring1_Phase_Times, cum_phaseInRing1, color=color) - ax1.plot(cum_Right_Ring1_Phase_Times, cum_phaseInRing1, color=color) - plt.xticks(np.arange(cum_Right_Ring1_Phase_Times[0], cum_Right_Ring1_Phase_Times[-1], 10),fontsize = 18) - ax1.set_yticks(ticks=np.arange(cum_phaseInRing1[0], cum_phaseInRing1[-1], 10)) - ax1.set_yticklabels(phasesInRing1) - ax1.tick_params(axis='y', labelcolor=color, labelsize=18) - - - elif ringNo == 'Ring2': - color = 'tab:blue' - ax1.set_xlabel('time (s)', fontsize=20) - ax1.set_ylabel('Ring 2', color=color, fontsize=20) - ax1.plot(cum_Left_Ring2_Phase_Times, cum_phaseInRing2, color=color) - ax1.plot(cum_Right_Ring2_Phase_Times, cum_phaseInRing2, color=color) - plt.xticks(np.arange(cum_Right_Ring2_Phase_Times[0], cum_Right_Ring2_Phase_Times[-1], 10),fontsize = 18) - ax1.set_yticks(ticks=np.arange(cum_phaseInRing2[0], cum_phaseInRing2[-1], 10)) - ax1.set_yticklabels(phasesInRing2) - ax1.tick_params(axis='y', labelcolor=color,labelsize=18) - - # Requested phase of First Type Priority Request - requestedPhasePosition =[] - indexPosList =[] - indexPos = 0 - #Get the requested phases index - for i in req_phase: - if i<5: - for j in range(len(phasesInRing1)): - if phasesInRing1[j] == i: - indexPosList.append(j) - elif i>4: - for j in range(len(phasesInRing2)): - if phasesInRing2[j] == i: - indexPosList.append(j) - # Get the cumulative phase duration value of requested phases based on the index - if i<5: - for i in indexPosList: - pos = cum_phaseInRing1[i] - requestedPhasePosition.append(pos) - elif i>4: - for i in indexPosList: - pos = cum_phaseInRing2[i] - requestedPhasePosition.append(pos) - - #Draw the rectangles to denote priority request - patches =[] - req_phase_length = len(requestedPhasePosition) - for i in range(0,req_phase_length): - x = ETA[i] - y = requestedPhasePosition[i] - z = ETA_Duration[i] - if i == 0: - ax1.add_patch(matplotlib.patches.Rectangle((x, y),z,10,angle=0.0,color = 'green',linewidth = 2, label = 'Coordination Priority Request')) - else: - ax1.add_patch(matplotlib.patches.Rectangle((x, y),z,10,angle=0.0,color = 'green',linewidth = 2)) - # patches.append(matplotlib.patches.Rectangle((x, y),25,10,angle=0.0,color = 'red')) - # ax1.add_collection(PatchCollection(patches)) - - # Requested phase of Second Type Priority Request - requestedPhasePosition =[] - indexPosList =[] - indexPos = 0 - for i in dilemmaZone_phases: - if i<5: - for j in range(len(phasesInRing1)): - if phasesInRing1[j] == i: - indexPosList.append(j) - elif i>4: - for j in range(len(phasesInRing2)): - if phasesInRing2[j] == i: - indexPosList.append(j) - - - if i<5: - for i in indexPosList: - pos = cum_phaseInRing1[i] - requestedPhasePosition.append(pos) - elif i>4: - for i in indexPosList: - pos = cum_phaseInRing2[i] - requestedPhasePosition.append(pos) - - - - patches =[] - req_phase_length = len(requestedPhasePosition) - for i in range(0,req_phase_length): - x = dilemmaZone_ETA[i] - y = requestedPhasePosition[i] - z = dilemmaZone_ETA_Duration[i] - if i == 0: - ax1.add_patch(matplotlib.patches.Rectangle((x, y),z,10,angle=0.0,color = '#0099FF',linewidth = 2, label = 'Truck Priority Request')) - else: - ax1.add_patch(matplotlib.patches.Rectangle((x, y),z,10,angle=0.0,color = '#0099FF', linewidth = 2)) - - ax1.legend(loc='upper right', bbox_to_anchor=(1, 1), prop={"size":18}) - fig.tight_layout() # otherwise the right y-label is slightly clipped - plt.grid(color='black', linestyle='-', linewidth=2) - # plt.legend(loc='best', bbox_to_anchor=(1.1, 1.1)) - # plt.legend() - plt.show() - - -def subplotTimePhaseDiagram(cum_Left_Ring1_Phase_Times, cum_Right_Ring1_Phase_Times, cum_phaseInRing1, cum_Left_Ring2_Phase_Times, cum_Right_Ring2_Phase_Times, cum_phaseInRing2, ETA, phasesInRing1, phasesInRing2,req_phase): - - # Plotting time-phase diagram - fig, ax1 = plt.subplots(2) - - color = 'tab:red' - ax1[0].set_xlabel('time (s)') - ax1[0].set_ylabel('Ring 1', color=color) - ax1[0].plot(cum_Left_Ring1_Phase_Times, cum_phaseInRing1, color=color) - ax1[0].plot(cum_Right_Ring1_Phase_Times, cum_phaseInRing1, color=color) - plt.xticks(np.arange(cum_Right_Ring1_Phase_Times[0], cum_Right_Ring1_Phase_Times[-1], 10)) - - - ax1[0].set_yticks(ticks=np.arange( - cum_phaseInRing1[0], cum_phaseInRing1[-1], 10)) # added by Kelsey - ax1[0].set_yticklabels(phasesInRing1) # added by Kelsey - ax1[0].tick_params(axis='y', labelcolor=color) - fig.tight_layout() - ax1[0].grid(linestyle='-', linewidth='0.5', color='red') - - # ax2 = ax1[0].twinx() # instantiate a second axes that shares the same x-axis - - # color = 'tab:blue' - # # we already handled the x-label with ax1 - # ax2.set_ylabel('Ring 2', color=color) - # ax2.set_yticks(ticks=np.arange( - # cum_phaseInRing1[0], cum_phaseInRing1[-1], 10)) # added by Kelsey - # ax2.set_yticklabels(phasesInRing2) # added by Kelsey - # ax2.tick_params(axis='y', labelcolor=color) - - - - -###For second plot (Ring2) - color = 'tab:blue' - ax1[1].set_xlabel('time (s)') - ax1[1].set_ylabel('Ring 2', color=color) - ax1[1].plot(cum_Left_Ring2_Phase_Times, cum_phaseInRing2, color=color) - ax1[1].plot(cum_Right_Ring2_Phase_Times, cum_phaseInRing2, color=color) - plt.xticks(np.arange(cum_Right_Ring2_Phase_Times[0], cum_Right_Ring2_Phase_Times[-1], 10)) - - - ax1[1].set_yticks(ticks=np.arange( - cum_phaseInRing2[0], cum_phaseInRing2[-1], 10)) - ax1[1].set_yticklabels(phasesInRing1) - ax1[1].tick_params(axis='y', labelcolor=color) - - # ax2 = ax1[1].twinx() # instantiate a second axes that shares the same x-axis - - # color = 'tab:blue' - # # we already handled the x-label with ax1 - # ax2.set_ylabel('Ring 2', color=color) - # ax2.plot(cum_Left_Ring2_Phase_Times, cum_phaseInRing2, color=color) - # ax2.plot(cum_Right_Ring2_Phase_Times, cum_phaseInRing2, color=color) - # ax2.set_yticks(ticks=np.arange( - # cum_phaseInRing2[0], cum_phaseInRing2[-1], 10)) - # ax2.set_yticklabels(phasesInRing2) - # ax2.tick_params(axis='y', labelcolor=color) - - fig.tight_layout() # otherwise the right y-label is slightly clipped - ax1[1].grid(linestyle='-', linewidth='0.5', color='blue') - - - # Requested phase - # req_phase = [2,7] - requestedPhasePosition =[] - for i in req_phase: - if i<5: - pos = phasesInRing1.index(i)#phasesInRing1.index(req_phase) - pos = cum_phaseInRing1[pos] - requestedPhasePosition.append(pos) - else: - i=i-4 - pos = phasesInRing1.index(i) - pos = cum_phaseInRing1[pos] - requestedPhasePosition.append(pos) - - patches =[] - req_phase_length = len(req_phase) - for i in range(0,req_phase_length): - x = ETA[i] - y = requestedPhasePosition[i] - patches.append(matplotlib.patches.Rectangle((x, y),5,10,angle=0.0,color='r')) - ax1[0].add_collection(PatchCollection(patches)) - ax1[1].add_collection(PatchCollection(patches)) - - - # fig.tight_layout() # otherwise the right y-label is slightly clipped - # plt.grid() - plt.show() - - - -def main(): - configFile = open("configuration.json", 'r') - config = (json.load(configFile)) - # Close the config file: - configFile.close() - - r1_phases = [1, 2, 3, 4] - r2_phases = [5, 6, 7, 8] - left_R1_CP_phase_times = [] - right_R1_CP_phase_times = [] - cum_Left_Ring1_Phase_Times = [] - cum_Right_Ring1_Phase_Times = [] - cum_phaseInRing1 = [] - - left_R2_CP_phase_times = [] - right_R2_CP_phase_times = [] - cum_Left_Ring2_Phase_Times = [] - cum_Right_Ring2_Phase_Times = [] - cum_phaseInRing2 = [] - - ETA = [] - req_phase = [] - ETA_Duration = [] - - count = 0 - noOfIteration = config["NoOfRequest"] - - while (count < noOfIteration): - ETA_Val = config["ETA"][count] - ETA_Duration_Val = config ["ETA_Duration"][count] - #Append the same ETA value twice for draw two rectangles for two cycle - ETA.append(ETA_Val) - ETA.append(ETA_Val) - ETA_Duration.append(ETA_Duration_Val) - ETA_Duration.append(ETA_Duration_Val) - count = count + 1 - print("ETA", ETA) - - count = 0 - noOfIteration = config["NoOfRequiredPhase"] - while (count < noOfIteration): - phaseVal = config["RequestedPhase"][count] - req_phase.append(phaseVal) - count = count + 1 - print("Requested Phase", req_phase) - - # ETA = getPriorityRequest() - # ETA = [25.0, 25.0, 20.0, 20.0] - # print("ETA", ETA) - #For Differentiating two types of request - dilemmaZone_phases = [] - dilemmaZone_ETA = [] - dilemmaZone_ETA_Duration = [] - #Dilemma-Zone Information - multipleTypesofRequest = config["MultipleTypesofRequest"] - if bool(multipleTypesofRequest): - count = 0 - noOfIteration = config["NoOfDilemmaZoneRequest"] - - while (count < noOfIteration): - ETA_Val = config["DilemmaZoneETA"][count] - ETA_Duration_Val = config["DilemmaZoneETA_Duration"][count] - #Append the same ETA value twice for draw two rectangles for two cycle - dilemmaZone_ETA.append(ETA_Val) - dilemmaZone_ETA.append(ETA_Val) - dilemmaZone_ETA_Duration.append(ETA_Duration_Val) - dilemmaZone_ETA_Duration.append(ETA_Duration_Val) - count = count + 1 - print("DilemmaZone ETA", dilemmaZone_ETA) - - count = 0 - noOfIteration = config["NoOfRequiredDilemmaZonePhase"] - while (count < noOfIteration): - phaseVal = config["DilemmaZonePhases"][count] - dilemmaZone_phases.append(phaseVal) - count = count + 1 - print("DilemmaZone Requested Phase", dilemmaZone_phases) - - - SP1, SP2 = getStartingPhases().split() #Get the stating phase information - print("SP1 =", SP1) - print("SP2 =", SP2) - SP1 = int(SP1) #Converting starting phase into integar value - SP2 = int(SP2) #Converting starting phase into integar value - # if SP2-SP1 == 3: - # phasesInRing1 = [SP1-1,SP1] - # else: - # phasesInRing1 = [SP1] #Appending the SP1 into phasesInring1 list - - # if SP2-SP1 == 5: - # phasesInRing2 = [SP2-1,SP1] - # else: - # phasesInRing2 = [SP2] #Appending the SP2 into phasesInring2 list - - phasesInRing1 = [SP1] #Appending the SP1 into phasesInring1 list - phasesInRing2 = [SP2] #Appending the SP2 into phasesInring2 list - - #Obtained planned signal phase of cycle1,2,3 for ring 1. There will be 8 phases. - phasesInRing1 = phaseGroupInRing(SP1, r1_phases, phasesInRing1) - print("Phases In Ring1", phasesInRing1) - #Obtained planned signal phase of cycle1,2,3 for ring 2. There will be 8 phases - phasesInRing2 = phaseGroupInRing(SP2, r2_phases, phasesInRing2) - print("Phases In Ring2", phasesInRing2) - #obtained init time and green elapssed time - init1, init2, grn1, grn2 = getInitToPhasesAndElaspedGreenTime().split() - print("ini1 =", init1) - print("ini2 =", init2) - print("Elapesd Green1 =", grn1) - print("Elapesd Green2 =", grn2) - - ################## For Ring1################## - - #Obatined ring wise phase duration for left and right critical points - left_R1_CP_phase_times = getPhaseTimesForCycle1( - left_R1_CP_phase_times, SP1, 'Left','Ring1') - right_R1_CP_phase_times = getPhaseTimesForCycle1( - right_R1_CP_phase_times, SP1, 'Right', 'Ring1') - print("Left Critical Points Phase times for Ring1 =", left_R1_CP_phase_times) - print("Right Critical Points Phase times for Ring1 =", right_R1_CP_phase_times) - # #creating cumulative list - - if SP2-SP1 == 3: ##starting phase 4,7 - cum_Left_Ring1_Phase_Times = getCummulativePhaseTimes( - left_R1_CP_phase_times) - - cum_Right_Ring1_Phase_Times = getCummulativePhaseTimes( - right_R1_CP_phase_times) - - cum_Left_Ring1_Phase_Times = np.insert(cum_Left_Ring1_Phase_Times,0,0.0) - cum_Right_Ring1_Phase_Times = np.insert(cum_Right_Ring1_Phase_Times,0,0.0) - # cum_Left_Ring1_Phase_Times[0] = 10.0 - # cum_Right_Ring1_Phase_Times[0] =10.0 - - phasesInRing1 = np.insert(phasesInRing1, 0, SP1-1) - x = 0 - cum_phaseInRing1= [x] - length = len(cum_Left_Ring1_Phase_Times)-1 - for i in range(length): - x = x+10 - cum_phaseInRing1.append(x) - - elif SP2-SP1 == 5: ##starting phase 3,8 - cum_Left_Ring1_Phase_Times = getCummulativePhaseTimes( - left_R1_CP_phase_times) - - cum_Right_Ring1_Phase_Times = getCummulativePhaseTimes( - right_R1_CP_phase_times) - - cum_Left_Ring1_Phase_Times = np.insert(cum_Left_Ring2_Phase_Times,len(cum_Left_Ring2_Phase_Times),cum_Left_Ring2_Phase_Times[-1]+10) - cum_Right_Ring1_Phase_Times = np.insert(cum_Right_Ring2_Phase_Times,len(cum_Right_Ring2_Phase_Times),cum_Right_Ring2_Phase_Times[-1]+10) - - phasesInRing1 = np.insert(phasesInRing1, len(phasesInRing1), SP1) - x = 0 - cum_phaseInRing1= [x] - length = len(cum_Left_Ring1_Phase_Times)-1 - for i in range(length): - x = x+10 - cum_phaseInRing1.append(x) - - - else: - cum_Left_Ring1_Phase_Times = getCummulativePhaseTimes(left_R1_CP_phase_times) - cum_Right_Ring1_Phase_Times = getCummulativePhaseTimes(right_R1_CP_phase_times) - x = 0 - cum_phaseInRing1= [x] - length = len(cum_Left_Ring1_Phase_Times)-1 - for i in range(length): - x = x+10 - cum_phaseInRing1.append(x) - - print("Phases In Ring1", phasesInRing1) - print("Cumulative Left Critical Points Phase times for Ring1 =", - cum_Left_Ring1_Phase_Times) - print("Cumulative Right Critical Points Phase times for Ring1 =", - cum_Right_Ring1_Phase_Times) - print("Cumulative Phases in Ring1 =", cum_phaseInRing1) - - ################## For Ring2################## - - left_R2_CP_phase_times = getPhaseTimesForCycle1( - left_R2_CP_phase_times, SP2, 'Left','Ring2') - right_R2_CP_phase_times = getPhaseTimesForCycle1( - right_R2_CP_phase_times, SP2, 'Right', 'Ring2') - print("Left Critical Points Phase times for Ring2 =", left_R2_CP_phase_times) - print("Right Critical Points Phase times for Ring2 =", right_R2_CP_phase_times) - # #creating cumulative list - if SP2-SP1 == 3: - cum_Left_Ring2_Phase_Times = getCummulativePhaseTimes( - left_R2_CP_phase_times) - - cum_Right_Ring2_Phase_Times = getCummulativePhaseTimes( - right_R2_CP_phase_times) - - cum_Left_Ring2_Phase_Times = np.insert(cum_Left_Ring2_Phase_Times,len(cum_Left_Ring2_Phase_Times),cum_Left_Ring2_Phase_Times[-1]+10) - cum_Right_Ring2_Phase_Times = np.insert(cum_Right_Ring2_Phase_Times,len(cum_Right_Ring2_Phase_Times),cum_Right_Ring2_Phase_Times[-1]+10) - - phasesInRing2 = np.insert(phasesInRing2, len(phasesInRing2), SP2) - x = 0 - cum_phaseInRing2= [x] - length = len(cum_Left_Ring2_Phase_Times)-1 - for i in range(length): - x = x+10 - cum_phaseInRing2.append(x) - - - elif SP2-SP1 == 5: - cum_Left_Ring2_Phase_Times = getCummulativePhaseTimes( - left_R2_CP_phase_times) - - cum_Right_Ring2_Phase_Times = getCummulativePhaseTimes( - right_R2_CP_phase_times) - - cum_Left_Ring2_Phase_Times = np.insert(cum_Left_Ring2_Phase_Times,0,0.0) - cum_Right_Ring2_Phase_Times = np.insert(cum_Right_Ring2_Phase_Times,0,0.0) - - phasesInRing2 = np.insert(phasesInRing2, 0, SP2-1) - x = 0 - cum_phaseInRing2= [x] - length = len(cum_Left_Ring2_Phase_Times)-1 - for i in range(length): - x = x+10 - cum_phaseInRing2.append(x) - - else: - cum_Left_Ring2_Phase_Times = getCummulativePhaseTimes(left_R2_CP_phase_times) - cum_Right_Ring2_Phase_Times = getCummulativePhaseTimes(right_R2_CP_phase_times) - - x = 0 - cum_phaseInRing2= [x] - length = len(cum_Left_Ring2_Phase_Times)-1 - for i in range(length): - x = x+10 - cum_phaseInRing2.append(x) - - print("Phases In Ring2", phasesInRing2) - print("Cumulative Left Critical Points Phase times for Ring2 =", - cum_Left_Ring2_Phase_Times) - print("Cumulative Right Critical Points Phase times for Ring2 =", - cum_Right_Ring2_Phase_Times) - print("Cumulative Phases in Ring2 =", cum_phaseInRing2) - - - timePhaseDiagramMethod2(SP1, SP2,cum_Left_Ring1_Phase_Times, cum_Right_Ring1_Phase_Times, - cum_phaseInRing1,cum_Left_Ring2_Phase_Times, cum_Right_Ring2_Phase_Times, - cum_phaseInRing2, phasesInRing1, phasesInRing2, ETA, ETA_Duration, req_phase, dilemmaZone_phases, dilemmaZone_ETA, dilemmaZone_ETA_Duration, 'Ring1&2') - - - - # timePhaseDiagram(SP1, SP2,cum_Left_Ring1_Phase_Times, cum_Right_Ring1_Phase_Times, - # cum_phaseInRing1,cum_Left_Ring2_Phase_Times, cum_Right_Ring2_Phase_Times, - # cum_phaseInRing2, ETA, phasesInRing1, phasesInRing2,req_phase, 'Ring1&2') - - # subplotTimePhaseDiagram(cum_Left_Ring1_Phase_Times, cum_Right_Ring1_Phase_Times, - # cum_phaseInRing1,cum_Left_Ring2_Phase_Times, cum_Right_Ring2_Phase_Times, - # cum_phaseInRing2, ETA, phasesInRing1, phasesInRing2,req_phase) - - -if __name__ == '__main__': - main() \ No newline at end of file