示例#1
0
 def get_interference_capacity(self) -> float:
     """Return the maximum extra interference(dB) that PUR can stands, using threshold."""
     irp_decimal = get_decimal(self.__irp)
     if self.beta is not None:  # using beta
         rp_decimal = get_decimal(self.rx.received_power)
         return get_db(rp_decimal / self.__beta - irp_decimal)
     else:  # using threshold
         thr_decimal = get_decimal(self.threshold)
         return get_db(thr_decimal - irp_decimal)
示例#2
0
 def power_with_path_loss(
         self, tx: TX,
         rx: RX):  # False for sign means negative otherwise positive
     """Return received power after applying tx power. rx_power = tx_power + rx_power"""
     tx_power = tx.power
     if tx_power == -float('inf'):
         return rx.received_power
     loss = self.propagation_model.path_loss(tx.element * self.cell_size,
                                             rx.element * self.cell_size)
     return get_db(
         get_decimal(rx.received_power) + get_decimal(tx_power - loss))
示例#3
0
 def add_interference(self, key: str, value: float):
     """Add power(dB) of a new element to PUR.
     If it exists, it raise a warning."""
     if key in self.__irp_map:
         warnings.warn(
             "Power for {0} element already exists in {1}.".format(
                 key, self.__id) +
             " Use update_interference() if you need to update power for an element."
         )
         return
     self.__irp_map[key] = value
     self.__irp = get_db(get_decimal(self.__irp) + get_decimal(value))
示例#4
0
 def update_interference(self, key: str, value: float):
     """Update power(dB) for key to PUR.
     If it does not exist, it raise a warning."""
     if key not in self.__irp_map:
         warnings.warn(
             "Power for {0} element does not exist in {1}.".format(
                 key, self.__id) +
             " Use add_interference() if you need to add power for an element."
         )
         return
     old_power = self.__irp_map[key]
     self.__irp_map[key] = value
     self.__irp = get_db(
         get_decimal(self.__irp) + get_decimal(value) -
         get_decimal(old_power))
示例#5
0
 def delete_interference_power_from(self, key):
     if key in self.__irp_map:
         value = self.__irp_map.pop(key)
         self.__irp = get_db(get_decimal(self.__irp) - get_decimal(value))
