def execute(self):

        self.Light.setNextState()
        currentState = self.Light.State
        prevState = self.Light.queryPrevState()
        print("%.4f:::Light %s Changed from %s to %s" %
              (self.T, self.Light.ID, TrafficLightState(prevState).name,
               TrafficLightState(currentState).name))

        nextState = self.Light.queryNextState()
        self.dispatch(
            LightChange(self.Light.nextStateGlobalT[nextState], self.Light))
Beispiel #2
0
    def execute(self):

        light = self.C.light

        # Set lane front pointer to Null and decrease the counter
        self.L.front = None
        self.L.capacity -= 1

        # Add the vehicle to another lane
        sinklane = self.L.sinkLanes[self.V.intention]
        sink = self.L.sinkLanes[self.V.intention].sink
        self.chain(EnterLane(self.T, self.V, sink, sinklane))

        # if there is no more vehicle in this lane, update the tail pointer
        if self.L.capacity == 0:
            self.L.tail = None
        # otherwise, make the follower arriving the crossing, after a small delay (Unit Delay)
        else:
            self.dispatch(
                ArriveCrossing(self.T + DELAY, self.V.follower, self.C,
                               self.L))

        print(
            "%d:::Car %d Left the Intersection %d from Lane %d, Light is %s, Intention is %s"
            % (self.T, self.V.ID, self.C.ID, self.L.ID,
               TrafficLightState(light.State).name, Intention(
                   self.V.intention).name))
Beispiel #3
0
    def execute(self):
        light = self.C.light

        #update the lane front pointer
        self.L.front = self.V

        print(
            "%d:::Car %d Arrived the Intersection %d from lane %d, Light is %s, Intention is %s"
            % (self.T, self.V.ID, self.C.ID, self.L.ID,
               TrafficLightState(light.State).name, Intention(
                   self.V.intention).name))

        # If the the lane the vehicle is travelling to is full, add this vehicle to waitlist of the target lane
        if self.L.sinkLanes[self.V.intention].capacity == 0:
            self.L.sinkLanes[self.V.intention].waitlist.put_nowait(self.V)

        # if the vehicle can immediately pass the crossing, send a exit event
        elif self.V.intention in light.AllowedIntention[
                light.State] and self.L.ID in light.AllowedLanes[light.State]:
            self.chain(ExitCrossing(self.T, self.V, self.C, self.L))
        # Otherwise find out the exit time (waitTime, wT)
        else:
            wt = min([
                T for LS, T in light.nextStateGlobalT.items()
                if self.V.intention in light.AllowedIntention[LS]
                and self.L.ID in light.AllowedLanes[LS]
            ]) - self.T
            self.dispatch(ExitCrossing(self.T + wt, self.V, self.C, self.L))
    def execute(self):
        light = self.C.light

        print(self.V.ID)
        # Update the lane front pointer
        self.L.front = self.V
        intention = self.V.intention[-1]
        direction = self.L.direction

        if self.retry:
            print(
                "%.4f:::Car %s retry %d time passing intersection %s from lane %s, Light is %s, Intention is %s"
                % (self.T, self.V.ID, self.retry, self.C.ID, self.L.ID,
                   TrafficLightState(
                       light.State).name, Intention(intention).name))
        else:
            print(
                "%.4f:::Car %s Arrived the Intersection %s from lane %s, Light is %s, Intention is %s"
                % (self.T, self.V.ID, self.C.ID, self.L.ID,
                   TrafficLightState(
                       light.State).name, Intention(intention).name))

        # If the the lane the vehicle is travelling to is full, add this vehicle to waitlist of the target lane
        if self.L.getExitLane(intention).isFull():
            print("%.4f:::Car %s blocked" % (self.T, self.V.ID))
            self.L.getExitLane(intention).waitlist.put_nowait(self)

        # if the vehicle can immediately pass the crossing, send a exit event
        elif light.canPass(intention, direction):
            print("%.4f:::Car %s Immediate Exited" % (self.T, self.V.ID))
            self.chain(ExitCrossing(self.T, self.V, self.C, self.L))

        # Otherwise find out the exit time (waitTime, wT), at that time, retry ArriveCrossing
        else:
            wt = min([
                T for LS, T in light.nextStateGlobalT.items()
                if light.canPass(intention, direction, LS)
            ]) - self.T + DELAY
            print("%.4f:::Car %s will wait at crossing %s until %f" %
                  (self.T, self.V.ID, self.C.ID, self.T + wt))
            self.dispatch(
                ArriveCrossing(self.T + wt,
                               self.V,
                               self.C,
                               self.L,
                               retry=self.retry + 1))
