Esempio n. 1
0
 def returnSumOfThroughput(self, bsnumber, step):
     ue = devices.UE()
     sumOfInternalThroughput = 0
     internalBS = 0
     sumOfExternalThroughput = 0
     externalBS = 0
     for x in range(0, round(self.constraintAreaMaxX), step):
         for y in range(0, round(self.constraintAreaMaxY), step):
             ue.x = x
             ue.y = y
             ue.connectToNearestBS(self.bs)
             if ue.connectedToBS == bsnumber:
                 #if ue.distanceToBS(self.bs[bsnumber]) < self.bs[bsnumber].mi * self.bs[bsnumber].Rc:
                 if ue.inside:
                     sumOfInternalThroughput = sumOfInternalThroughput + ue.calculateMaxThroughputOfTheNode(
                         self.bs)
                     internalBS = internalBS + 1
                 else:
                     sumOfExternalThroughput = sumOfExternalThroughput + ue.calculateMaxThroughputOfTheNode(
                         self.bs)
                     externalBS = externalBS + 1
     if externalBS != 0:
         sumOfExternalThroughput = sumOfExternalThroughput / externalBS
     if internalBS != 0:
         sumOfInternalThroughput = sumOfInternalThroughput / internalBS
     sumOfThroughput = sumOfExternalThroughput + sumOfInternalThroughput
     return sumOfThroughput
 def insertUErandomly(self, numberOfDevices):
     number = 0
     for i in range(0, numberOfDevices):
         ue = devices.UE()
         ue.ID = number
         ue.x = random.uniform(0, self.parent.constraintAreaMaxX)
         ue.y = random.uniform(0, self.parent.constraintAreaMaxY)
         self.parent.ue.append(ue)
         number = number+1
 def insertUEingrid(self, numberOfDevices):
     numberOfNodesInRow = math.ceil(math.sqrt(numberOfDevices))
     number = 0
     x_step = int(self.parent.constraintAreaMaxX)/numberOfNodesInRow
     y_step = int(self.parent.constraintAreaMaxY)/numberOfNodesInRow
     for x_pos in range(0, numberOfNodesInRow):
         for y_pos in range(0, numberOfNodesInRow):
             ue = devices.UE()
             ue.ID = number
             ue.x = 0.5*x_step + (x_pos*x_step)
             ue.y = 0.5*y_step + (y_pos*y_step)
             self.parent.ue.append(ue)
             number = number+1
Esempio n. 4
0
 def insertUEingroup(self, numberOfDevices, percentSpace):
     number = 0
     center_x = 0.5 + random.uniform(-(0.5 - percentSpace / 200),
                                     (0.5 - percentSpace / 200))
     center_y = 0.5 + random.uniform(-(0.5 - percentSpace / 200),
                                     (0.5 - percentSpace / 200))
     print("percentSpace = ", percentSpace)
     print("center_x = ", center_x)
     print("center_y = ", center_y)
     for i in range(0, numberOfDevices):
         ue = devices.UE()
         ue.ID = number
         min_x = (center_x -
                  percentSpace / 200) * self.parent.constraintAreaMaxX
         max_x = (center_x +
                  percentSpace / 200) * self.parent.constraintAreaMaxX
         min_y = (center_y -
                  percentSpace / 200) * self.parent.constraintAreaMaxY
         max_y = (center_y +
                  percentSpace / 200) * self.parent.constraintAreaMaxY
         ue.x = random.uniform(min_x, max_x)
         ue.y = random.uniform(min_y, max_y)
         self.parent.ue.append(ue)
         number = number + 1
