def display_grid(self, aps, conn, nroads): for n in range(nroads): if n == 0: p = ginp(2) self.points[n] = p self.all_points = p else: p = ginp(1) self.points[n] = p self.all_points.append(p[0]) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] if n == 0: # Get all the points in the line self.points[n] = self.get_line(int(x1[0]), int(y1[0]), int(x1[1]), int(y1[1])) else: self.points[n] = self.get_line(int(self.all_points[n][0]), int(self.all_points[n][1]), int(p[0][0]), int(p[0][1])) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] self.interX[n] = x1 self.interY[n] = y1 # Create a line object with the x y values of the points in a line self.roads[n] = plot2d.line2d(x1, y1, color='g') plot2d.line(self.roads[n]) for bs in aps: bs.prop = ginp(1)[0] bs_x = round(bs.prop[0], 2) bs_y = round(bs.prop[1], 2) self.scatter = plot2d.scatter(float(bs_x), float(bs_y)) bs.params['position'] = bs_x, bs_y, 0 bs.set_pos_wmediumd(bs.params['position']) plot2d.instantiateNode(bs) plot2d.instantiateAnnotate(bs) plot2d.instantiateCircle(bs) plot2d.text(bs, float(bs_x), float(bs_y)) plot2d.circle(bs, float(bs_x), float(bs_y)) plot2d.draw() sleep(1) if 'src' in conn: for c in range(len(conn['src'])): line = plot2d.line2d([ conn['src'][c].params['position'][0], conn['dst'][c].params['position'][0] ], [ conn['src'][c].params['position'][1], conn['dst'][c].params['position'][1] ], 'b', ls='dashed') plot2d.line(line)
def display_grid(self, baseStations, connections, nroads): for n in range(nroads): if n == 0: p = ginp(2) self.points[n] = p self.all_points = p else: p = ginp(1) self.points[n] = p self.all_points.append(p[0]) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] if n == 0: # Get all the points in the line self.points[n] = self.get_line(int(x1[0]), int(y1[0]), int(x1[1]), int(y1[1])) else: self.points[n] = self.get_line(int(self.all_points[n][0]), int(self.all_points[n][1]), int(p[0][0]), int(p[0][1])) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] self.interX[n] = x1 self.interY[n] = y1 # Create a line object with the x y values of the points in a line self.road[n] = plot2d.plotLine2d(x1, y1, color='g') plot2d.plotLine(self.road[n]) for bs in baseStations: bs.properties = ginp(1)[0] bs_x = '%.2f' % bs.properties[0] bs_y = '%.2f' % bs.properties[1] self.scatter = plot2d.plotScatter(bs_x, bs_y) bs.params['position'] = bs_x, bs_y, 0 bs.set_position_wmediumd() plot2d.instantiateNode(bs) plot2d.instantiateAnnotate(bs) plot2d.instantiateCircle(bs) plot2d.text(bs) plot2d.circle(bs) plot2d.plotDraw() sleep(1) if 'src' in connections: for c in range(0, len(connections['src'])): line = plot2d.plotLine2d([connections['src'][c].params['position'][0], connections['dst'][c].params['position'][0]], \ [connections['src'][c].params['position'][1], connections['dst'][c].params['position'][1]], 'b', ls='dashed') plot2d.plotLine(line)
def display_grid(self, aps, conn, nroads): for n in range(nroads): if n == 0: p = ginp(2) self.points[n] = p self.all_points = p else: p = ginp(1) self.points[n] = p self.all_points.append(p[0]) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] if n == 0: # Get all the points in the line self.points[n] = self.get_line(int(x1[0]), int(y1[0]), int(x1[1]), int(y1[1])) else: self.points[n] = self.get_line(int(self.all_points[n][0]), int(self.all_points[n][1]), int(p[0][0]), int(p[0][1])) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] self.interX[n] = x1 self.interY[n] = y1 # Create a line object with the x y values of the points in a line self.roads[n] = plot2d.line2d(x1, y1, color='g') plot2d.line(self.roads[n]) for bs in aps: bs.prop = ginp(1)[0] bs_x = '%.2f' % bs.prop[0] bs_y = '%.2f' % bs.prop[1] self.scatter = plot2d.scatter(float(bs_x), float(bs_y)) bs.params['position'] = bs_x, bs_y, 0 bs.set_pos_wmediumd(bs.params['position']) plot2d.instantiateNode(bs) plot2d.instantiateAnnotate(bs) plot2d.instantiateCircle(bs) plot2d.text(bs, float(bs_x), float(bs_y)) plot2d.circle(bs, float(bs_x), float(bs_y)) plot2d.draw() sleep(1) if 'src' in conn: for c in range(len(conn['src'])): line = plot2d.line2d([conn['src'][c].params['position'][0], conn['dst'][c].params['position'][0]], \ [conn['src'][c].params['position'][1], conn['dst'][c].params['position'][1]], 'b', ls='dashed') plot2d.line(line)
def display_grid(self, baseStations, srcConn, dstConn, nroads): for n in range(nroads): if n == 0: p = ginp(2) self.points[n] = p self.all_points = p else: p = ginp(1) self.points[n] = p self.all_points.append(p[0]) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] if n == 0: self.points[n] = self.get_line( int(x1[0]), int(y1[0]), int(x1[1]), int(y1[1])) # Get all the points in the line else: self.points[n] = self.get_line( int(self.all_points[n][0]), int(self.all_points[n][1]), int(p[0][0]), int(p[0][1])) # Get all the points in the line x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] self.interX[n] = x1 self.interY[n] = y1 self.road[n] = plot2d.plotLine2d( x1, y1, color='g' ) # Create a line object with the x y values of the points in a line plot2d.plotLine(self.road[n]) for bs in baseStations: bs.properties = ginp(1)[0] bs_x = bs.properties[0] bs_y = bs.properties[1] self.scatter = plot2d.plotScatter(bs_x, bs_y) bs.params['position'] = bs_x, bs_y, 0 plot2d.instantiateAnnotate(bs) plot2d.instantiateCircle(bs) plot2d.text(bs) plot2d.circle(bs) plot2d.plotDraw() for c in range(0, len(srcConn)): line = plot2d.plotLine2d([srcConn[c].params['position'][0], dstConn[c].params['position'][0]], \ [srcConn[c].params['position'][1], dstConn[c].params['position'][1]], 'b', ls='dashed') plot2d.plotLine(line)
def display_grid(self, baseStations, nroads): for n in range(0, nroads): if n == 0: p = ginp(2) self.points[n] = p self.all_points = p else: p = ginp(1) self.points[n] = p self.all_points.append(p[0]) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] if n == 0: self.points[n] = self.get_line( int(x1[0]), int(y1[0]), int(x1[1]), int(y1[1])) # Get all the points in the line else: self.points[n] = self.get_line( int(self.all_points[n][0]), int(self.all_points[n][1]), int(p[0][0]), int(p[0][1])) # Get all the points in the line x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] self.interX[n] = x1 self.interY[n] = y1 self.road[n] = plot.plotLine2d( x1, y1, color='g' ) # Create a line object with the x y values of the points in a line plot.plotLine(self.road[n]) #plot.plotDraw() for i in range(len(baseStations)): self.bss[baseStations[i]] = ginp(1)[0] bs_x = self.bss[baseStations[i]][0] bs_y = self.bss[baseStations[i]][1] self.scatter = plot.plotScatter(bs_x, bs_y) baseStations[i].params['position'] = bs_x, bs_y, 0 plot.instantiateAnnotate(baseStations[i]) plot.instantiateCircle(baseStations[i]) plot.drawTxt(baseStations[i]) plot.drawCircle(baseStations[i]) plot.plotDraw()
def display_grid(self, links, roads, **kwargs): for n in range(roads): if n == 0: p = ginp(2) self.points[n] = p self.all_points = p else: p = ginp(1) self.points[n] = p self.all_points.append(p[0]) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] if n == 0: # Get all the points in the line self.points[n] = self.get_line(int(x1[0]), int(y1[0]), int(x1[1]), int(y1[1])) else: self.points[n] = self.get_line(int(self.all_points[n][0]), int(self.all_points[n][1]), int(p[0][0]), int(p[0][1])) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] self.interX[n] = x1 self.interY[n] = y1 # Create a line object with the x y values of the points in a line self.roads[n] = Plot2D.line2d(x1, y1, color='g') Plot2D.line(self.roads[n]) for bs in kwargs['aps']: bs.prop = ginp(1)[0] bs_x = round(bs.prop[0], 2) bs_y = round(bs.prop[1], 2) self.scatter = Plot2D.scatter(float(bs_x), float(bs_y)) bs.position = bs_x, bs_y, 0 bs.set_pos_wmediumd(bs.position) Plot2D.instantiate_attrs(bs) bs.draw_text(float(bs_x), float(bs_y)) bs.set_circle_center(float(bs_x), float(bs_y)) Plot2D.draw() sleep(1) Plot2D.create_line(links)
def display_grid(self, baseStations, nroads): for n in range(0, nroads): if n == 0: p = ginp(2) self.points[n] = p self.all_points = p else: p = ginp(1) self.points[n] = p self.all_points.append(p[0]) x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] if n == 0: self.points[n] = self.get_line(int(x1[0]),int(y1[0]),int(x1[1]),int(y1[1])) # Get all the points in the line else: self.points[n] = self.get_line(int(self.all_points[n][0]),int(self.all_points[n][1]),int(p[0][0]),int(p[0][1])) # Get all the points in the line x1 = [x[0] for x in self.points[n]] y1 = [x[1] for x in self.points[n]] self.interX[n] = x1 self.interY[n] = y1 self.road[n] = plot.plotLine2d(x1,y1, color='g') # Create a line object with the x y values of the points in a line plot.plotLine(self.road[n]) #plot.plotDraw() for i in range(len(baseStations)): self.bss[baseStations[i]] = ginp(1)[0] bs_x = self.bss[baseStations[i]][0] bs_y = self.bss[baseStations[i]][1] self.scatter = plot.plotScatter(bs_x, bs_y) baseStations[i].params['position'] = bs_x, bs_y, 0 plot.instantiateAnnotate(baseStations[i]) plot.instantiateCircle(baseStations[i]) plot.drawTxt(baseStations[i]) plot.drawCircle(baseStations[i]) plot.plotDraw()
def display_grid(): #define global variables global all_points global all_lines global road_legend #get the first 2 points and draw the 1st line and plot it global line1 points1 = ginp(2) # get the 2 end points of the first line all_points = points1 x1 = [x[0] for x in points1] y1 = [x[1] for x in points1] points1 = get_line(int(x1[0]), int(y1[0]), int(x1[1]), int(y1[1])) # Get all the points in the line x1 = [x[0] for x in points1] y1 = [x[1] for x in points1] line1 = plt.Line2D( x1, y1) # Create a line object with the x y values of the points in a line plt.gca().add_line(line1) plt.draw() #get the 3rd point and plot the 2nd line global line2 points2 = ginp(1) all_points.append(points2[0]) # get the 3rd point points2 = get_line(int(all_points[1][0]), int(all_points[1][1]), int(points2[0][0]), int(points2[0][1])) # Get all the points in the line x2 = [x[0] for x in points2] y2 = [x[1] for x in points2] line2 = plt.Line2D( x2, y2) # Create a line object with the x y values of the points in a line plt.gca().add_line(line2) plt.draw() #get the 4th point and plot the 3rd line global line3 points3 = ginp(1) all_points.append(points3[0]) # get the 4th point points3 = get_line(int(all_points[2][0]), int(all_points[2][1]), int(points3[0][0]), int(points3[0][1])) # Get all the points in the line x3 = [x[0] for x in points3] y3 = [x[1] for x in points3] line3 = plt.Line2D( x3, y3) # Create a line object with the x y values of the points in a line plt.gca().add_line(line3) plt.draw() #get the 5th point and plot the 4th line global line4 points4 = ginp(1) all_points.append(points4[0]) # get the 5th point points4 = get_line(int(all_points[3][0]), int(all_points[3][1]), int(points4[0][0]), int(points4[0][1])) # Get all the points in the line x4 = [x[0] for x in points4] y4 = [x[1] for x in points4] line4 = plt.Line2D( x4, y4, label='road' ) # Create a line object with the x y values of the points in a line road_legend = line4.get_label() plt.gca().add_line(line4) plt.draw() all_lines = [line1, line2, line3, line4] # List of all points in all the lines #get the rsu positions for i in range(number_of_rsus): rsus.append(ginp(1)[0]) # create a list of rsu positions rsu_x = rsus[i][0] # x position of rsu rsu_y = rsus[i][1] # y position of rsu scatter = plt.scatter(rsu_x, rsu_y, label='RSU') # Plot the rsu on the grid plt.annotate(rsu_legend, xy=(rsu_x, rsu_y), xytext=(rsu_x - 50, rsu_y + 30)) # label the rsu plt.draw()
def display_grid(): #define global variables global all_points global all_lines global road_legend #get the first 2 points and draw the 1st line and plot it global line1 points1 = ginp(2) # get the 2 end points of the first line all_points = points1 x1= [x[0] for x in points1] y1=[x[1] for x in points1] points1 = get_line(int(x1[0]),int(y1[0]),int(x1[1]),int(y1[1])) # Get all the points in the line x1= [x[0] for x in points1] y1=[x[1] for x in points1] line1 = plt.Line2D(x1,y1) # Create a line object with the x y values of the points in a line plt.gca().add_line(line1) plt.draw() #get the 3rd point and plot the 2nd line global line2 points2 = ginp(1) all_points.append(points2[0]) # get the 3rd point points2 = get_line(int(all_points[1][0]),int(all_points[1][1]),int(points2[0][0]),int(points2[0][1])) # Get all the points in the line x2= [x[0] for x in points2] y2= [x[1] for x in points2] line2 = plt.Line2D(x2,y2) # Create a line object with the x y values of the points in a line plt.gca().add_line(line2) plt.draw() #get the 4th point and plot the 3rd line global line3 points3 = ginp(1) all_points.append(points3[0]) # get the 4th point points3 = get_line(int(all_points[2][0]),int(all_points[2][1]),int(points3[0][0]),int(points3[0][1])) # Get all the points in the line x3= [x[0] for x in points3] y3= [x[1] for x in points3] line3 = plt.Line2D(x3,y3) # Create a line object with the x y values of the points in a line plt.gca().add_line(line3) plt.draw() #get the 5th point and plot the 4th line global line4 points4 = ginp(1) all_points.append(points4[0]) # get the 5th point points4 = get_line(int(all_points[3][0]),int(all_points[3][1]),int(points4[0][0]),int(points4[0][1])) # Get all the points in the line x4= [x[0] for x in points4] y4= [x[1] for x in points4] line4 = plt.Line2D(x4,y4,label='road') # Create a line object with the x y values of the points in a line road_legend = line4.get_label() plt.gca().add_line(line4) plt.draw() all_lines = [line1, line2, line3, line4] # List of all points in all the lines #get the rsu positions for i in range(number_of_rsus): rsus.append(ginp(1)[0]) # create a list of rsu positions rsu_x = rsus[i][0] # x position of rsu rsu_y = rsus[i][1] # y position of rsu scatter = plt.scatter(rsu_x, rsu_y,label = 'RSU') # Plot the rsu on the grid plt.annotate(rsu_legend, xy=(rsu_x,rsu_y), xytext = (rsu_x-50, rsu_y+30)) # label the rsu plt.draw()