Ejemplo n.º 1
0
    def __init__(self):
        # Base Station
        self.n_antennas = f.get_codebook().shape[
            0]  # number of transmit antennas
        self.codebook_size = f.get_codebook().shape[1]  # number of codes
        self.n_power_levels = 5  # number of discrete power levels
        self.n_actions = self.codebook_size * self.n_power_levels  # number of available actions to choose
        self.bs_power = 38  # maximum transmit power of base stations

        # Channel
        self.angular_spread = 3 / 180 * np.pi  # angular spread
        self.multi_paths = 4  # number of multi-paths
        self.rho = 0.64  # channel correlation coefficient
        self.noise_power = f.dB2num(-114)  # noise power

        # Cellular Network
        self.cell_radius = 200  # cell radius
        self.n_links = 19  # number of simulated direct links in the simulation
        self.inner_cell_radius = 10  # inner cell radius

        # Simulation
        self.slot_interval = 0.02  # interval of one time slot
        self.random_seed = 2019  # random seed to control the simulated cellular network
        self.total_slots = 100000  # total time slots in the simulation
        self.U = 5  # number of neighbors taken into consideration
Ejemplo n.º 2
0
    def __init__(self, bs, ue):
        """ establish a channel given a BS and a UE """

        self.bs = bs
        self.ue = ue
        self.index = np.array([bs.index, ue.index])

        self.norminal_aod = f.get_azimuth(bs.location, ue.location)
        self.angular_spread = Config().angular_spread
        self.multi_paths = Config().multi_paths
        self.rho = Config().rho

        self.d = np.linalg.norm(self.bs.location - self.ue.location)
        self.path_loss = 1 / f.dB2num(120.9 + 37.6 * np.log10(self.d / 1000) +
                                      np.random.normal(0, 8))
        self._check_is_link_()
        self._generate_steering_vector_()
        self.g = (np.random.randn(1, self.multi_paths) +
                  np.random.randn(1, self.multi_paths) * 1j) / np.sqrt(
                      2 * self.multi_paths)
        self._cal_csi_(ir_change=True)
        # for saving outdated csi
        self.h1, self.h2 = None, None
        self.r_power10, self.r_power11, self.r_power20, self.r_power21 = None, None, None, None
        self.gain10, self.gain11, self.gain20, self.gain21 = None, None, None, None
Ejemplo n.º 3
0
    def observe(self):
        """ obtain the states of the BSs"""
        # normalization factors for the elements in states
        n_r_power = 1e-9
        n_gain = 1e-9
        n_IN = 1e-7
        power_max = f.dB2num(self.config.bs_power)
        n_links = self.config.n_links - 1
        n_ulitity = 5

        observations = []
        for link in self.links:
            local_information, interferer_information, interfered_information = [], [], []

            local_information = np.hstack(
                (link.bs.power / power_max, link.bs.code_index,
                 link.utility11 / n_ulitity, link.gain / n_gain,
                 link.gain10 / n_gain, link.IN / n_IN,
                 link.IN10 / n_IN)).tolist()

            for link_index in link.interferer_neighbors11:
                channel = self.get_channel_list(bs_index=link_index,
                                                ue_index=link.ue.index)
                interferer_information.append(channel.bs.index / n_links)
                interferer_information.append(channel.r_power11 / n_r_power)
                interferer_information.append(channel.bs.code_index)
                interferer_information.append(
                    self.get_link(link_index).utility11 / n_ulitity)

            for link_index in link.interferer_neighbors21:
                channel = self.get_channel_list(bs_index=link_index,
                                                ue_index=link.ue.index)
                interferer_information.append(channel.bs.index / n_links)
                interferer_information.append(channel.r_power21 / n_r_power)
                interferer_information.append(channel.bs.code_index1)
                interferer_information.append(
                    self.get_link(link_index).utility21 / n_ulitity)

            for link_index in link.interfered_neighbors11:
                channel = self.get_channel_list(bs_index=link.bs.index,
                                                ue_index=link_index)
                interfered_information.append(channel.gain11 / n_gain)
                interfered_information.append(
                    self.get_link(link_index).utility11 / n_ulitity)
                interfered_information.append(channel.r_power11 /
                                              self.get_link(link_index).IN11)

            observation = local_information + interferer_information + interfered_information
            observations.append(observation)
        return np.array(observations)
Ejemplo n.º 4
0
    def __init__(self, location, index):

        self.location = location
        self.index = index
        self.n_antennas = Config().n_antennas
        self.dqn = DQN()
        self.max_power = f.dB2num(Config().bs_power)
        self.codebook = f.get_codebook()
        self.powerbook = np.arange(
            Config().n_power_levels) * self.max_power / (
                Config().n_power_levels - 1)
        self.code_index = random.randint(0, Config().codebook_size - 1)
        self.power_index = random.randint(0, Config().n_power_levels - 1)

        self.code = self.codebook[:, self.code_index]
        self.power = self.powerbook[self.power_index]

        self._init_params_()
Ejemplo n.º 5
0
    def __init__(self):
        # Base Station
        self.n_antennas = f.get_codebook().shape[0]
        self.codebook_size = f.get_codebook().shape[1]
        self.n_power_levels = 5
        self.n_actions = self.codebook_size * self.n_power_levels
        self.bs_power = 38

        # Channel
        self.angular_spread = 3 / 180 * np.pi
        self.multi_paths = 4
        self.rho = 0.64
        self.noise_power = f.dB2num(-114)

        # Cellular Network
        self.cell_radius = 200
        self.n_links = 19
        self.inner_cell_radius = 10

        # Simulation
        self.slot_interval = 0.02
        self.random_seed = 2020
        self.total_slots = 100000
        self.U = 5
Ejemplo n.º 6
0
import json
import numpy as np
from config import Config
import random
import time
import functions as f
import scipy.io as sio
import os
os.environ['MKL_NUM_THREADS'] = '1'

c = Config()
random.seed(c.random_seed)
np.random.seed(c.random_seed)
K = c.n_antennas
M = c.n_links
p_max = f.dB2num(c.bs_power)
codebook = f.get_codebook()
noise_power = c.noise_power
cn = CN()
utility = []
cn.draw_topology()
rate_m = []
for _ in range(c.total_slots):
    print(_)
    H = cn.get_H()
    # fp algorithm
    y, y_next = np.zeros(M, dtype=np.complex), np.zeros(M, dtype=np.complex)
    W, W_next = np.zeros((K, M), dtype=np.complex), np.zeros((K, M),
                                                             dtype=np.complex)
    gamma, gamma_next = np.zeros(M), np.zeros(M)