Esempio n. 1
0
 def get_LoS_Rate(self, ue_s):
     sc_xyz = np.array([])
     ch_model = 'fsp'
     mimo_model = MIMO(ue_s, self.gNB[0], sc_xyz, ch_model, self.ptx, self.N_tx, self.N_rx)
     #print("[Env]: LoS h: {0}".format(mimo_model.channel.pathloss))
     Los_SNR, Los_rate = mimo_model.Los_Rate()
     return Los_rate
Esempio n. 2
0
    def get_Exh_Rate(self, state):
        state = np.rint(state * self.high_obs)
        ue_xloc, ue_yloc = state
        ue_pos = np.array([ue_xloc, ue_yloc, 0])

        if (ue_xloc == 0) and (ue_yloc) == 0:
            #return -1.0,-1.0
            ue_pos = np.array([ue_xloc + 40, ue_yloc + 40, 0])

        mimo_exh_model = MIMO(ue_pos, self.gNB[0], self.sc_xyz, self.ch_model,
                              self.ptx, self.N_tx, self.N_rx)
        #rbeam_vec = self.BeamSet#Generate_BeamDir(self.N)
        exh_SNR = []
        exh_rates = []

        for rbeam in self.BeamSet:  #rbeam_vec:
            SNR, rate = mimo_exh_model.Calc_ExhRate(self.SF_time,
                                                    np.array([rbeam, 0]))
            #rate = 1e3 * rate
            exh_SNR.append(SNR)
            exh_rates.append(rate)

        best_rbeam_ndx = np.argmax(exh_rates)
        best_beam = self.BeamSet[best_rbeam_ndx]
        SNRmax, rate_max = mimo_exh_model.Calc_ExhRate(self.SF_time,
                                                       np.array([best_beam,
                                                                 0]),
                                                       noise_flag=False)
        #print("[UAV_Env]: AOD: {}, AoA: {}, AoD-AoA: {}".format(mimo_exh_model.channel.az_aod[0], self.BeamSet[best_rbeam_ndx], -self.BeamSet[best_rbeam_ndx]+mimo_exh_model.channel.az_aod[0]))
        return best_beam, rate_max  #(Best RBS, Best Rate)
Esempio n. 3
0
    def step(self, action):
        assert self.act_space.contains(action), "%r (%s) invalid" % (action, type(action))

        state = self.state * self.high_obs
        dist, ue_ang, rbd = state
        rbs = self.BeamSet[action]

        ue_pos = np.array(sph2cart(ue_ang, 0, dist)) #ue_pos is(x,y)

        ue_pos[0] += self.ue_v

        new_dist = np.sqrt(ue_pos[0]**2 + ue_pos[1]**2) #x**2 + y**2
        new_ang = np.arctan2(ue_pos[1],ue_pos[0])
        self.state = np.array([new_dist, new_ang, rbs]) / self.high_obs

        self.mimo_model = MIMO(ue_pos, self.gNB[0], self.sc_xyz, self.ch_model, self.ptx, self.N_tx, self.N_rx)
        prev_rate = self.rate
        prev_dist = dist
        self.SNR, self.rate = self.mimo_model.Calc_Rate(self.SF_time, np.array([rbs, 0]))#rkbeam_vec, tbeam_vec )

        self.steps_done += 1

        rwd = self._reward(prev_rate, prev_dist, new_dist)
        #print("[uav_env] rwd: {}".format(rwd))
        done = self._gameover()

        return self.state, rwd, done, {}
Esempio n. 4
0
    def Compute_RIM(self, ue, omega_vec):
        #compute rssi information of each ue_x and gnB location, forming a 3kx1 nd.array
        self.mimo_models = []
        RIM = np.zeros(3*self.K) #(3k, 1), k set of receive beams each instant

        for i in range(len(self.gNB)):
            self.mimo_models.append(MIMO(ue, self.gNB[i], self.ptx, self.N_tx, self.N_rx))
            RIM[i*self.K: (i+1)*self.K] = self.mimo_models[i].Compute_RSSI(omega_vec, self.TB_r)

        return RIM
