Beispiel #1
0
 def compute_simulation_stats(self):
     # run here the code to summarize statistics from this specific run
     if self.plot_simulation_progress:
         plots.plot_simulation_progress(self)
     # add here the code to include other statistics you may want
     self.results[self.policy.name][self.load].append({
         'request_blocking_ratio':
         self.get_request_blocking_ratio(),
         'average_link_usage':
         np.mean([
             self.topology[n1][n2]['utilization']
             for n1, n2 in self.topology.edges()
         ]),
         'individual_link_usage': [
             self.topology[n1][n2]['utilization']
             for n1, n2 in self.topology.edges()
         ],
         'average_node_usage':
         np.mean([
             self.topology.nodes[node]['utilization']
             for node in self.topology.graph['dcs']
         ]),
         'individual_node_usage': {
             node: self.topology.nodes[node]['utilization']
             for node in self.topology.graph['dcs']
         }
     })
Beispiel #2
0
    def setup_next_arrival(self):
        """
        Returns the next arrival to be scheduled in the simulator
        """
        if self._processed_arrivals > self.num_arrivals:
            return None # returns None when all arrivals have been processed
        at = self.current_time + self.rng.expovariate(1 / self.mean_service_inter_arrival_time)

        ht = self.rng.expovariate(1 / self.mean_service_holding_time)
        dst = src = self.rng.choice([x for x in self.topology.nodes()])
        while src == dst:
            dst = self.rng.choice([x for x in self.topology.nodes()])
        src_id = self.topology.graph['node_indices'].index(src)
        dst_id = self.topology.graph['node_indices'].index(dst)

        self._processed_arrivals += 1

        if self._processed_arrivals % self.track_stats_every == 0:
            self.tracked_results['request_blocking_ratio'].append(self.get_request_blocking_ratio())
            self.tracked_results['average_link_usage'].append(np.mean([(self.topology[n1][n2]['total_units'] - self.topology[n1][n2]['available_units']) / self.topology[n1][n2]['total_units'] for n1, n2 in self.topology.edges()]))
        if self._processed_arrivals % self.plot_tracked_stats_every == 0:
            plots.plot_simulation_progress(self)

        #TODO: number of units necessary can also be randomly selected, now it's always one
        next_arrival = Service(self._processed_arrivals, at, ht, src, src_id, dst, dst_id, number_units=1)
        self.add_event(Event(next_arrival.arrival_time, events.arrival, next_arrival))