Exemplo n.º 1
0
 def _generate_calls(self):
     print_status(self.env.now, f"Building has started generating calls...")
     while True:
         yield self.env.timeout(100)
         call = self._generate_single_call()
         self.call_queue.put(call)
         self.call_history.append(call)
Exemplo n.º 2
0
 def _assign_calls(self):
     """Periodically check the call queue for any calls and assign them."""
     print_status(self.env.now, "Building has started assigning calls...")
     while True:
         call = yield self.call_queue.get()
         elevator = self._select_elevator(call)
         elevator.enqueue(call)
Exemplo n.º 3
0
 def _drop_off(self):
     """Drop off all passengers waiting to get off at current floor."""
     while self.call_queue.get_dropoffs(self.floor):
         call = self.call_queue.next_dropoff(self.floor)
         call.completed(self.env.now)
         self.curr_capacity -= 1
         yield self.env.timeout(self.dropoff_duration)
         print_status(
             self.env.now, f"(drop off) Elevator {self.id} at floor "
             f"{self.floor}, capacity now {self.curr_capacity}")
Exemplo n.º 4
0
    def _await_calls(self):
        """Wait for calls to be assigned and recalibrate as they arrive.

        Periodically check the call pipe for any assigned calls, and
        recalibrate the call queue when a call is found.
        """
        while True:
            call = yield self.call_pipe.get()
            print_status(
                self.env.now,
                f"Elevator {self.id} received call {call.id} at floor {self.floor}"
            )
            self._recalibrate(call)
Exemplo n.º 5
0
    def _pick_up(self):
        """Pick up as many passengers as possible on the current floor.

        Pick up as many passengers as the Elevator's capacity allows. If the
        Elevator reaches maximum capacity, passengers are left on the current
        floor to be handled at a later time.
        """
        while self.call_queue.get_pickups(self.direction, self.floor):
            if self.curr_capacity >= self.max_capacity:
                print_status(self.env.now, f"Elevator {self.id} is full.")
                self.call_queue.reject_reachable(self.direction, self.floor)
                break
            call = self.call_queue.next_pickup(self.direction, self.floor)
            call.picked_up(self.env.now)
            yield self.env.timeout(self.pickup_duration)
            self.curr_capacity += 1
            print_status(
                self.env.now,
                f"(pick up) Elevator {self.id} at floor {self.floor}"
                f", capacity now {self.curr_capacity}")
Exemplo n.º 6
0
    def _move_to(self, target_floor):
        """Move to target floor.

        Normally, target floor lies in direction of travel while elevator is
        handling each call in a single direction. Exceptional case is when
        elevator switches directions and moves to its new starting floor.
        """
        if (target_floor is None
                or not (self.lower_bound <= target_floor <= self.upper_bound)):
            raise InvalidFloorError("Cannot move to specified floor.")
        print_status(
            self.env.now, f"Elevator {self.id} started moving"
            f" {to_string(self.direction)} to"
            f" {target_floor}")
        if target_floor - self.floor > 0:
            step = 1
        else:
            step = -1
        while self.floor != target_floor:
            yield self.env.timeout(self.f2f_time)
            self.floor += step
            print(f"floor updated to {self.floor}")
        print_status(self.env.now,
                     f"Elevator {self.id} is now at floor {self.floor}")
Exemplo n.º 7
0
 def _select_elevator(self, call):
     """Select an elevator at random to handle the given call."""
     selected = self.elevators[randint(0, self.num_elevators - 1)]
     print_status(self.env.now,
                  f"[Select] call {call.id}: Elevator {selected.id}")
     return selected
Exemplo n.º 8
0
 def _generate_single_call(self):
     """Return a single, random call."""
     call = rand_call(self.env.now, self.num_floors)
     print_status(self.env.now, f"[Generate] call {call.id}:"
                                f" floor {call.source} to {call.dest}")
     return call