Esempio n. 5
0
    def get_Los_Rate(self, state):
        dist, ue_ang, rbd = (state * self.high_obs)
        ue_pos = np.array(sph2cart(ue_ang, 0, dist))  # ue_pos is(x,y)

        sc_xyz = np.array([])
        ch_model = 'fsp'

        mimo_model = MIMO(ue_pos, self.gNB[0], sc_xyz, ch_model, self.ptx, self.N_tx, self.N_rx)
        SNR, rate = mimo_model.Los_Rate()  # rkbeam_vec, tbeam_vec )

        return SNR, rate
Esempio n. 6
0
    def step(self, action):
        assert self.act_space.contains(action), "%r (%s) invalid" % (action, type(action))

        state = np.rint(self.state * self.high_obs)

        rbd_ndx, ue_mv_ndx = self.decode_action(action)
        ue_vx, ue_vy = self.choose_vel(ue_mv_ndx)
        rbs = self.BeamSet[rbd_ndx]
        ue_xdest = self.ue_xdest[0]
        ue_ydest = self.ue_ydest[0]

        ue_xloc, ue_yloc = state

        ue_mv = self.ue_moves[ue_mv_ndx]
        if ue_mv == 'L':
            new_ue_xloc = max(ue_xloc + ue_vx, np.min(self.ue_xloc))
            new_ue_yloc = ue_yloc + ue_vy
        if ue_mv == 'U':
            new_ue_xloc = ue_xloc + ue_vx
            new_ue_yloc = min(ue_yloc + ue_vy, np.max(self.ue_yloc))
        if ue_mv == 'R':
            new_ue_xloc = min(ue_xloc + ue_vx, np.max(self.ue_xloc))
            new_ue_yloc = ue_yloc + ue_vy
        if ue_mv == 'D':
            new_ue_xloc = ue_xloc + ue_vx
            new_ue_yloc = max(ue_yloc + ue_vy, np.min(self.ue_yloc))

        new_ue_pos = np.array([new_ue_xloc, new_ue_yloc, 0])
        self.mimo_model = MIMO(new_ue_pos, self.gNB[0], self.sc_xyz, self.ch_model, self.ptx, self.N_tx, self.N_rx)


        self.SNR, self.rate = self.mimo_model.Calc_Rate(self.SF_time, np.array([rbs, 0]))  # rkbeam_vec, tbeam_vec )

        self.cur_rate = self.rate
        self.cur_dist = np.sqrt((ue_xloc-ue_xdest)**2 + (ue_yloc-ue_ydest)**2) #x**2 + y**2
        self.state = np.array([new_ue_xloc, new_ue_yloc]) / self.high_obs
        rwd, done = self._gameover(rbs, self.mimo_model.az_aod)

        #self.rate = 1e3*self.rate

        new_ue_xndx = np.where(self.ue_xloc ==new_ue_xloc)[0][0]
        new_ue_yndx = np.where(self.ue_yloc == new_ue_yloc)[0][0]
        self.ue_path_rates.append(self.rate)
        #self.ue_path_rates.append(self.rate)
        self.ue_path.append(np.array([new_ue_xloc, new_ue_yloc]))

        self.steps_done += 1

        #rwd = self._reward(prev_dist)
        #print("[uav_env] rwd: {}".format(rwd))


        return self.state, rwd, done, {}
Esempio n. 7
0
    def get_Los_Rate(self, state):

        state = np.rint(state * self.high_obs)
        ue_xloc, ue_yloc = state

        sc_xyz = np.array([])
        ch_model = 'fsp'
        ue_pos = np.array([ue_xloc, ue_yloc, 0])

        mimo_model = MIMO(ue_pos, self.gNB[0], sc_xyz, ch_model, self.ptx, self.N_tx, self.N_rx)
        SNR, rate = mimo_model.Los_Rate()  # rkbeam_vec, tbeam_vec )
        #rate = 1e3 * rate
        return SNR, rate
