示例#1
0
    def display_cars(self, cars):

        car_lines = []

        for n in range(0, len(cars)):
            car_lines.append(random.choice(self.road))

        for n in range(0, len(self.totalRoads)):

            road = self.road[n]
            line_data = road.get_data()

            x_min, x_max = self.lineX(line_data)
            y_min, y_max = self.lineY(line_data)

            locX = (x_max - x_min) / 2 + x_min
            locY = (y_max - y_min) / 2 + y_min

            plot.plotLineTxt(locX, locY, n + 1)

        # temporal variable to hold values of cars
        points = [[], []]

        # get X cars in the graph
        for n in range(0, len(cars)):

            random_index = randrange(0, len(car_lines))
            self.currentRoad[cars[n]] = random_index
            car_line = car_lines[random_index]
            point = car_line.get_xydata()[0]  # first point in the graph

            # calculate the angle
            line_data = car_line.get_data()
            ang = self.calculateAngle(line_data)

            self.cars[cars[n]] = self.carProperties(point, ang, x_min, x_max)

            # for the even cars shift angle to negative
            # so that it goes in opposite direction from car1
            i = self.cars.keys().index(cars[n])
            if i % 2 == 0:
                ang = ang + math.pi
                point = car_line.get_xydata()[-1]  # for this car get the last point as positions

            x_min, x_max = self.lineX(line_data)

            self.initial[cars[n]] = self.carPoint(point)

            # add scatter
            points[0].append(point[0])
            points[1].append(point[1])

            self.speed(cars[n])  # Get Speed

            # Useful to Graph
            plot.instantiateCircle(cars[n])
            plot.instantiateAnnotate(cars[n])

        # plot the cars
        self.scatter = plot.plotScatter(points[0], points[1])
示例#2
0
    def display_cars(self, cars):
    
        car_lines = []
        
        for n in range(0,len(cars)):
            car_lines.append(random.choice(self.road))
        
        for n in range(0, len(self.totalRoads)):
            
            road = self.road[n]            
            line_data = road.get_data()
            
            x_min, x_max = self.lineX(line_data)
            y_min, y_max = self.lineY(line_data)

            locX = (x_max - x_min)/2 + x_min
            locY = (y_max - y_min)/2 + y_min
            
            plot.plotLineTxt(locX, locY, n+1)
            
        #temporal variable to hold values of cars
        points = [[],[]]
        
        #get X cars in the graph
        for n in range(0,len(cars)):
            
            random_index = randrange(0,len(car_lines))            
            self.currentRoad[cars[n]] = random_index            
            car_line = car_lines[random_index]
            point = car_line.get_xydata()[0] #first point in the graph
            
            #calculate the angle
            line_data = car_line.get_data()            
            ang = self.calculateAngle(line_data)
            
            self.cars[cars[n]] = self.carProperties(point, ang, x_min, x_max)
            
            #for the even cars shift angle to negative
            #so that it goes in opposite direction from car1
            i = self.cars.keys().index(cars[n])
            if i%2==0:
                ang = ang + math.pi
                point = car_line.get_xydata()[-1] #for this car get the last point as positions
    
            x_min, x_max = self.lineX(line_data)
            
            self.initial[cars[n]] = self.carPoint(point)
             
            #add scatter
            points[0].append(point[0])
            points[1].append(point[1])
                        
            self.speed(cars[n]) # Get Speed
            
            #Useful to Graph
            plot.instantiateCircle(cars[n])
            plot.instantiateAnnotate(cars[n])
            
        #plot the cars
        self.scatter = plot.plotScatter(points[0],points[1])
示例#3
0
def instantiateGraph():
    nodeList = mobility.staList + mobility.apList
    for node in nodeList:
        plot.instantiateGraph(mobility.MAX_X, mobility.MAX_Y)
        plot.instantiateNode(node, mobility.MAX_X, mobility.MAX_Y)
        plot.instantiateAnnotate(node)
        plot.instantiateCircle(node)
        plot.graphUpdate(node)
def instantiateGraph():
        nodeList = mobility.staList + mobility.apList
        for node in nodeList:
            plot.instantiateGraph(mobility.MAX_X, mobility.MAX_Y)
            plot.instantiateNode(node, mobility.MAX_X, mobility.MAX_Y)
            plot.instantiateAnnotate(node)
            plot.instantiateCircle(node)
            plot.graphUpdate(node)
示例#5
0
    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()
示例#6
0
 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()
示例#7
0
 def instatiateNodes(self, node):
     plot.instantiateAnnotate(node)
     plot.instantiateCircle(node)
     plot.instantiateNode(node, self.MAX_X, self.MAX_Y)
     plot.graphUpdate(node)  
示例#8
0
 def graphInstantiateNodes(self, node):
     plot.instantiateAnnotate(node)
     plot.instantiateCircle(node)
     plot.instantiateNode(node, self.MAX_X, self.MAX_Y)
     plot.graphUpdate(node)