Esempio n. 5
0
    def loadNodesFromKMLFile(self, filename, numberOfDevices):

        ppk = PointPolygonKML(self)
        xyp = ppk.generatePointsFromKML(filename, numberOfDevices)

        lat_min = 999
        long_min = 999

        for row in xyp:
            if row.x < long_min: long_min = row.x
            if row.y < lat_min: lat_min = row.y

        R = 6371e3
        number = 0
        max_x = 0
        max_y = 0

        for row in xyp:
            fi1 = math.radians(row.y)
            fi2 = math.radians(lat_min)
            deltafi = math.radians(row.y - lat_min)
            deltalambda = math.radians(row.x - long_min)

            a = math.sin(deltafi / 2.0) * math.sin(
                deltafi / 2.0) + math.cos(fi1) * math.cos(fi2) * math.sin(
                    deltalambda / 2.0) * math.sin(deltalambda / 2.0)
            c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
            d = R * c

            fi1 = math.radians(row.y)
            fi2 = math.radians(lat_min)
            deltafi = math.radians(row.y - lat_min)
            deltalambda = math.radians(row.x - row.x)

            a = math.sin(deltafi / 2.0) * math.sin(
                deltafi / 2.0) + math.cos(fi1) * math.cos(fi2) * math.sin(
                    deltalambda / 2.0) * math.sin(deltalambda / 2.0)
            c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
            y = R * c

            fi1 = math.radians(row.y)
            fi2 = math.radians(row.y)
            deltafi = math.radians(row.y - lat_min)
            deltalambda = math.radians(row.x - long_min)

            a = math.sin(deltafi / 2.0) * math.sin(
                deltafi / 2.0) + math.cos(fi1) * math.cos(fi2) * math.sin(
                    deltalambda / 2.0) * math.sin(deltalambda / 2.0)
            c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
            x = R * c

            if type(self.parent) is network.LoRaNetwork:
                ue = devices.Node(self.parent)
            else:
                ue = devices.UE(self.parent)

            if max_x < x: max_x = x
            if max_y < y: max_y = y
            print("gen", number, x, y, row.x, row.y)
            ue.x = x
            ue.y = y
            ue.lat = row.y
            ue.long = row.x
            ue.height = 15
            ue.ID = number
            self.parent.ue.append(ue)
            number = number + 1
        # print(len(self.parent.ue), "wspolrzednych dodane, teraz kubelki")
        # print("lat", lat, "long", long, "d", round(d,2), "x", round(x,2), "y", round(y,2))
        self.parent.constraintAreaMaxX = int(max_x + 0.05 * max_x)
        self.parent.constraintAreaMaxY = int(max_y + 0.05 * max_y)

        for ue in self.parent.ue:
            self.addToBucket(ue.ID, ue.x, ue.y)
Esempio n. 6
0
    def loadNodesFromFile(self, filename):
        # print("Jestem w loadNodesFromFile")
        file = open(filename)
        file.readline()
        networkcsv = csv.reader(file, delimiter=';')
        lat_min = 999
        long_min = 999
        for row in networkcsv:
            if len(row) == 5:
                lat = float(row[1].replace(',', '.'))
                long = float(row[2].replace(',', '.'))
                if int(lat) == 0 or int(long) != 0:
                    if lat < lat_min: lat_min = lat
                    if long < long_min: long_min = long
        file.seek(0)
        file.readline()
        # print(lat_min, long_min)
        # print("min maks znaleziony")
        R = 6371e3
        number = 0
        max_x = 0
        max_y = 0
        for row in networkcsv:
            if len(row) == 5:
                lat = float(row[1].replace(',', '.'))
                long = float(row[2].replace(',', '.'))
                height = float(row[3].replace(',', '.'))
                dtype = int(row[4])
                if int(lat) == 0 or int(long) != 0:
                    fi1 = math.radians(lat)
                    fi2 = math.radians(lat_min)
                    deltafi = math.radians(lat - lat_min)
                    deltalambda = math.radians(long - long_min)

                    a = math.sin(deltafi / 2.0) * math.sin(
                        deltafi /
                        2.0) + math.cos(fi1) * math.cos(fi2) * math.sin(
                            deltalambda / 2.0) * math.sin(deltalambda / 2.0)
                    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
                    d = R * c

                    fi1 = math.radians(lat)
                    fi2 = math.radians(lat_min)
                    deltafi = math.radians(lat - lat_min)
                    deltalambda = math.radians(long - long)

                    a = math.sin(deltafi / 2.0) * math.sin(
                        deltafi /
                        2.0) + math.cos(fi1) * math.cos(fi2) * math.sin(
                            deltalambda / 2.0) * math.sin(deltalambda / 2.0)
                    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
                    y = R * c

                    fi1 = math.radians(lat)
                    fi2 = math.radians(lat)
                    deltafi = math.radians(lat - lat_min)
                    deltalambda = math.radians(long - long_min)

                    a = math.sin(deltafi / 2.0) * math.sin(
                        deltafi /
                        2.0) + math.cos(fi1) * math.cos(fi2) * math.sin(
                            deltalambda / 2.0) * math.sin(deltalambda / 2.0)
                    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
                    x = R * c

                    if type(self.parent) is network.LoRaNetwork:
                        ue = devices.Node(self.parent)
                    else:
                        ue = devices.UE(self.parent)

                    if max_x < x: max_x = x
                    if max_y < y: max_y = y

                    ue.x = x
                    ue.y = y
                    ue.lat = lat
                    ue.long = long
                    ue.height = height
                    ue.type = dtype
                    ue.ID = number
                    self.parent.ue.append(ue)
                    number = number + 1
        # print(len(self.parent.ue), "wspolrzednych dodane, teraz kubelki")
        # print("lat", lat, "long", long, "d", round(d,2), "x", round(x,2), "y", round(y,2))
        self.parent.constraintAreaMaxX = int(max_x + 0.05 * max_x)
        self.parent.constraintAreaMaxY = int(max_y + 0.05 * max_y)

        # print("X", self.parent.constraintAreaMaxX / 1000, "Y", self.parent.constraintAreaMaxY / 1000)
        for ue in self.parent.ue:
            # None
            self.addToBucket(ue.ID, ue.x, ue.y)
        # print("kubelki dodane")
        file.close()