Esempio n. 8
0
    def step(self, action):
        # check the legal move first and then return its reward
        # if action in self.actions[self.current_state]:
        #assert self.action_space.contains(action), "%r (%s) invalid" % (action, type(action))
        #rkbeam_vec, delta_p = action[:self.K], action[self.K][0]
        #rkbeam_vec = action[:]
        #tbeam_vec = [self.TB_r]
        #changing only receiver beam based on the action

        #prev_ue = self.cur_ue
        #self.cur_ue[0] += self.ue_v + delta_p
        #prev_obs = self.obs[:]
        #prev_obs[0] += delta_p
        self.ue_s[0] += self.ue_v #+ delta_p
        self.obs[1] = np.array(action)
        self.obs[0] = np.array(self.ue_s)
        #self.TB_r = get_TBD(self.ue_s, self.alpha)
        #RIM = self.Compute_RIM(prev_obs, kbeam_vec)
        #rssi_gnb1 = RIM[:self.K]
        #best_rssi_val = np.max(rssi_gnb1)
        #print('[RF_Env] UE_S: ', self.ue_s)

        self.mimo_model = MIMO(self.ue_s, self.gNB[0], self.sc_xyz, self.ch_model, self.ptx, self.N_tx, self.N_rx)

        self.SNR, self.rate = self.mimo_model.Calc_Rate(self.SF_time, np.array([self.obs[1][0], 0]))#rkbeam_vec, tbeam_vec )
        #print("[RF_Env] SNR: {0}, rate: {1}".format(20*np.log10(self.SNR), self.rate))

        #self.mimo_los_model = MIMO(self.ue_s, self.gNB[0], self.ptx, self.N_tx, self.N_rx)

        #print("[RF_Env] Los_SNR: {0}, Los_rate: {1}".format(20 * np.log10(self.Los_SNR), self.Los_rate))
        #self.mimo_los_model = MIMO(self.obs, self.gNB[0], self.ptx, self.N_tx, self.N_rx)
        #self.Los_SNR, self.LoS_rate = self.mimo_los_model.Los_Rate(SF_time, self.K)
        #print("[RF_Env] pos_corr: {0}, Rate: {1}".format(delta_p,self.rate))


        self.cum_rate += self.rate

        #self.Los_rate = self.get_LoS_Rate(self.ue_s)
        #self.cum_Los_rate += self.Los_rate

        self.count += 1
        rwd = self.Reward()
        done = self.Game_Over()


        #self.obs[0] += self.ue_v
        #done = self.Game_Over()
        #self.cur_ue = prev_ue
        return self.obs, rwd, done
Esempio n. 9
0
    def get_Exh_Rate(self, state):
        dist, ue_ang, rbd = (state*self.high_obs)
        ue_pos = np.array(sph2cart(ue_ang, 0, dist))  # ue_pos is(x,y)

        mimo_exh_model = MIMO(ue_pos, self.gNB[0], self.sc_xyz, self.ch_model, self.ptx, self.N_tx, self.N_rx)
        #rbeam_vec = self.BeamSet#Generate_BeamDir(self.N)
        exh_SNR = []
        exh_rates = []

        for rbeam in self.BeamSet:#rbeam_vec:
            SNR, rate = mimo_exh_model.Calc_Rate(self.SF_time, np.array([rbeam, 0]))
            exh_SNR.append(SNR)
            exh_rates.append(rate)

        best_rbeam_ndx = np.argmax(exh_rates)
        return self.BeamSet[best_rbeam_ndx], np.max(exh_rates) #(Best RBS, Best Rate)
