def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" """ config = { 'num_people_per_round': 2, } """ self.arrival_generator = config['arrival_generator'] self.elevators = [] for i in range(config['num_elevators']): new_elevator = Elevator(config['elevator_capacity']) self.elevators.append(new_elevator) self.moving_algorithm = config['moving_algorithm'] self.num_floors = config['num_floors'] self.waiting = {} for i in range(1, config['num_floors'] + 1): self.waiting[i] = [] # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize']) self.num_round = 0 self.total_people = 0 self.people_completed = []
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" # Running Attributes self.arrival_generator = config['arrival_generator'] self.elevators = [] self.moving_algorithm = config['moving_algorithm'] self.num_floors = config['num_floors'] self.waiting = {} # Stat Attributes self._num_iterations = 0 # updated in self.run self._total_people = 0 # changed in self._generate_arrivals() self._people_completed = 0 # changed in self._handle_leaving() self._max_time = 0 # This and below update in self.handle_leaving() self._min_time = 16 # 1 + num_rounds so first occurrence is always min self._wait_times = list() # updates in self._handle_leaving() # Populates waiting with empty lists for every floor_num # i + 1 b/c first floor is 1 for i in range(self.num_floors): self.waiting[i + 1] = [] # Populates self.elevators with number if elevators needed i = 0 while i < config['num_elevators']: self.elevators.append(Elevator(config['elevator_capacity'])) i += 1 # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" self.moving_algorithm = config['moving_algorithm'] self.arrival_generator = config['arrival_generator'] self._num_elevators = config['num_elevators'] # Initialize elevators self.elevators = [] count = self._num_elevators while count > 0: self.elevators.append(Elevator(config["elevator_capacity"])) count -= 1 self.num_floors = config['num_floors'] self.waiting = {} for floor in range(1, self.num_floors + 1): self.waiting[floor] = [] self._num_people_per_round = config['num_people_per_round'] self._people_completed = [] self._num_rounds = 0 self._total_people = 0 # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.visualizer = Visualizer( self.elevators, # should be self.elevators self.num_floors, # should be self.num_floors config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration. Precondition: config['num_floors'] >= 2 config['num_elevators'] >= 1 config['elevator_capacity'] >= 1 config['num_people_per_round'] >= 0 """ # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.arrival_generator = config['arrival_generator'] elevator = [] while len(elevator) != config['num_elevators']: elevator.append(Elevator(config['elevator_capacity'])) self.elevators = elevator self.moving_algorithm = config['moving_algorithm'] self.num_floors = config['num_floors'] self.waiting = {} self.iterations = 0 self.total_people = 0 self.completed_people = 0 self.waiting_time = [] self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration. """ self.data_record = { "total_people_arrived": 0, "total_people_completed": 0, "total_round": 0, "time_record": [] } self.num_floors = config["num_floors"] self.arrival_generator = config["arrival_generator"] self.moving_algorithm = config["moving_algorithm"] self.elevators = [] for i in range(0, config["num_elevators"]): self.elevators.append(Elevator(config["elevator_capacity"])) self.waiting = {} for i in range(1, self.num_floors + 1): self.waiting[i] = [] # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration. Precondition: arrival_generator is RandomArrivals(num_floors, people_per_round) or FileArrivals(num_floors, 'csv_file_name') moving_algorithm is RandomAlgorithm() or PushyPassenger() or ShortSighted() num_floors >= 2 waiting keys are floor numbers people_per_round >= 0 """ # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.arrival_generator = config['arrival_generator'] self.elevators = [] for i in range(config['num_elevators']): self.elevators.append(Elevator(config['elevator_capacity'])) self.moving_algorithm = config['moving_algorithm'] self.num_floors = config['num_floors'] self.waiting = {} for i in range(1, self.num_floors + 1): self.waiting[i] = [] self.people_per_round = config['num_people_per_round'] self.results = { 'num_iterations': 0, 'total_people': 0, 'people_completed': 0, 'max_time': 0, 'min_time': 0, 'avg_time': 0.0} self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize'])
def closest_target_floor(self, elevator: Elevator, max_floor: int) -> int: """ Returns the closest target floor based on the elevators current passengers and current floor. This method is designed for non-empty elevators. """ closest_floor = elevator.get_floor() closest_floors = self.floor_check(elevator, max_floor) passenger_floors = [] for passenger in elevator.get_passengers(): passenger_floors.append(passenger.get_target_floor()) for floor in closest_floors: if floor in passenger_floors: closest_floor = floor break return closest_floor
def floor_check(self, elevator: Elevator, max_floor: int) -> List[int]: """ Returns a list of all possible floors by order of closest distance to elevator """ floors = [] current_floor = elevator.get_floor() floors.append(current_floor) max_distance = max_floor - 1 for i in range(1, max_distance + 1): floors.append(current_floor - i) floors.append(current_floor + i) filtered_floors = self.filter_impossible_floors(floors, max_floor) return filtered_floors
def empty_closest_floor(self, elevator: Elevator, waiting: Dict[int, List[Person]], max_floor: int) -> int: """ Returns the closest floor to the elevator that contains waiting people. This method is designed for empty elevators. """ closest_floor = elevator.get_floor() floors_to_check = self.floor_check(elevator, max_floor) for floor in floors_to_check: if len(waiting[floor]) > 0: closest_floor = floor break return closest_floor
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" self.num_floors = config['num_floors'] self.elevators = [] for _ in range(config['num_elevators']): self.elevators.append(Elevator(config['elevator_capacity'])) self.moving_algorithm = (config['moving_algorithm']) self.arrival_generator = (config['arrival_generator']) self.waiting = {} for floor in range(1, self.num_floors + 1): self.waiting[floor] = [] self.all_finished = [] self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" self.num_floors = config['num_floors'] self.elevators = [] for i in range(0, config['num_elevators']): self.elevators.append(Elevator(config['elevator_capacity'])) self.arrival_generator = config['arrival_generator'] self.moving_algorithm = config['moving_algorithm'] self.waiting = {} for i in range(1, self.num_floors + 1): self.waiting[i] = [] self.num_iterations = 0 self.total_people = 0 self.people_completed = 0 self.max_time = -1 self.min_time = -1 self.total_time = 0.0 self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" self.visualize = config['visualize'] self.elevators = [] for _ in range(config['num_elevators']): e = Elevator(config['elevator_capacity']) self.elevators.append(e) self.waiting = {} self.stats = SimulationStatistics() self.parameters = SimulationParameters(config) # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.visualizer = Visualizer(self.elevators, self.parameters.num_floors, config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration. Preconditions: num_floors >= 2 num_elevators >= 1 elevator_capacity >= 1 """ self.arrival_generator = config['arrival_generator'] self.elevators = [Elevator(config['elevator_capacity']) \ for i in range(config['num_elevators'])] self.moving_algorithm = config['moving_algorithm'] self.num_floors = config['num_floors'] self.waiting = {i + 1: [] for i in range(self.num_floors)} self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize']) # Stats self.num_iterations = 0 self.total_people = 0 self.people_completed = 0 self.wait_times = []
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" self.elevators = [] for _ in range(config["num_elevators"]): self.elevators.append(Elevator(config["elevator_capacity"])) self.waiting = {} self.num_floors = config["num_floors"] self.generate_waiting() self.arrival_generator = config["arrival_generator"] self.num_of_arrivals = 0 self.people_completed = [] self.moving_algorithm = config["moving_algorithm"] # Initialize the visualizer. # Note that this should be called *after* the other attributes # have been initialized. self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize'])
def __init__(self, config: Dict[str, Any]) -> None: """Initialize a new simulation using the given configuration.""" self.arrival_generator = config['arrival_generator'] self.elevators = [ Elevator(config['elevator_capacity']) for _i in range(config['num_elevators']) ] self.moving_algorithm = config['moving_algorithm'] self.num_floors = config['num_floors'] self.visualizer = Visualizer(self.elevators, self.num_floors, config['visualize']) self.waiting = {} self.wait_time = [] self.report = { 'num_iterations': 0, 'total_people': 0, 'people_completed': 0, 'max_time': 0, 'min_time': 0, 'avg_time': 0 }
"""CSC148 Assignment 1 - Simulation