示例#1
0
    def checkMaxGreenAndYellowPhaseRule(self, tl: TrafficLight,
                                        nextRule: Rule) -> bool:
        if "G" in traci.trafficlight.getPhaseName(tl.getName()):
            if tl.getTimeInCurrentPhase() >= self.maxGreenPhaseTime:
                if traci.trafficlight.getPhase(
                        tl.getName()) >= (len(tl.getPhases()) - 2):
                    traci.trafficlight.setPhase(tl.getName(), 0)
                    return True
                else:
                    traci.trafficlight.setPhase(
                        tl.getName(),
                        traci.trafficlight.getPhase(tl.getName()) + 1)
                    return True
            else:
                #traci.trafficlight.setPhase(tl.getName(), nextRule.getAction())
                tl.updateTimeInCurrentPhase(5)

        elif "Y" in traci.trafficlight.getPhaseName(tl.getName()):
            if tl.getTimeInCurrentPhase() >= self.maxYellowPhaseTime:
                if traci.trafficlight.getPhase(
                        tl.getName()) >= (len(tl.getPhases()) - 2):
                    traci.trafficlight.setPhase(tl.getName(), 0)
                    return True

                else:
                    traci.trafficlight.setPhase(
                        tl.getName(),
                        traci.trafficlight.getPhase(tl.getName()) + 1)
                    return True
            else:
                tl.updateTimeInCurrentPhase(5)
        else:
            return False
示例#2
0
    def applyUserDefinedRuleAction(self, trafficLight: TrafficLight,
                                   currPhaseName: str, rule: Rule) -> None:
        # If max green phase time reached, switch phase to yellow in same direction
        if rule.getConditions()[0] == "maxGreenPhaseTimeReached":
            currPhase = traci.trafficlight.getPhaseName(trafficLight.getName())
            currPhase[5] = "Y"
            traci.trafficlight.setPhase(trafficLight.getName(), currPhase)

        # If max yellow phase time reached, switch to next phase in the schedule
        elif rule.getConditions()[0] == "maxYellowPhaseTimeReached":
            if traci.trafficlight.getPhase(trafficLight.getName()) >= (
                    len(trafficLight.getPhases()) - 2):
                traci.trafficlight.setPhase(trafficLight.getName(), 0)
            else:
                traci.trafficlight.setPhase(
                    trafficLight.getName(),
                    traci.trafficlight.getPhase(trafficLight.getName()) + 1)