Esempio n. 7
0
    def drawNetwork(self,
                    filename,
                    BS=True,
                    UE=True,
                    links=True,
                    obstacles=True,
                    fillMethod="SINR",
                    colorMap=None,
                    drawLegend=True,
                    tilesInLine=100,
                    figSize=(8, 8),
                    colorMinValue=None,
                    colorMaxValue=None,
                    outputFileFormat=["png"]):
        main_draw = plt.figure(1, figsize=figSize)
        ax = main_draw.add_subplot(111)
        if fillMethod == "SINR":
            if colorMap == None:
                cm = plt.cm.get_cmap("viridis")
            else:
                cm = plt.cm.get_cmap(colorMap)
            ue = devices.UE()
            imageMatrix = np.zeros((tilesInLine, tilesInLine))
            d_x = round(self.parent.constraintAreaMaxX / tilesInLine)
            d_y = round(self.parent.constraintAreaMaxY / tilesInLine)
            for x in range(0, tilesInLine):
                for y in range(0, tilesInLine):
                    ue.x = x * d_x
                    ue.y = y * d_y
                    ue.connectToTheBestBS(self.parent.bs,
                                          self.parent.obstacles)
                    SINR = ue.calculateSINR(self.parent.bs,
                                            self.parent.obstacles)
                    imageMatrix[y][x] = SINR
            if colorMinValue != None:
                colorMin = colorMinValue
            else:
                colorMin = imageMatrix.min()
            if colorMaxValue != None:
                colorMax = colorMaxValue
            else:
                colorMax = imageMatrix.max()
            image = plt.imshow(imageMatrix,
                               vmin=colorMin,
                               vmax=colorMax,
                               origin='lower',
                               extent=[
                                   0, self.parent.constraintAreaMaxX, 0,
                                   self.parent.constraintAreaMaxY
                               ],
                               interpolation='nearest',
                               cmap=cm)
            if drawLegend == True:
                from mpl_toolkits.axes_grid1 import make_axes_locatable
                divider = make_axes_locatable(ax)
                cax1 = divider.append_axes("right", size="5%", pad=0.05)
                cbar = plt.colorbar(image, cax=cax1)
                #cbar.set_clim(-60, 50)
                #cbar.ax.set_yticklabels(['0','1','2','>3'])
                #cbar.set_label('# of contacts', rotation=270)

        elif fillMethod == "Sectors":
            if colorMap == None:
                cm = plt.cm.get_cmap("Paired")
            else:
                cm = plt.cm.get_cmap(colorMap)
            ue = devices.UE()
            imageMatrix = np.zeros((tilesInLine, tilesInLine))
            d_x = round(self.parent.constraintAreaMaxX / tilesInLine)
            d_y = round(self.parent.constraintAreaMaxY / tilesInLine)
            for x in range(0, tilesInLine):
                for y in range(0, tilesInLine):
                    RSSI_best = -1000
                    BS_best = -1
                    for bs in self.parent.bs:
                        ue.x = x * d_x
                        ue.y = y * d_y
                        if ue.isSeenFromBS(bs) == False:
                            continue
                        ue.connectedToBS = bs.ID
                        temp_RSSI = ue.calculateSINR(self.parent.bs)
                        if temp_RSSI > RSSI_best:
                            RSSI_best = temp_RSSI
                            BS_best = bs.ID

                    imageMatrix[y][x] = BS_best
            plt.imshow(imageMatrix,
                       origin='lower',
                       extent=[
                           0, self.parent.constraintAreaMaxX, 0,
                           self.parent.constraintAreaMaxY
                       ],
                       interpolation='nearest',
                       cmap=cm)

        if BS == True:
            bs_x_locations = []
            bs_y_locations = []
            for bs in self.parent.bs:
                bs_x_locations.append(bs.x)
                bs_y_locations.append(bs.y)
            ax.plot(bs_x_locations,
                    bs_y_locations,
                    'r^',
                    color="black",
                    markersize=10)

        if UE == True:
            ue_x_locations = []
            ue_y_locations = []
            for ue in self.parent.ue:
                ue_x_locations.append(ue.x)
                ue_y_locations.append(ue.y)
            ax.plot(ue_x_locations,
                    ue_y_locations,
                    'b*',
                    color="black",
                    markersize=10)

        if links == True:
            for ue in self.parent.ue:
                ax.arrow(ue.x, ue.y, self.parent.bs[ue.connectedToBS].x - ue.x,
                         self.parent.bs[ue.connectedToBS].y - ue.y)

        if obstacles == True:
            for obstacle in self.parent.obstacles:
                ax.arrow(obstacle[0], obstacle[1], obstacle[2] - obstacle[0],
                         obstacle[3] - obstacle[1])

        networkBorder = plt.Rectangle((0, 0),
                                      self.parent.constraintAreaMaxX,
                                      self.parent.constraintAreaMaxY,
                                      color='black',
                                      fill=False)
        ax.add_patch(networkBorder)
        ax.axis('equal')

        ax.axis([
            0, self.parent.constraintAreaMaxX, 0,
            self.parent.constraintAreaMaxY
        ])
        ax.axis('off')
        ax.xaxis.set_visible(False)
        ax.yaxis.set_visible(False)
        for outputFormat in outputFileFormat:
            if outputFormat == "png":
                main_draw.savefig(filename + ".png",
                                  format="png",
                                  dpi=300,
                                  bbox_inches='tight')
            if outputFormat == "pdf":
                main_draw.savefig(filename + ".pdf",
                                  format="pdf",
                                  dpi=300,
                                  bbox_inches='tight')

        plt.clf()
