def obtain_sigma(self, n, k): if (self.type == Antenna.RRH_ID): #RRH macro = self.near_macro(self._grid.bs_list) dMue = util.dist(macro, self.connected_ues[n]) #distancia rrh to user dMn = 31.5 + 35.0 * math.log10(dMue) #pathloss hRnk = 1 #channel gain hMnk = 1 #channel gain Pm = self.PMmax #pmax b0 = self.B0 #bandwidth N0 = util.sinr( self.p[n][k], self.i[n][k], util.noise() ) # estimated power spectrum density of both the sum of noise and weak inter-RRH interference (in dBm/Hz) dRue = util.dist(self, self.connected_ues[n] ) #distancia rrh to user#distancia rrh to user dRn = 31.5 + 40.0 * math.log10(dRue) return (dRn * hRnk) / (Pm * dMn * hMnk + b0 * N0) else: #MACRO dMue = util.dist(self, self.connected_ues[n]) #distancia rrh to user dMn = 31.5 + 35.0 * math.log10(dMue) #pathloss hMnk = 1 #channel gain b0 = self.B0 #bandwidth N0 = util.sinr( self.p[n][k], self.i[n][k], util.noise() ) # estimated power spectrum density of both the sum of noise and weak inter-RRH interference (in dBm/Hz) #print dMn, hMnk, b0, N0 return (dMn * hMnk) / (b0 * N0)
def transmission_power(antenna, user, interferece): R = util.dist(user, antenna) if (antenna.type == antenna.BS_ID): p = p_friis(antenna, interferece, util.noise(), threeGPP.HPN_T_GAIN, threeGPP.UE_R_GAIN, R, threeGPP.WAVELENTH) #dBm else: p = p_friis(antenna, interferece, util.noise(), threeGPP.LPN_T_GAIN, threeGPP.UE_R_GAIN, R, threeGPP.WAVELENTH) #dBm return p
def arrow(draw, bbox, thickness=3, fill=(0, 255, 0), arrlen=50, arrang=0.5): x1, y1, x2, y2 = bbox xc, yc = x1 + (x2 - x1) / 2, y1 + (y2 - y1) / 2 bbox_pt = rand_bbox_point(bbox) theta = angle((xc, yc), bbox_pt) head = point(bbox_pt, theta, 20) tail = point(bbox_pt, theta, 20 + arrlen) draw.line([head, tail], fill=fill, width=thickness) for ang in [arrang + theta, -arrang + theta]: arrwing = point(head, ang, 20) arrwing = (arrwing[0] + noise(10), arrwing[1] + noise(10)) draw.line([head, arrwing], fill=fill, width=thickness)
def rand_rb(self, particle, antenna, ue, grid): roulette = numpy.zeros(shape=(threeGPP.TOTAL_RBS)) accumulated = 0 probMinimum = 1 for rb in range(0, threeGPP.TOTAL_RBS-1): i = calc.power_interference(ue, rb, antenna, grid, particle) power = calc.transmission_power(antenna, antenna.connected_ues[ue], i) data = (util.shannon(threeGPP.B0, util.sinr(power, i, util.noise()))) #print "power", power prob = (data/1048576)/util.dBm_to_watts(power) #print prob if prob > probMinimum: accumulated = accumulated + prob else: accumulated = accumulated + probMinimum roulette[rb] = accumulated playmove = random.randint(0, int(accumulated)) for rb in range(0, threeGPP.TOTAL_RBS-1): if playmove < roulette[rb]: return rb return rb ############################################ #### end-refactor ############################################
def datarate(antenna, particle=0): antenna.datarate[particle] = 0 antenna.meet_users[particle] = 0 antenna.datarate_constraint[particle] = 0 if antenna.connected_ues != None: antenna.user_datarate[particle] = numpy.zeros( shape=(len(antenna.connected_ues))) for n in range(0, len(antenna.connected_ues)): for k in range(0, threeGPP.TOTAL_RBS): data_bits = (util.shannon( (antenna.a[particle][n][k] * threeGPP.B0), util.sinr( antenna.p[particle][n][k], antenna.i[particle][n][k], util.noise()))) / 2000 #Qnt de bits em 0,5 ms antenna.datarate[particle] += data_bits antenna.user_datarate[particle][n] += data_bits if antenna.connected_ues[n]._type == antenna.connected_ues[ n].HIGH_RATE_USER: if (antenna.user_datarate[particle, n] < threeGPP.NER): antenna.datarate_constraint[particle] += ( antenna.user_datarate[particle, n] - threeGPP.NR) else: antenna.meet_users[particle] += 1 else: if (antenna.user_datarate[particle, n] < threeGPP.NER): antenna.datarate_constraint[particle] += ( antenna.user_datarate[particle, n] - threeGPP.NER) else: antenna.meet_users[particle] += 1
def power_calc(self, arb, user, particle, grid): antenna_index = int(arb/Antenna.TOTAL_RBS) antenna = grid.antennas[antenna_index] ue = grid.users[user] R = util.dist(ue, antenna) p = util.p_friis(antenna,self.i_particles[particle, user, arb], util.noise(), Antenna.T_GAIN, Antenna.R_GAIN, R, Antenna.WAVELENTH) #dBm return p
def circle(draw, bbox, thickness=4, loops=2, fill=(255, 0, 0)): """draw a 'handdrawn' ellipse around a bounding box""" offset = 0 x1, y1, x2, y2 = bbox w, h = x2 - x1, y2 - y1 x_c, y_c = x1 + w / 2, y1 + h / 2 rot = noise(0.6) a, b = w, h for loop in range(loops): for r in np.arange(0, 2 * pi + random.random(), 1 / (max(w, h))): offset += noise() for i in range(thickness): x, y = ellipse_pt(r, x_c, y_c, a + i + offset, b + i + offset, rot) draw.point((x, y), fill=fill) a, b = a + 1, b + 1
def layout(images, canvas, shakiness=0): """compute image layout; this doesn't guarantee that every image will be included! this resizes overflowing images to fit. """ to_place = [] ims = [im.im for im in images] packed = pack(ims, canvas) for img, pos in zip(images, packed): pos = (round(pos[0] + util.noise(shakiness)), round(pos[1] + util.noise(shakiness))) if pos[0] + img.size[0] > config.SIZE[ 0] or pos[1] + img.size[1] > config.SIZE[1]: # compute overflow new_size = (config.SIZE[0] - pos[0], config.SIZE[1] - pos[1]) img.resize_to_limit(new_size) to_place.append((img, pos)) return to_place
def underline_and_crop_bbox(img, bbox, margin=(140, 60), shakiness=8): draw = ImageDraw.Draw(img) bx1, by1, bx2, by2 = bbox x1 = bx1 + noise(shakiness) y1 = by2 + noise(shakiness) x2 = bx2 + noise(shakiness) y2 = by2 + noise(shakiness) link(draw, (x1, y1), (x2, y2)) cx1 = round(bx1 - margin[0] + noise(shakiness)) cy1 = round(by1 - margin[1] + noise(shakiness)) cx2 = round(bx2 + margin[0] + noise(shakiness)) cy2 = round(by2 + margin[1] + noise(shakiness)) # trim to fit return img.crop((cx1, cy1, cx2, cy2)).copy()
def link(draw, frm, to, thickness=4, shakiness=0.4, fill=(255, 0, 0)): """draw a 'handdrawn' line connecting two points""" offset = 0 eps = 0.0001 x_1, y_1 = frm x_2, y_2 = to m = (y_2 - y_1) / (x_2 - x_1 + eps) b = y_1 - (m * x_1) for x in np.arange(x_1, x_2, 0.05): offset += noise(shakiness) for i in range(thickness): y = m * x + b if m < 0.1: y += i x_ = x else: x_ = x + i + offset draw.point((x_, y), fill=fill)
def rand_user(self, particle, antenna_index, antenna, arb, covered_users, prob_zero, grid): #prob_zero = 0 databitsPerUser = numpy.zeros(shape=(len(antenna.connected_ues))) totalUes = len(antenna.connected_ues) #for ue in range (covered_users+1, totalUes): # self.datarate_user_particles[particle, ue] = 0 #for rb in range(0, Antenna.TOTAL_RBS):# Loop de K * M para preencher A #arb = (antenna_index*Antenna.TOTAL_RBS-1)+rb #user = numpy.argmax(self.a_particles[particle, :, arb]) #if self.a_particles[particle, user, arb] > 0: #data_bits = (util.shannon((self.a_particles[particle, user, arb] * Antenna.B0), util.sinr(self.p_particles[particle, user, arb], self.i_particles[particle, user, arb], util.noise())))/2000#Qnt de bits em 0,5 ms #self.datarate_user_particles[particle, user] += data_bits #covered_users = self.covered_users_calc(grid.antennas, antenna_index) probPerUser = numpy.ones(shape=(len(antenna.connected_ues))) sum_prob = 0 #print "Covered_users", covered_users, for ue in range(0, len(antenna.connected_ues)): user = ue + covered_users + 1 self.i_particles[particle, user, arb] = self.interference_calc(arb, user, particle, grid) self.p_particles[particle, user, arb] = self.power_calc(arb, user, particle, grid) probPerUser[ue] = sum_prob + (util.shannon((1 * Antenna.B0), util.sinr(self.p_particles[particle, user, arb], self.i_particles[particle, user, arb], util.noise())))/2000#Qnt de bits em 0,5 ms # if grid.users[user]._type == User.HIGH_RATE_USER: # if(self.datarate_user_particles[particle, user] < Antenna.NR): # probPerUser[ue] = sum_prob + (Antenna.NR - self.datarate_user_particles[particle, user]) # else: # if(self.datarate_user_particles[particle, user] < Antenna.NER): # probPerUser[ue] = sum_prob + (Antenna.NER - self.datarate_user_particles[particle, user]) sum_prob = probPerUser[ue] rand = random.randint(int(covered_users-prob_zero), int(covered_users+sum_prob)) if rand > covered_users: for ue in range (0, totalUes): if rand <= probPerUser[ue]: #print "return", ue return covered_users + 1 + ue else: #print "return", rand return rand
def data_rate_and_power_consumption_calc(self, particle, grid): self.datarate_user_particles[particle] = numpy.zeros(shape=(len(grid.users))) self.consumption_antenna_particles[particle] = numpy.zeros(shape=(len(grid.antennas))) datarate_particle = 0 consumption_particle = 0 previous_antennas = 0 previous_consumption = 0 for arb in range(0, Antenna.TOTAL_RBS*len(grid.antennas)):# Loop de K * M para preencher A antenna_index = int(arb/Antenna.TOTAL_RBS) antenna = grid.antennas[antenna_index]# Identifica antena user = numpy.argmax(self.a_particles[particle, :, arb]) if self.a_particles[particle, user, arb] > 0: #DATA RATE data_bits = (util.shannon((self.a_particles[particle, user, arb] * Antenna.B0), util.sinr(self.p_particles[particle, user, arb], self.i_particles[particle, user, arb], util.noise())))/2000#Qnt de bits em 0,5 ms self.datarate_user_particles[particle, user] += data_bits #print "Data User: ", str(numpy.matrix(self.datarate_user_particles[particle])) datarate_particle += data_bits previous_consumption += util.dBm_to_watts(self.a_particles[particle, user, arb] * self.p_particles[particle, user, arb]) #POWER CONSUMPTION next_arb_antenna = int((arb+1)/Antenna.TOTAL_RBS) if next_arb_antenna > antenna_index or arb == (Antenna.TOTAL_RBS*len(grid.antennas))-1: if (antenna.type == Antenna.BS_ID): self.consumption_antenna_particles[particle, antenna_index] = (Antenna.MEFF * previous_consumption) + Antenna.PMC + Antenna.PMBH else: self.consumption_antenna_particles[particle, antenna_index] = (Antenna.EFF * previous_consumption) + Antenna.PMC + Antenna.PMBH consumption_particle += self.consumption_antenna_particles[particle, antenna_index] previous_consumption = 0 self.datarate_particles[particle] = self.list_append(self.datarate_particles[particle], datarate_particle) self.consumption_particles[particle] = self.list_append(self.consumption_particles[particle], consumption_particle)