Ejemplo n.º 1
0
    def run(self):
        """ Begin the simulation and record the system variables during execution. """
        # Initialise the beginning parameters of the simulation
        servers = Servers(self.total_servers)
        self.event_handler = M1M2EventHandler()
        self.event_handler.start()

        # Begin iteration of events, record arrivals for checking
        self.count_arrival = 0
        self.arrival = {"handover": 0, "new": 0}
        while self.count_arrival < self.total_arrival:
            # Collect next event from the event handler
            current_event = self.event_handler.next()
            # Update simulation time
            self.sim_time = current_event.time()

            if current_event.type == "arrival":
                # Arrival event received
                priority = current_event.path
                self.count_arrival += 1
                self.arrival[priority] += 1

                # Create new arrival event
                self.event_handler.add(
                    M1M2Event(priority, "arrival", current_event.time()))

                # Check server available
                if (len(servers) > self.threshold) or \
                        (priority == "handover" and servers.is_free()):
                    # Begin serving the client.
                    current_event.served_by(servers.allocate())

                    # All event handler to manage departure
                    self.event_handler.add(current_event)
                    continue

                # No servers were available therefore the event is blocked
                self.event_handler.block(
                    current_event)  # Arriving client has been blocked

            else:
                # Departure event received
                servers.deallocate(
                    current_event.served_by())  # Free the server
                self.event_handler.depart(
                    current_event)  # Event recorded as departed.
Ejemplo n.º 2
0
    def run(self):
        """ Begin the simulation of a MMCC system. Process the information until
        termination criteria is meet.
        """

        # Initialise the beginning parameters of the simulation
        servers = Servers(self.total_servers)  # Set up server handler
        self.event_handler = EventHandler()  # Set up the event handler

        start_event = Event("arrival", 0)  # Construct the first event object
        start_event.departure_time -= start_event.arrival_time  # Reset times
        start_event.arrival_time = 0  # Reset times

        self.event_handler.add(start_event)  # Create the first event

        # Begin iteration of events, record arrivals for checking
        self.count_arrival = 0
        while self.count_arrival < self.total_arrival:
            # Collect next event from the event handler
            current_event = self.event_handler.next()
            # Update simulation time
            self.sim_time = current_event.time()

            if current_event.type == "arrival":
                # Create new arrival event
                self.event_handler.add(Event('arrival', current_event.time()))
                # Record number of arrivals
                self.count_arrival += 1

                # Check if any server is available
                if not servers.is_free():
                    self.event_handler.block(current_event)
                    continue

                # Begin serving the client.
                current_event.served_by(servers.allocate())
                # All event handler to manage departure
                self.event_handler.add(current_event)

            else:
                # Departure event received
                servers.deallocate(current_event.served_by())
                self.event_handler.depart(current_event)