Esempio n. 10
0
    def get_Exh_Rate(self, ue_s):
        #print("[RF_Env] obs: {0}".format(self.obs))
        #print("[RF_Env] TB_r: {0}".format(self.TB_r))
        self.mimo_exh_model = MIMO(ue_s, self.gNB[0], self.sc_xyz, self.ch_model, self.ptx, self.N_tx, self.N_rx)
        #print("[Env]: exh h: {0}".format(self.mimo_exh_model.channel.pathloss))
        rbeam_vec = Generate_BeamDir(self.N)
        tbeam_vec = Generate_BeamDir(self.N)
        exh_SNR = []
        exh_rates=[]

        for rbeam in rbeam_vec:
            SNR, rate = self.mimo_exh_model.Calc_Rate(self.SF_time, np.array([rbeam[0], 0]))
            exh_SNR.append(SNR)
            exh_rates.append(rate)

        best_rbeam_ndx = np.argmax(exh_rates)
        return rbeam_vec[best_rbeam_ndx], np.max(exh_rates)
Esempio n. 11
0
    def step(self, action):
        assert self.act_space.contains(
            action), "%r (%s) invalid" % (action, type(action))

        state = np.rint(self.state * self.high_obs)
        rbd_ndx, ue_mv_ndx = self.decode_action(action)
        ue_vx, ue_vy = self.choose_vel(ue_mv_ndx)
        rbs = self.BeamSet[rbd_ndx]
        ue_xdest = self.ue_xdest[0]
        ue_ydest = self.ue_ydest[0]
        ue_xloc, ue_yloc = state

        self.cur_dist = np.sqrt(
            (ue_xloc - ue_xdest)**2 + (ue_yloc - ue_ydest)**2)  # x**2 + y**2
        self.cur_state = state

        if self.done:  #reached terminal state
            return self.state, self.rwd, self.done, {}

        ue_mv = self.ue_moves[ue_mv_ndx]
        if ue_mv == 'L':
            new_ue_xloc = max(ue_xloc + ue_vx, np.min(self.ue_xloc))
            new_ue_yloc = ue_yloc + ue_vy
        if ue_mv == 'U':
            new_ue_xloc = ue_xloc + ue_vx
            new_ue_yloc = min(ue_yloc + ue_vy, np.max(self.ue_yloc))
        if ue_mv == 'R':
            new_ue_xloc = min(ue_xloc + ue_vx, np.max(self.ue_xloc))
            new_ue_yloc = ue_yloc + ue_vy
        if ue_mv == 'D':
            new_ue_xloc = ue_xloc + ue_vx
            new_ue_yloc = max(ue_yloc + ue_vy, np.min(self.ue_yloc))

        new_ue_pos = np.array([new_ue_xloc, new_ue_yloc, 0])

        #Approximating (0,0) to (20,20) location to prevent rate->Inf
        if (new_ue_xloc == 0) and (new_ue_yloc == 0):
            self.mimo_model = MIMO(np.array([40, 40, 0]), self.gNB[0],
                                   self.sc_xyz, self.ch_model, self.ptx,
                                   self.N_tx, self.N_rx)
            self.SNR, self.rate = self.mimo_model.Calc_Rate(
                self.SF_time, np.array([rbs, 0]))  # rkbeam_vec, tbeam_vec )

        else:
            self.mimo_model = MIMO(new_ue_pos, self.gNB[0], self.sc_xyz,
                                   self.ch_model, self.ptx, self.N_tx,
                                   self.N_rx)
            self.SNR, self.rate = self.mimo_model.Calc_Rate(
                self.SF_time, np.array([rbs, 0]))  # rkbeam_vec, tbeam_vec )

        if self.measure == 'rate_thr_path':
            self.rwd, self.done = self._gameover()
        elif self.measure == 'rate_path':
            self.rwd, self.done = self.rate_path_gameover()
        elif self.measure == 'short_path':
            self.rwd, self.done = self.short_path_gameover()
        else:
            print("Err: Incorrect measure str\n")
            self.rwd, self.done = -100.0, True

        self.ue_path_rates.append(self.rate)
        self.ue_path.append(np.array([new_ue_xloc, new_ue_yloc]))

        self.cur_rate = self.rate
        self.prev_dist = self.cur_dist
        self.state = np.array([new_ue_xloc, new_ue_yloc]) / self.high_obs

        self.steps_done += 1

        return self.state, self.rwd, self.done, {}