PROGRAM MeasurePerformance; /*This vap collects a performance measure, green time utilization. It's written for an Intersection with eight phases following the standard NEMA conventions*/ VAP_Frequency 10; CONST /*****************************/ /*********CONSTANTS***********/ /*****************************/ StepLength = 0.1, /*Controller Frequency is 10 time step per second*/ SubIntervalLength= 1.0; /************************************************/ /*********Signal Status Communication***********/ /**********************************************/ /* Obtain signal status from the HILS controller. 0- red, 1- green, 2- yellow*/ Sg1:=marker_get(101); Sg2:=marker_get(102); Sg3:=marker_get(103); Sg4:=marker_get(104); Sg5:=marker_get(105); Sg6:=marker_get(106); Sg7:=marker_get(107); Sg8:=marker_get(108); /*************************************/ /***Record phase starting status ****/ /***********************************/ /*If the current signal status is green and the previous signal status was red, then it is the start of green time. Similarly, we can determine starting time step of yellow and red time.*/ /*Phase 1*/ If (Sg1=2) AND (SignalWasYellow1=0) Then YellowStarted1:=1; End; IF Sg1=1 AND (SignalWasGreen1=0) THEN GreenStarted1:=1; End; If Not((Sg1=1) And (SignalWasGreen1=0)) Then GreenStarted1:=0; End; If Not((Sg1=2) And (SignalWasYellow1=0)) Then YellowStarted1:=0; End; /*Phase 2*/ If (Sg2=2) AND (SignalWasYellow2=0) Then YellowStarted2:=1; End; IF Sg2=1 AND (SignalWasGreen2=0) THEN GreenStarted2:=1; End; If Not((Sg2=1) And (SignalWasGreen2=0)) Then GreenStarted2:=0; End; If Not((Sg2=2) And (SignalWasYellow2=0)) Then YellowStarted2:=0; End; /*Phase 3*/ If (Sg3=2) AND (SignalWasYellow3=0) Then YellowStarted3:=1; End; IF Sg3=1 AND (SignalWasGreen3=0) THEN GreenStarted3:=1; End; If Not((Sg3=1) And (SignalWasGreen3=0)) Then GreenStarted3:=0; End; If Not((Sg3=2) And (SignalWasYellow3=0)) Then YellowStarted3:=0; End; /*Phase 4*/ If (Sg4=2) AND (SignalWasYellow4=0) Then YellowStarted4:=1; End; IF Sg4=1 AND (SignalWasGreen4=0) THEN GreenStarted4:=1; End; If Not((Sg4=1) And (SignalWasGreen4=0)) Then GreenStarted4:=0; End; If Not((Sg4=2) And (SignalWasYellow4=0)) Then YellowStarted4:=0; End; /*Phase 5*/ If (Sg5=2) AND (SignalWasYellow5=0) Then YellowStarted5:=1; End; IF Sg5=1 AND (SignalWasGreen5=0) THEN GreenStarted5:=1; End; If Not((Sg5=1) And (SignalWasGreen5=0)) Then GreenStarted5:=0; End; If Not((Sg5=2) And (SignalWasYellow5=0)) Then YellowStarted5:=0; End; /*Phase 6*/ If (Sg6=2) AND (SignalWasYellow6=0) Then YellowStarted6:=1; End; IF Sg6=1 AND (SignalWasGreen6=0) THEN GreenStarted6:=1; End; If Not((Sg6=1) And (SignalWasGreen6=0)) Then GreenStarted6:=0; End; If Not((Sg6=2) And (SignalWasYellow6=0)) Then YellowStarted6:=0; End; /*Phase 7*/ If (Sg7=2) AND (SignalWasYellow7=0) Then YellowStarted7:=1; End; IF Sg7=1 AND (SignalWasGreen7=0) THEN GreenStarted7:=1; End; If Not((Sg7=1) And (SignalWasGreen7=0)) Then GreenStarted7:=0; End; If Not((Sg7=2) And (SignalWasYellow7=0)) Then YellowStarted7:=0; End; /*Phase 8*/ If (Sg8=2) AND (SignalWasYellow8=0) Then YellowStarted8:=1; End; IF Sg8=1 AND (SignalWasGreen8=0) THEN GreenStarted8:=1; End; If Not((Sg8=1) And (SignalWasGreen8=0)) Then GreenStarted8:=0; End; If Not((Sg8=2) And (SignalWasYellow8=0)) Then YellowStarted8:=0; End; /******************************/ /***Green time utilization****/ /****************************/ /**phase 1**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted1=1 Then S1:=0.0; Utilized1:=0; TotalUsedSubInterval1:=0; TotalSubInterval1:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg1=1 Then S1:=S1+StepLength; If (S1<=SubIntervalLength) Then If Detection(1)=1 Then Utilized1:=1; End; End; If (S1>=SubIntervalLength) Then TotalUsedSubInterval1:=TotalUsedSubInterval1+Utilized1; TotalSubInterval1:=TotalSubInterval1+1; S1:=0.0; Utilized1:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted1=1 Then If (S10) Then TotalUsedSubInterval1:=TotalUsedSubInterval1+Utilized1; TotalSubInterval1:=TotalSubInterval1+1; End; /*GreenUtilizationRatio2 is 100 times the true green utilization*/ GreenUtilizationRatio1:=100.0*TotalUsedSubInterval1/TotalSubInterval1; Record_value(1, GreenUtilizationRatio1); End; /**phase 2**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted2=1 Then S2:=0.0; Utilized2:=0; TotalUsedSubInterval2:=0; TotalSubInterval2:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg2=1 Then S2:=S2+StepLength; If (S2<=SubIntervalLength) Then If Detection(2)=1 Then Utilized2:=1; End; End; If (S2>=SubIntervalLength) Then TotalUsedSubInterval2:=TotalUsedSubInterval2+Utilized2; TotalSubInterval2:=TotalSubInterval2+1; S2:=0.0; Utilized2:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted2=1 Then If (S20) Then TotalUsedSubInterval2:=TotalUsedSubInterval2+Utilized2; TotalSubInterval2:=TotalSubInterval2+1; End; /*GreenUtilizationRatio2 is 100 times the true green utilization*/ GreenUtilizationRatio2:=100.0*TotalUsedSubInterval2/TotalSubInterval2; Record_value(2, GreenUtilizationRatio2); End; /**phase 3**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted3=1 Then S3:=0.0; Utilized3:=0; TotalUsedSubInterval3:=0; TotalSubInterval3:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg3=1 Then S3:=S3+StepLength; If (S3<=SubIntervalLength) Then If Detection(3)=1 Then Utilized3:=1; End; End; If (S3>=SubIntervalLength) Then TotalUsedSubInterval3:=TotalUsedSubInterval3+Utilized3; TotalSubInterval3:=TotalSubInterval3+1; S3:=0.0; Utilized3:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted3=1 Then If (S30) Then TotalUsedSubInterval3:=TotalUsedSubInterval3+Utilized3; TotalSubInterval3:=TotalSubInterval3+1; End; /*GreenUtilizationRatio3 is 100 times the true green utilization*/ GreenUtilizationRatio3:=100.0*TotalUsedSubInterval3/TotalSubInterval3; Record_value(3, GreenUtilizationRatio3); End; /**phase 4**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted4=1 Then S4:=0.0; Utilized4:=0; TotalUsedSubInterval4:=0; TotalSubInterval4:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg4=1 Then S4:=S4+StepLength; If (S4<=SubIntervalLength) Then If Detection(4)=1 Then Utilized4:=1; End; End; If (S4>=SubIntervalLength) Then TotalUsedSubInterval4:=TotalUsedSubInterval4+Utilized4; TotalSubInterval4:=TotalSubInterval4+1; S4:=0.0; Utilized4:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted4=1 Then If (S40) Then TotalUsedSubInterval4:=TotalUsedSubInterval4+Utilized4; TotalSubInterval4:=TotalSubInterval4+1; End; /*GreenUtilizationRatio4 is 100 times the true green utilization*/ GreenUtilizationRatio4:=100.0*TotalUsedSubInterval4/TotalSubInterval4; Record_value(4, GreenUtilizationRatio4); End; /**phase 5**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted5=1 Then S5:=0.0; Utilized5:=0; TotalUsedSubInterval5:=0; TotalSubInterval5:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg5=1 Then S5:=S5+StepLength; If (S5<=SubIntervalLength) Then If Detection(5)=1 Then Utilized5:=1; End; End; If (S5>=SubIntervalLength) Then TotalUsedSubInterval5:=TotalUsedSubInterval5+Utilized5; TotalSubInterval5:=TotalSubInterval5+1; S5:=0.0; Utilized5:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted5=1 Then If (S50) Then TotalUsedSubInterval5:=TotalUsedSubInterval5+Utilized5; TotalSubInterval5:=TotalSubInterval5+1; End; /*GreenUtilizationRatio5 is 100 times the true green utilization*/ GreenUtilizationRatio5:=100.0*TotalUsedSubInterval5/TotalSubInterval5; Record_value(5, GreenUtilizationRatio5); End; /**phase 6**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted6=1 Then S6:=0.0; Utilized6:=0; TotalUsedSubInterval6:=0; TotalSubInterval6:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg6=1 Then S6:=S6+StepLength; If (S6<=SubIntervalLength) Then If Detection(6)=1 Then Utilized6:=1; End; End; If (S6>=SubIntervalLength) Then TotalUsedSubInterval6:=TotalUsedSubInterval6+Utilized6; TotalSubInterval6:=TotalSubInterval6+1; S6:=0.0; Utilized6:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted6=1 Then If (S60) Then TotalUsedSubInterval6:=TotalUsedSubInterval6+Utilized6; TotalSubInterval6:=TotalSubInterval6+1; End; /*GreenUtilizationRatio6 is 100 times the true green utilization*/ GreenUtilizationRatio6:=100.0*TotalUsedSubInterval6/TotalSubInterval6; Record_value(6, GreenUtilizationRatio6); End; /**phase 7**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted7=1 Then S7:=0.0; Utilized7:=0; TotalUsedSubInterval7:=0; TotalSubInterval7:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg7=1 Then S7:=S7+StepLength; If (S7<=SubIntervalLength) Then If Detection(7)=1 Then Utilized7:=1; End; End; If (S7>=SubIntervalLength) Then TotalUsedSubInterval7:=TotalUsedSubInterval7+Utilized7; TotalSubInterval7:=TotalSubInterval7+1; S7:=0.0; Utilized7:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted7=1 Then If (S70) Then TotalUsedSubInterval7:=TotalUsedSubInterval7+Utilized7; TotalSubInterval7:=TotalSubInterval7+1; End; /*GreenUtilizationRatio7 is 100 times the true green utilization*/ GreenUtilizationRatio7:=100.0*TotalUsedSubInterval7/TotalSubInterval7; Record_value(7, GreenUtilizationRatio7); End; /**phase 8**/ /*Clear variable values at the beginning of the green time*/ If GreenStarted8=1 Then S8:=0.0; Utilized8:=0; TotalUsedSubInterval8:=0; TotalSubInterval8:=0; End; /*Record utilized sub intervals and total sub intervals during the green time*/ If Sg8=1 Then S8:=S8+StepLength; If (S8<=SubIntervalLength) Then If Detection(8)=1 Then Utilized8:=1; End; End; If (S8>=SubIntervalLength) Then TotalUsedSubInterval8:=TotalUsedSubInterval8+Utilized8; TotalSubInterval8:=TotalSubInterval8+1; S8:=0.0; Utilized8:=0; End; End; /*If the last sub interval during the green is less than the sub interval length, then it is examined whether it has been utilized at the onset of yellow. The green time utilization is recorded as 100 times of its value.*/ If YellowStarted8=1 Then If (S80) Then TotalUsedSubInterval8:=TotalUsedSubInterval8+Utilized8; TotalSubInterval8:=TotalSubInterval8+1; End; /*GreenUtilizationRatio8 is 100 times the true green utilization*/ GreenUtilizationRatio8:=100.0*TotalUsedSubInterval8/TotalSubInterval8; Record_value(8, GreenUtilizationRatio8); End; /******************************/ /***Determine phase status****/ /****************************/ /*This section should always be the last in the code*/ /*Phase 1*/ If Sg1=1 Then SignalWasGreen1:=1; ENd; If Sg1<>1 Then SignalWasGreen1:=0; End; If Sg1=2 Then SignalWasYellow1:=1; End; If Sg1<>2 Then SignalWasYellow1:=0; End; /*Phase 2*/ If Sg2=1 Then SignalWasGreen2:=1; ENd; If Sg2<>1 Then SignalWasGreen2:=0; End; If Sg2=2 Then SignalWasYellow2:=1; End; If Sg2<>2 Then SignalWasYellow2:=0; End; /*Phase 3*/ If Sg3=1 Then SignalWasGreen3:=1; ENd; If Sg3<>1 Then SignalWasGreen3:=0; End; If Sg3=2 Then SignalWasYellow3:=1; End; If Sg3<>2 Then SignalWasYellow3:=0; End; /*Phase 4*/ If Sg4=1 Then SignalWasGreen4:=1; ENd; If Sg4<>1 Then SignalWasGreen4:=0; End; If Sg4=2 Then SignalWasYellow4:=1; End; If Sg4<>2 Then SignalWasYellow4:=0; End; /*Phase 5*/ If Sg5=1 Then SignalWasGreen5:=1; ENd; If Sg5<>1 Then SignalWasGreen5:=0; End; If Sg5=2 Then SignalWasYellow5:=1; End; If Sg5<>2 Then SignalWasYellow5:=0; End; /*Phase 6*/ If Sg6=1 Then SignalWasGreen6:=1; ENd; If Sg6<>1 Then SignalWasGreen6:=0; End; If Sg6=2 Then SignalWasYellow6:=1; End; If Sg6<>2 Then SignalWasYellow6:=0; End; /*Phase 7*/ If Sg7=1 Then SignalWasGreen7:=1; ENd; If Sg7<>1 Then SignalWasGreen7:=0; End; If Sg7=2 Then SignalWasYellow7:=1; End; If Sg7<>2 Then SignalWasYellow7:=0; End; /*Phase 8*/ If Sg8=1 Then SignalWasGreen8:=1; ENd; If Sg8<>1 Then SignalWasGreen8:=0; End; If Sg8=2 Then SignalWasYellow8:=1; End; If Sg8<>2 Then SignalWasYellow8:=0; End.