def reset(self): self.num_steps = 0 for device in self.simulator.devices.values(): if device.id == BASE_STATION_ID: pos = Position( 0, 0 ) # assume MBS fixed at (0,0) and everything else builds around it elif device.id in self.config.devices: pos = Position(*self.config.devices[device.id]['position']) elif any(device.id in d for d in [self.devices.cues, self.devices.due_pairs]): pos = get_random_position(self.config.cell_radius_m) elif device.id in self.devices.due_pairs_inv: due_tx_id = self.devices.due_pairs_inv[device.id] due_tx = self.simulator.devices[due_tx_id] pos = get_random_position_nearby(self.config.cell_radius_m, due_tx.position, self.config.d2d_radius_m) else: raise ValueError( f'Invalid configuration for device "{device.id}".') device.set_position(pos) self.simulator.reset() # take a step with random D2D actions to generate initial SINRs random_actions = { due_id: self._extract_action(due_id, self.action_space.sample()) for due_id in self.devices.due_pairs.keys() } results = self.simulator.step(random_actions) obs = self.obs_fn.get_state(results) return obs
def test_call(self): pl = LogDistancePathLoss(2.1) bs = BaseStation('bs') ue = UserEquipment('ue') ue.set_position(Position(250, 0)) assert pl(ue, bs) == approx(86.85097) ue.set_position(Position(0, 500)) assert pl(ue, bs) == approx(92.87156)
def test_call(self): pl = CostHataPathLoss(2.1, AreaType.URBAN) bs = BaseStation('bs') ue = UserEquipment('ue') ue.set_position(Position(250, 0)) assert pl(bs, ue) == approx(121.44557455875727) assert pl(ue, bs) == approx(114.35415557446962) ue.set_position(Position(0, 500)) assert pl(bs, ue) == approx(132.2768393081241) assert pl(ue, bs) == approx(127.5231950610599)
def test_distance(self): for _ in range(NUM_TEST_REPEATS): a_x, a_y = random.uniform(0, 500), random.uniform(0, 500) b_x, b_y = random.uniform(0, 500), random.uniform(0, 500) pos_a = Position(a_x, a_y) pos_b = Position(b_x, b_y) dist = sqrt((a_x - b_x)**2 + (a_y - b_y)**2) assert dist >= 0.0 assert dist == approx(pos_a.distance(pos_b)) assert dist == approx(pos_b.distance(pos_a))
def test_set_position(self): ue = UserEquipment('ue') ue.set_position(Position(-123.45, 78.9)) assert ue.position.as_tuple() == (-123.45, 78.9)
def test_as_tuple(self): x, y = random.uniform(0, 500), random.uniform(0, 500) pos = Position(x, y) assert pos.as_tuple() == (x, y)