Beispiel #5
0
    def execute(self):
        currentState = self.Light.State
        nextState = self.Light.queryNextState()
        prevState = self.Light.queryPrevState()
        elapsedT = self.Light.StateLength[currentState]

        print("%d:::Light %d Changed from %s to %s" %
              (self.T, self.Light.ID, TrafficLightState(currentState).name,
               TrafficLightState(nextState).name))
        self.Light.State = nextState

        # Schedule for next LightChange event
        nextState = self.Light.queryNextState()
        for k, v in self.Light.nextStateGlobalT.items():
            self.Light.nextStateGlobalT[k] += elapsedT
        if self.Light.nextStateGlobalT[nextState] < MAX_T:
            self.dispatch(
                LightChange(self.Light.nextStateGlobalT[nextState],
                            self.Light))
Beispiel #6
0
    def execute(self):

        light = self.C.light
        self.L.capacity -= 1
        # TODO: ADD THIS VEHICLE TO ANOTHER LANE

        # if there is no more vehicle in this lane, update the tail pointer
        if self.L.capacity == 0:
            self.L.tail = None
        # otherwise, make the follower arriving the crossing, after a small delay
        else:
            self.dispatch(
                ArriveCrossing(self.T + DELAY, self.V.follower, self.C,
                               self.L))

        print(
            "%d:::Car %d Left the Intersection %d from Lane %d, Light is %s, Intention is %s"
            % (self.T, self.V.ID, self.C.ID, self.L.ID,
               TrafficLightState(light.State).name, Intention(
                   self.V.intention).name))
Beispiel #7
0
    def execute(self):
        light = self.C.light

        print(
            "%d:::Car %d Arrived the Intersection %d from lane %d, Light is %s, Intention is %s"
            % (self.T, self.V.ID, self.C.ID, self.L.ID,
               TrafficLightState(light.State).name, Intention(
                   self.V.intention).name))

        # if the vehicle can immediately pass the crossing, send a exit event
        if self.V.intention in light.AllowedIntention[
                light.State] and self.L.ID in light.AllowedLanes[light.State]:
            self.chain(ExitCrossing(self.T, self.V, self.C, self.L))
        # Otherwise find out the exit time (waitTime, wT)
        else:
            wt = min([
                T for LS, T in light.nextStateGlobalT.items()
                if self.V.intention in light.AllowedIntention[LS]
                and self.L.ID in light.AllowedLanes[LS]
            ]) - self.T
            self.dispatch(ExitCrossing(self.T + wt, self.V, self.C, self.L))
    def execute(self):

        light = self.C.light
        intention = self.V.intention[-1]

        # Set lane front pointer to Null and decrease the counter
        self.L.front = None
        self.L.nV -= 1

        if self.L.getExitLane(intention).isFull():
            print("!!!!!!! CHECK BUG !!!!!!!!")

        print(
            "%.4f:::Car %s Left the Intersection %s from Lane %s, Light is %s, Intention is %s"
            % (self.T, self.V.ID, self.C.ID, self.L.ID,
               TrafficLightState(light.State).name, Intention(intention).name))

        # Add the vehicle to another lane
        self.chain(
            EnterLane(self.T, self.V,
                      self.L.getExitLane(intention).sink,
                      self.L.getExitLane(intention)))

        # if there is no more vehicle in this lane, update the tail pointer
        if self.L.isFull():
            self.L.tail = None

        # otherwise, make the follower arriving the crossing, after a small delay (Unit Delay)
        elif self.V.follower:
            self.dispatch(
                ArriveCrossing(self.T + DELAY, self.V.follower, self.C,
                               self.L))

        self.V.follower = None
        self.V.intention.pop()

        # Also notify the waiting list
        if not self.L.waitlist.empty():
            self.chain(NotifyWaitlist(self.T, self.C, self.L))