Esempio n. 8
0
 def insertUE(self, xPos, yPos, ueNum):
     ue = devices.UE()
     ue.ID = ueNum
     ue.x = xPos
     ue.y = yPos
     self.parent.ue.append(ue)
Esempio n. 9
0
    def drawNetwork(self, filename, BS=True, UE=True, links=True, obstacles=True, fillMethod="SINR", colorMap = 'viridis', drawLegend=True, tilesInLine = 100, figSize = (8, 8), colorMinValue = None, colorMaxValue = None, outputFileFormat = ["png"], forceRedraw = False):
        main_draw = plt.figure(1, figsize=figSize)
        ax = main_draw.add_subplot(111)
        
        cm = plt.cm.get_cmap(colorMap)
        ue = devices.UE()
        # check if tilesInLine changed
        if (forceRedraw == True):
            self.imageMatrixValid = False

        if (self.tilesInLine != tilesInLine):
            self.tilesInLine = tilesInLine
            self.imageMatrixValid = False 
            
        if (self.fillMethod != fillMethod):
            self.fillMethod = fillMethod
            self.imageMatrixValid = False
        
        # If this is the fist time, or if something changed
        if(self.imageMatrixValid == False):
            self.imageMatrix = np.zeros((tilesInLine, tilesInLine))
            d_x = self.parent.constraintAreaMaxX/tilesInLine
            d_y = self.parent.constraintAreaMaxY/tilesInLine

            for x in range(0, tilesInLine):
                for y in range(0, tilesInLine):
                    ue.x = round(x * d_x)
                    ue.y = round(y * d_y)
                    if fillMethod == "SINR":
                        ue.connectToTheBestBS(self.parent.bs, self.parent.obstacles)
                        SINR, RSSI = ue.calculateSINR(self.parent.bs, self.parent.obstacles)
                        self.imageMatrix[y][x] = SINR
                    if fillMethod == "RSSI":
                        ue.connectToTheBestBS(self.parent.bs, self.parent.obstacles)
                        SINR, RSSI = ue.calculateSINR(self.parent.bs, self.parent.obstacles)
                        self.imageMatrix[y][x] = RSSI
                    if fillMethod == "Sectors":
                        SINR_best = -1000
                        BS_best = -1
                        for bs in self.parent.bs:
                            ue.connectedToBS = bs.ID
                            temp_SINR, RSSI = ue.calculateSINR(self.parent.bs, self.parent.obstacles)
                            if (temp_SINR > SINR_best) and (RSSI > -120):
                                SINR_best = temp_SINR
                                BS_best = bs.ID
                        self.imageMatrix[y][x] = BS_best
            self.imageMatrixValid = True

        if colorMinValue != None:
            colorMin = colorMinValue
        else:
            colorMin = self.imageMatrix.min()
        if colorMaxValue != None:
            colorMax = colorMaxValue
        else:
            colorMax = self.imageMatrix.max()
        image = plt.imshow(self.imageMatrix, vmin=colorMin, vmax=colorMax, origin='lower', extent=[0, self.parent.constraintAreaMaxX, 0, self.parent.constraintAreaMaxY], interpolation='nearest', cmap=cm)
        
        if drawLegend == True:
            from mpl_toolkits.axes_grid1 import make_axes_locatable
            divider = make_axes_locatable(ax)
            cax1 = divider.append_axes("right", size="5%", pad=0.05)
            cbar = plt.colorbar(image, cax = cax1)
            cbar.set_clim(-40, 40) #end

        if BS == True:
            bs_x_locations = []
            bs_y_locations = []
            bs_ID = []
            bs_angle = []
            bs_count = 0
            for bs in self.parent.bs:
                bs_x_locations.append(bs.x)
                bs_y_locations.append(bs.y)
                bs_ID.append(bs.ID)
                bs_angle.append(bs.angle)
                bs_count+=1
            ax.plot(bs_x_locations, bs_y_locations, 'r^', color="red", markersize=10)
            for i in range(0,bs_count):
                offsetAngle = math.radians(bs_angle[i])
                distance = (self.parent.constraintAreaMaxX + self.parent.constraintAreaMaxY) / 50
                z = distance*complex(math.sin(offsetAngle), -math.cos(offsetAngle))
                ax.annotate(bs_ID[i], xy=(bs_x_locations[i],bs_y_locations[i]), xytext=(bs_x_locations[i]+z.real, bs_y_locations[i]+z.imag), color='red')
                        
        if UE == True:
            for ue in self.parent.ue:
                ax.annotate(ue.ID, xy=(ue.x, ue.y), xytext=(ue.x, ue.y), color='black')

        if links == True:
            for ue in self.parent.ue:
                ax.arrow(ue.x, ue.y, self.parent.bs[ue.connectedToBS].x - ue.x, self.parent.bs[ue.connectedToBS].y - ue.y)

        if obstacles == True:
            for obstacle in self.parent.obstacles:
                ax.arrow(obstacle[0], obstacle[1], obstacle[2] - obstacle[0], obstacle[3] - obstacle[1], width=10, color="red")

        networkBorder = plt.Rectangle((0,0), self.parent.constraintAreaMaxX, self.parent.constraintAreaMaxY, color='black', fill=False)
        ax.add_patch(networkBorder)
        ax.axis('equal')

        ax.axis([0, self.parent.constraintAreaMaxX, 0, self.parent.constraintAreaMaxY])
        ax.axis('off')
        ax.xaxis.set_visible(False)
        ax.yaxis.set_visible(False)
        for outputFormat in outputFileFormat:
            if outputFormat == "png":
                main_draw.savefig(filename+".png", format="png", dpi=300, bbox_inches='tight')
            if outputFormat == "pdf":
                main_draw.savefig(filename+".pdf", format="pdf", dpi=300, bbox_inches='tight')