示例#6
0
    def interpolation_max_power(self, inter_sm_param: InterSMParam):
        k_pu = self.num_select(inter_sm_param.pu_size, len(self.pus))
        k_ss = self.num_select(inter_sm_param.ss_size, len(self.sss))
        su = self.sus[
            -1]  # TODO this code has written for only one SU. Fix for multiple before using it
        if type(
                self.propagation_model
        ) == LogDistancePM:  # TODO only written for LogNormal Propagation Model
            pl_alpha = self.propagation_model.alpha
        else:
            raise ValueError("Only Log-Distance has been implemented")

        pu_inds, sss_inds, sss_dists = [], [], []
        if not inter_sm_param.selection_algo:
            pu_inds = list(range(k_pu))
            sss_inds = list(range(k_ss))
            sss_dists = [
                self.cell_size * su.tx.element.location.distance(
                    self.sss[i].rx.element.location) for i in range(k_ss)
            ]
        elif inter_sm_param.selection_algo.lower() == 'sort':
            pu_dists = []
            for i, pu in enumerate(self.pus):
                dist, ind = self.cell_size * su.tx.element.location.distance(
                    pu.tx.element.location), i
                if i < k_pu:
                    pu_inds.append(i)
                    pu_dists.append(dist)
                else:
                    for j in range(len(pu_inds)):
                        if dist < pu_dists[j]:
                            pu_dists[j], dist = dist, pu_dists[j]
                            ind, pu_inds[j] = pu_inds[j], ind

            for i, ss in enumerate(self.sss):
                dist, ind = self.cell_size * su.tx.element.location.distance(
                    ss.rx.element.location), i
                if i < k_ss:
                    sss_inds.append(i)
                    sss_dists.append(dist)
                else:
                    for j in range(len(sss_inds)):
                        if dist < sss_dists[j]:
                            sss_dists[j], dist = dist, sss_dists[j]
                            ind, sss_inds[j] = sss_inds[j], ind
        elif inter_sm_param.selection_algo.lower() == 'random':
            pu_inds = sample(range(len(self.pus)), k_pu)
            pu_dists = [
                self.cell_size * su.tx.element.location.distance(
                    self.pus[i].tx.element.location) for i in pu_inds
            ]
            sss_inds = sample(range(len(self.sss)), k_ss)
            sss_dists = [
                self.cell_size * su.tx.element.location.distance(
                    self.sss[i].rx.element.location) for i in sss_inds
            ]
        else:
            print('Unsupported selection algorithm!')
            return None
        # end selection

        # compute weights
        weights, tmp_sum_weight = [], 0.0
        for ss_dist in sss_dists:
            d = ss_dist
            d = max(d, 0.0001)  # TODO why 0.0001?

            # Weight of this SS with respect to this SU
            w = (1.0 / d)**pl_alpha
            weights.append(w)
            tmp_sum_weight += w

        # BY ME
        received_powers = []
        pl_pu_ss = []
        for i, ss_idx in enumerate(sss_inds):
            tmp_ss, all_power, tmp_pl_pu_ss = [], 0, []
            for j, pu_idx in enumerate(pu_inds):
                tmp = get_decimal(self.pus[pu_idx].tx.power) / \
                      (self.cell_size *
                       self.pus[pu_idx].tx.element.location.distance(self.sss[ss_idx].rx.element.location)) ** pl_alpha
                tmp_ss.append(tmp)
                all_power += tmp
                tmp_pl_pu_ss.append(get_decimal(self.pus[pu_idx].tx.power))
                # tmp_pow = power_with_path_loss(TRX(pus[pu_idx].loc, pus[pu_idx].p), TRX(sss[ss_
                # idx].loc, -float('inf')),
                #                                propagation_model=propagation_model, noise=noise)
                # # tmp_pow = max(tmp_pow, noise_floor)
                # tmp_ss.append(tmp_pow)
            received_powers.append([
                get_decimal(self.sss[ss_idx].rx.received_power) / all_power * x
                for x in tmp_ss
            ])
            pl_pu_ss.append(
                [x / y for x in tmp_pl_pu_ss for y in received_powers[-1]])
        # Compute SU transmit power
        # tp = thresh * sum(w(SS)) / sum(r(SS) / t(PU) * w(SS))
        max_transmit_power, estimated_path_loss = float('inf'), []
        for y, j in enumerate(pu_inds):
            sum_weight = 0.0
            sum_weighted_ratio = 0.0
            for x, i in enumerate(sss_inds):
                sum_weight += weights[x]
                # only DB is implemented here
                sum_weighted_ratio += weights[x] * (
                    received_powers[i][j] / get_decimal(self.pus[j].tx.power))
            this_pu_path_loss = sum_weighted_ratio / sum_weight
            # estimated_path_loss_tmp = []
            for x, pur in enumerate(self.pus[j].purs):
                pur_element = Element(
                    self.pus[j].tx.element.location + pur.rx.element.location,
                    pur.rx.element.height)
                this_pr_path_loss = this_pu_path_loss - inter_sm_param.gamma * \
                                    get_db(self.cell_size * su.tx.element.location.distance(pur_element.location) /
                                           su.tx.element.location.distance(self.pus[j].tx.element.location))
                # this_pr_path_loss = this_pu_path_loss - 10.0 * inter_sm_param.gamma * \
                #                     math.log10(cell_size * su.loc.distance(pur_location) /
                #  (cell_size * su.loc.distance(pus[j].loc)))
                # estimated_path_loss_tmp.append(this_pr_path_loss)
                # this_transmit_power = pur.thr - this_pr_path_loss
                this_transmit_power = pur.rx.received_power/pur.beta - pur.interference_received_power + \
                                      this_pr_path_loss
                max_transmit_power = min(max_transmit_power,
                                         this_transmit_power)
            # estimated_path_loss.append(estimated_path_loss_tmp)
        return max_transmit_power