예제 #1
0
    def __run_multiple_pairs_shitty_distribution(self, pair_distance):
        lower_lim_uc = 10**(self.lower_lim_uc_db/10) # sinr lower bound for MUEs in dB
        lower_lim_d2d = 10**(self.lower_lim_d2d_db/10)  # sinr lower bound for DUEs

        # channel specifications
        prop_coef = 3.5       # propagation coefficient
        channel = pathloss_channel(prop_coef)

        # noise specifications
        sigma = 1e-6        # awgn variance        

        mues = [mobile_user(x) for x in range(self.n_mues)]    # mobile users

        range1 = range(self.n_d2d//2)

        dues_tx = [d2d_user(i,type=d2d_node_type.TX) for i in range1]        
        dues_rx = [d2d_user(i,type=d2d_node_type.RX) for i in range1]        

        for i in range1:
            dues_tx[i].set_distance_d2d(pair_distance)
            dues_rx[i].set_distance_d2d(pair_distance)
        
        gen.distribute_nodes(mues,self.bs)     # distribute nodes on the map
        gen.distribute_pair_fixed_distance_multiple(dues_tx, dues_rx, self.bs) 

        # set nodes distances to bs
        for n in dues_tx+dues_rx:
            n.set_distance_to_bs(spatial.distance.euclidean(n.position, self.bs.position))

        # critical distance method
        allocation_matrix = self.__critical_distance_allocation_matrix(mues, dues_tx, channel)
        allocation_vector = self.__allocation_algorithm(allocation_matrix)

        return np.sum(allocation_vector)/self.n_d2d
예제 #2
0
    def __run_multiple_pairs(self, pair_distances_list):
        lower_lim_uc = 10**(self.lower_lim_uc_db/10) # sinr lower bound for MUEs in dB
        lower_lim_d2d = 10**(self.lower_lim_d2d_db/10)  # sinr lower bound for DUEs

        # channel specifications
        prop_coef = 3.5       # propagation coefficient
        channel = pathloss_channel(prop_coef)

        # noise specifications
        sigma = 1e-6        # awgn variance        

        mues = [mobile_user(x) for x in range(self.n_mues)]    # mobile users

        dues_tx = list()
        dues_rx = list()

        for i in range(self.n_d2d//2):
            due_tx = d2d_user(i,type=d2d_node_type.TX) 
            due_rx = d2d_user(i,type=d2d_node_type.RX)   
            distance = random.choice(pair_distances_list)            
            due_tx.set_distance_d2d(distance)   
            due_rx.set_distance_d2d(distance)               
            dues_tx.append(due_tx) # d2d users tx   
            dues_rx.append(due_rx) # d2d users rx 

        gen.distribute_nodes(mues,self.bs)     # distribute nodes on the map

        gen.distribute_pair_fixed_distance_multiple(dues_tx, dues_rx, self.bs) 

        # set nodes distances to bs
        for n in dues_tx+dues_rx:
            n.set_distance_to_bs(spatial.distance.euclidean(n.position, self.bs.position))

        # critical distance method
        allocation_matrix = self.__critical_distance_allocation_matrix(mues, dues_tx, channel)

        allocation_vector = self.__allocation_algorithm(allocation_matrix)
        
        # distances histogram stuff
        dues_indexes = np.where(allocation_vector==1)[0]        
        distances = [d.distance_d2d for d in np.array(dues_tx)[dues_indexes]]
        distances_indexes = np.array(list(), dtype='int32')
        for i in distances:
            distances_indexes = np.concatenate((np.array(distances_indexes),np.where(pair_distances_list == i)[0]))

        distances_total_allocation = np.zeros(len(pair_distances_list))
        distances_appeareances = np.zeros(len(pair_distances_list))
        unique, counts = np.unique([list(pair_distances_list).index(d.distance_d2d) for d in dues_tx], return_counts=True) 
        aux = dict(zip(unique, counts))

        for i in aux.keys():
            distances_appeareances[i] = aux[i]

        for i in distances_indexes:
            distances_total_allocation[i] += 1

        return distances_total_allocation, distances_appeareances
예제 #3
0
    def __run_single_pair(self, pair_distance):
        lower_lim_uc = 10**(self.lower_lim_uc_db/10) # sinr lower bound for MUEs in dB
        lower_lim_d2d = 10**(self.lower_lim_d2d_db/10)  # sinr lower bound for DUEs

        # channel specifications
        prop_coef = 3.5       # propagation coefficient
        channel = pathloss_channel(prop_coef)

        # noise specifications
        sigma = 1e-6        # awgn variance

        mues = [mobile_user(x) for x in range(self.n_mues)]    # mobile users
        dues = [d2d_user(x) for x in range(self.n_d2d)]   # d2d users

        _ = gen.distribute_nodes(mues,self.bs)     # distribute nodes on the map
        gen.distribute_pair_fixed_distance(dues, self.bs,pair_distance)        

        # calculate pathloss between d2d pairs
        d2d_pair_pathloss = channel.calculate_pathloss(pair_distance)        
        
        # set minimal allowed tx power for MUEs
        mue_bs_distance = spatial.distance.euclidean(mues[0].position, self.bs.position)
        noises_mues = [n**2/2 for n in sigma*np.random.randn(len(mues))]
        mues[0].set_pathloss_to_bs(channel.calculate_pathloss(mue_bs_distance))
        self.set_tx_power_mues_nodes(mues, lower_lim_uc, noises_mues, self.sinr_margin)

        if self.simulation_type == system_simulation_type_enum.SINGLE_D2D_PAIR_DIFFERENT_NOISE:
            noises_dues = [n**2/2 for n in [sigma*np.random.randn()]]
        else:
            noises_dues = noises_mues
            
        # set max allowed tx power for DUEs
        d2d_bs_distance = spatial.distance.euclidean(dues[0].position, self.bs.position)
        dues[0].set_pathloss_to_bs(channel.calculate_pathloss(d2d_bs_distance))        
        self.set_tx_power_dues_nodes([dues[0]], lower_lim_d2d, noises_dues, self.sinr_margin)

        # calculate sinr_dd
        d2d_mue_distance = spatial.distance.euclidean(mues[0].position, dues[0].position)
        d2d_mue_pathloss = channel.calculate_pathloss(d2d_mue_distance)
        sinr_dd = dues[0].tx_power*d2d_pair_pathloss/(noises_dues[0]+mues[0].tx_power*d2d_mue_pathloss)
        sinr_mue = self.get_sinr_uc(mues[0], dues[0], noises_mues[0])

        is_d2d_allocated_sinr = sinr_dd > lower_lim_d2d and sinr_mue > lower_lim_uc

        # critical distance method
        d2d_crit_distance = self.d2d_critical_distance(self.sinr_margin,channel,lower_lim_d2d,lower_lim_uc,mue_bs_distance, d2d_mue_distance, d2d_bs_distance)

        is_d2d_allocated_dcrit = pair_distance < d2d_crit_distance

        return is_d2d_allocated_dcrit, is_d2d_allocated_sinr
예제 #4
0
sinr_margin = 1  # safety margin
n_orthogonal_resources = 200

# devices distribution
n_mues = n_orthogonal_resources
n_d2d = 2 * n_mues  # must be an even number
bs = base_station((0, 0), radius=250)

# channel specifications
prop_coef = 3.5  # propagation coefficient
channel = pathloss_channel(prop_coef)

# noise specifications
sigma = 1e-6  # awgn variance

mues = [mobile_user(x) for x in range(n_mues)]  # mobile users
dues = [d2d_user(x) for x in range(n_d2d)]  # d2d users

nodes_bs_distances_table = gen.distribute_nodes(
    mues + dues, bs)  # distribute nodes on the map

# calculate pathloss from BS to each other node
for node in mues + dues:
    node.set_pathloss_to_bs(
        channel.calculate_pathloss(nodes_bs_distances_table[node.id]))

# calculate pathloss between d2d pairs
d2d_distances_table = gen.get_distances_table(dues)
d2d_pairs_table, d2d_pairs_pathloss_table = gen.get_d2d_links(
    d2d_distances_table, dues, channel)
예제 #5
0
    def __run(self):
        # simulation parameters
        lower_lim_uc = 10**(self.lower_lim_uc_db/10) # sinr lower bound for MUEs in dB
        lower_lim_d2d = 10**(self.lower_lim_d2d_db/10)  # sinr lower bound for DUEs

        # channel specifications
        prop_coef = 3.5       # propagation coefficient
        channel = pathloss_channel(prop_coef)

        # noise specifications
        sigma = 1e-6        # awgn variance

        mues = [mobile_user(x) for x in range(self.n_mues)]    # mobile users
        dues = [d2d_user(x) for x in range(self.n_d2d)]   # d2d users

        nodes_bs_distances_table = gen.distribute_nodes(mues+dues,self.bs)     # distribute nodes on the map

        # calculate pathloss from BS to each other node
        for node in mues+dues:    
            node.set_pathloss_to_bs(
                channel.calculate_pathloss(
                    nodes_bs_distances_table[node.id]
                )
            )

        # calculate pathloss between d2d pairs
        d2d_distances_table = gen.get_distances_table(dues)
        d2d_pairs_table, _ = gen.get_d2d_links(d2d_distances_table, dues, channel)

        # set minimal allowed tx power for MUEs
        noises_mues = [n**2/2 for n in sigma*np.random.randn(len(mues))]
        self.set_tx_power_mues_nodes(mues, lower_lim_uc, noises_mues, self.sinr_margin)

        # allocate MUEs
        mues_allocation_table = self.allocate_resources_sequential(mues, self.n_orthogonal_resources)

        # allocate DUEs
        dues_ids = [id[0] for id in np.array(list(d2d_pairs_table.values()))[:,0]]
        dues_txs = [due for due in dues if due.id in dues_ids]
        d2d_request_access_table = self.allocate_resources_sequential(dues_txs, self.n_orthogonal_resources)
        noises_dues = [n**2/2 for n in sigma*np.random.randn(len(dues_txs))]
        # set max allowed tx power for DUEs
        self.set_tx_power_dues_nodes(dues_txs, lower_lim_d2d, noises_dues, self.sinr_margin)

        # mues_sharing = [m for m in mues if m.id in [mues_allocation_table[i] for i in list(d2d_request_access_table.keys())]]
        sharing_table = dict()
        d2d_mue_distances_table = dict()
        for key in list(d2d_request_access_table.keys()):
            sharing_table[d2d_request_access_table[key]] = mues_allocation_table[key]    
        for key in list(sharing_table.keys()):    
            d2d_mue_distances_table[key] = spatial.distance.euclidean(
                next(m for m in mues if m.id == sharing_table[key]).position,
                next(d for d in dues_txs if d.id == key).position
            )

        # calculate sinr_dd
        d2d_mue_pathloss_table = dict()
        for key in list(d2d_mue_distances_table.keys()):
            d2d_mue_pathloss_table[key] = channel.calculate_pathloss(d2d_mue_distances_table[key])
        sinr_dd_table = dict()
        for key in list(d2d_mue_distances_table.keys()):
            due = next(d for d in dues_txs if d.id == key)
            mue = next(m for m in mues if m.id == sharing_table[key])
            i = int(due.id[due.id.index(':')+1:])
            sinr_dd_table[key] = due.tx_power*d2d_mue_distances_table[key]/(noises_dues[i]+mue.tx_power*d2d_mue_pathloss_table[key])

        # d2d allocation table
        dues_allocation_table = dict()
        for key in list(sinr_dd_table.keys()):
            dues_allocation_table[key] = sinr_dd_table[key] > lower_lim_d2d    

        # TODO: implementar verificação de enlace por meio da distância crítica e comparar com o método da SINR          

        # critical distance method
        d2d_crit_distance_table = dict()
        for d in dues_txs:
            d2d_crit_distance_table[d.id] = self.d2d_critical_distance(self.sinr_margin,channel,lower_lim_d2d,lower_lim_uc,nodes_bs_distances_table[sharing_table[d.id]], d2d_mue_distances_table[d.id],nodes_bs_distances_table[d.id])
        dues_allocation_table_dcrit = dict()
        for d in dues_txs:
            dues_allocation_table_dcrit[d.id] = d2d_pairs_table[d.link_id][1] <=  nodes_bs_distances_table[d.id]

        d2d_allocation_rate_sinr = np.sum(list(dues_allocation_table.values()))/len(dues_allocation_table)
        d2d_allocation_rate_dcrit = np.sum(list(dues_allocation_table_dcrit.values()))/len(dues_allocation_table_dcrit)

        return d2d_allocation_rate_dcrit, d2d_allocation_rate_sinr