def simulate_car_movement(self, scatter, com_lines): # temporal variables points = [[], []] scatter.remove() nodes = dict(self.cars.items() + self.bss.items()) # print initial while com_lines: com_lines[0].remove() del(com_lines[0]) # iterate over each car for car in self.cars: # get all the properties of the car velocity = round(np.random.uniform(self.velo[car][0], self.velo[car][1])) position_x = self.cars[car][0] position_y = self.cars[car][1] car.params['position'] = position_x, position_y, 0 angle = self.cars[car][2] # calculate new position of the car position_x = position_x + velocity * cos(angle) * self.time_per_iteraiton position_y = position_y + velocity * sin(angle) * self.time_per_iteraiton # check if car gets out of the line # no need to check for y coordinates as car follows the line if position_x < self.cars[car][3] or position_x > self.cars[car][4]: self.repeat(car) points[0].append(self.initial[car][0]) points[1].append(self.initial[car][1]) else: self.cars[car][0] = position_x self.cars[car][1] = position_y points[0].append(position_x) points[1].append(position_y) for node in nodes: if nodes[node] == nodes[car]: continue else: # compute to see if vehicle is in range inside = math.pow((nodes[node][0] - position_x), 2) + math.pow((nodes[node][1] - position_y), 2) if inside <= math.pow(node.params['range'] + 30, 2): line = plot.plotLine2d([position_x, nodes[node][0]], [position_y, nodes[node][1]], color='r') com_lines.append(line) plot.plotLine(line) plot.drawTxt(car) plot.drawCircle(car) scatter = plot.plotScatter(points[0], points[1]) plot.plotDraw() return [scatter, com_lines]
def simulate_car_movement(self,scatter,com_lines): #temporal variables points= [[],[]] scatter.remove() nodes = dict(self.cars.items() + self.bss.items()) #print initial while com_lines: com_lines[0].remove() del(com_lines[0]) #iterate over each car for car in self.cars: #get all the properties of the car velocity = round(np.random.uniform(self.velo[car][0],self.velo[car][1])) position_x = self.cars[car][0] position_y = self.cars[car][1] car.params['position'] = position_x, position_y, 0 angle = self.cars[car][2] #calculate new position of the car position_x = position_x + velocity*cos(angle)*self.time_per_iteraiton position_y = position_y + velocity*sin(angle)*self.time_per_iteraiton #check if car gets out of the line # no need to check for y coordinates as car follows the line if position_x < self.cars[car][3] or position_x> self.cars[car][4]: self.repeat(car) points[0].append(self.initial[car][0]) points[1].append(self.initial[car][1]) else: self.cars[car][0] = position_x self.cars[car][1] = position_y points[0].append(position_x) points[1].append(position_y) for node in nodes: if nodes[node] == nodes[car]: continue else: #compute to see if vehicle is in range inside = math.pow((nodes[node][0]-position_x),2) + math.pow((nodes[node][1]-position_y),2) if inside <= math.pow(node.range+30,2): line = plot.plotLine2d([position_x,nodes[node][0]],[position_y,nodes[node][1]], color='r') com_lines.append(line) plot.plotLine(line) plot.drawTxt(car) plot.drawCircle(car) scatter = plot.plotScatter(points[0],points[1]) plot.plotDraw() return [scatter,com_lines]
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 mobilityPositionDefined(self, initial_time, final_time, staMov): """ ongoing Mobility """ t_end = time.time() + final_time t_initial = time.time() + initial_time currentTime = time.time() i = 1 if self.DRAW == True: debug('Enabling Graph...\n') plot.instantiateGraph(self.MAX_X, self.MAX_Y) for sta in self.staList: self.graphInstantiateNodes(sta) if sta not in staMov: plot.pltNode[sta].set_data(sta.params['position'][0], sta.params['position'][1]) plot.drawTxt(sta) plot.drawCircle(sta) for ap in mobility.apList: self.graphInstantiateNodes(ap) for c in ap.connections: line = plot.plotLine2d([ap.connections[c].params['position'][0], ap.params['position'][0]], \ [ap.connections[c].params['position'][1], ap.params['position'][1]], 'b') plot.plotLine(line) for wall in mobility.wallList: line = plot.plotLine2d([wall.params['initPos'][0], wall.params['finalPos'][0]], \ [wall.params['initPos'][1], wall.params['finalPos'][1]], 'r', 10) plot.plotLine(line) try: while time.time() < t_end and time.time() > t_initial: if self.continue_: if time.time() - currentTime >= i: for sta in staMov: if time.time() - currentTime >= sta.startTime and time.time() - currentTime <= sta.endTime: x = float(sta.params['position'][0]) + float(self.moveFac[sta][0]) y = float(sta.params['position'][1]) + float(self.moveFac[sta][1]) z = float(sta.params['position'][2]) + float(self.moveFac[sta][2]) sta.params['position'] = x, y, z for wlan in range(0, len(sta.params['wlan'])): self.nodeParameter(sta, wlan) if self.DRAW: plot.graphPause() plot.graphUpdate(sta) i+=1 # have to verify this time.sleep(0.01) except: print 'Error! Mobility stopped!'
def mobilityPositionDefined(self, initial_time, final_time, staMov): """ ongoing Mobility """ t_end = time.time() + final_time t_initial = time.time() + initial_time currentTime = time.time() i=1 if self.DRAW == True: debug('Enabling Graph...\n') plot.instantiateGraph(self.MAX_X, self.MAX_Y) for sta in self.staList: self.graphInstantiateNodes(sta) if sta not in staMov: plot.pltNode[sta].set_data(sta.params['position'][0],sta.params['position'][1]) plot.drawTxt(sta) plot.drawCircle(sta) for ap in mobility.apList: self.graphInstantiateNodes(ap) for c in ap.connections: line = plot.plotLine2d([ap.connections[c].params['position'][0],ap.params['position'][0]], \ [ap.connections[c].params['position'][1],ap.params['position'][1]], 'b') plot.plotLine(line) for wall in mobility.wallList: line = plot.plotLine2d([wall.params['initPos'][0],wall.params['finalPos'][0]], \ [wall.params['initPos'][1],wall.params['finalPos'][1]], 'r', 10) plot.plotLine(line) try: while time.time() < t_end and time.time() > t_initial: if self.continue_: if time.time() - currentTime >= i: for sta in staMov: if time.time() - currentTime >= sta.startTime and time.time() - currentTime <= sta.endTime: x = float(sta.params['position'][0]) + float(self.moveFac[sta][0]) y = float(sta.params['position'][1]) + float(self.moveFac[sta][1]) z = float(sta.params['position'][2]) + float(self.moveFac[sta][2]) sta.params['position'] = x, y, z for wlan in range(0, len(sta.params['wlan'])): self.nodeParameter(sta, wlan) if self.DRAW: time.sleep(0.01) plot.graphUpdate(sta) i+=1 #have to verify this time.sleep(0.01) except: print 'Error! Mobility stopped!'
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 mobilityPositionDefined(self, initial_time, final_time, staMov): """ ongoing Mobility """ t_end = time.time() + final_time t_initial = time.time() + initial_time currentTime = time.time() i=1 if emulationEnvironment.DRAW == True: debug('Enabling Graph...\n') plot.instantiateGraph(self.MAX_X, self.MAX_Y) for sta in emulationEnvironment.staList: self.instatiateNodes(sta) if sta not in staMov: plot.pltNode[sta].set_data(sta.position[0],sta.position[1]) plot.drawTxt(sta) plot.drawCircle(sta) for ap in emulationEnvironment.apList: self.instatiateNodes(ap) for c in ap.connections: line = plot.plotLine2d([ap.connections[c].position[0],ap.position[0]], \ [ap.connections[c].position[1],ap.position[1]], 'b') plot.plotLine(line) try: while time.time() < t_end and time.time() > t_initial: if emulationEnvironment.continue_: if time.time() - currentTime >= i: for sta in emulationEnvironment.staList: if time.time() - currentTime >= sta.startTime and time.time() - currentTime <= sta.endTime: sta.position[0] = float(sta.position[0]) + float(self.moveFac[sta][0]) sta.position[1] = float(sta.position[1]) + float(self.moveFac[sta][1]) sta.position[2] = float(sta.position[2]) + float(self.moveFac[sta][2]) for wlan in range(0, sta.nWlans): self.nodeParameter(sta, wlan) if emulationEnvironment.DRAW: plot.graphUpdate(sta) i+=1 except: print 'Error! Mobility stopped!'
def models(self, nodes=None, model=None, min_v=0, max_v=0, seed=None, staMov=None, **mobilityparam): np.random.seed(seed) # simulation area (units) MAX_X, MAX_Y = self.MAX_X, self.MAX_Y dic = dict() dic['max_x'] = MAX_X dic['max_y'] = MAX_Y # max waiting time MAX_WT = 100. for node in nodes: if node.max_x == 0: node.max_x = MAX_X if node.max_y == 0: node.max_y = MAX_Y if node.max_v == 0: node.max_v = max_v if node.min_v == 0: node.min_v = min_v debug('Setting the mobility model %s' % model) if (model == 'RandomWalk'): # Random Walk model mob = random_walk(staMov) elif (model == 'TruncatedLevyWalk'): # Truncated Levy Walk model mob = truncated_levy_walk(staMov) elif (model == 'RandomDirection'): # Random Direction model mob = random_direction(staMov, dimensions=(MAX_X, MAX_Y)) elif (model == 'RandomWayPoint'): # Random Waypoint model mob = random_waypoint(staMov, wt_max=MAX_WT) elif (model == 'GaussMarkov'): # Gauss-Markov model mob = gauss_markov(staMov, alpha=0.99) elif (model == 'ReferencePoint'): # Reference Point Group model mob = reference_point_group(staMov, dimensions=(MAX_X, MAX_Y), aggregation=0.5) elif (model == 'TimeVariantCommunity' ): # Time-variant Community Mobility Model mob = tvc(staMov, dimensions=(MAX_X, MAX_Y), aggregation=[0.5, 0.], epoch=[100, 100]) else: raise Exception("Model not defined!") if self.DRAW: plot.instantiateGraph(self.MAX_X, self.MAX_Y) plot.plotGraph(nodes, mobility.wallList, staMov, **dic) for xy in mob: i = 0 for n in range(0, len(nodes)): node = nodes[n] if node in staMov: if 'station' == node.type: node.params['position'] = xy[i][0], xy[i][1], 0 i += 1 if self.DRAW: plot.pltNode[node].set_data(xy[:, 0], xy[:, 1]) plot.drawTxt(node) plot.drawCircle(node) if self.DRAW: plot.graphUpdate(node) plot.graphPause()
def models(self, model=None, staMov=None, min_v=0, max_v=0, seed=None, stations=None, aps=None, dstConn=None, srcConn=None, walls=None, plotNodes=None, MAX_X=0, MAX_Y=0): np.random.seed(seed) self.staList = stations self.apList = aps self.wallList = walls nodes = self.staList + self.apList + plotNodes dic = dict() dic['max_x'] = MAX_X dic['max_y'] = MAX_Y # max waiting time MAX_WT = 100. for sta in self.staList: if sta.max_x == 0: sta.max_x = MAX_X if sta.max_y == 0: sta.max_y = MAX_Y if sta.max_v == 0: sta.max_v = max_v if sta.min_v == 0: sta.min_v = min_v debug('Configuring the mobility model %s' % model) if (model == 'RandomWalk'): # Random Walk model mob = random_walk(staMov) elif (model == 'TruncatedLevyWalk'): # Truncated Levy Walk model mob = truncated_levy_walk(staMov) elif (model == 'RandomDirection'): # Random Direction model mob = random_direction(staMov, dimensions=(MAX_X, MAX_Y)) elif (model == 'RandomWayPoint'): # Random Waypoint model mob = random_waypoint(staMov, wt_max=MAX_WT) elif (model == 'GaussMarkov'): # Gauss-Markov model mob = gauss_markov(staMov, alpha=0.99) elif (model == 'ReferencePoint'): # Reference Point Group model mob = reference_point_group(staMov, dimensions=(MAX_X, MAX_Y), aggregation=0.5) elif (model == 'TimeVariantCommunity' ): # Time-variant Community Mobility Model mob = tvc(staMov, dimensions=(MAX_X, MAX_Y), aggregation=[0.5, 0.], epoch=[100, 100]) else: raise Exception("Model not defined!") if self.DRAW: plot.instantiateGraph(MAX_X, MAX_Y) plot.plotGraph(nodes, self.wallList, staMov, srcConn, dstConn, **dic) for xy in mob: i = 0 for node in staMov: node.params['position'] = xy[i][0], xy[i][1], 0 i += 1 if self.DRAW: plot.pltNode[node].set_data(xy[:, 0], xy[:, 1]) plot.drawTxt(node) plot.drawCircle(node) if self.DRAW: plot.graphUpdate(node) plot.graphPause()
def models(self, nodes=None, model=None, max_x=None, max_y=None, min_v=None, max_v=None, seed=None, staMov=None, **mobilityparam): self.modelName = model np.random.seed(seed) # number of nodes nr_nodes = len(staMov) # simulation area (units) MAX_X, MAX_Y = max_x, max_y # max and min velocity MIN_V, MAX_V = min_v, max_v # max waiting time MAX_WT = 100. if(self.modelName=='RandomWalk'): ## Random Walk model mob = random_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) elif(self.modelName=='TruncatedLevyWalk'): ## Truncated Levy Walk model mob = truncated_levy_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) elif(self.modelName=='RandomDirection'): ## Random Direction model mob = random_direction(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V)) elif(self.modelName=='RandomWayPoint'): ## Random Waypoint model mob = random_waypoint(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V), wt_max=MAX_WT) elif(self.modelName=='GaussMarkov'): ## Gauss-Markov model mob = gauss_markov(nr_nodes, dimensions=(MAX_X, MAX_Y), alpha=0.99) elif(self.modelName=='ReferencePoint'): ## Reference Point Group model mob = reference_point_group(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=0.5) elif(self.modelName=='TimeVariantCommunity'): ## Time-variant Community Mobility Model mob = tvc(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=[0.5,0.], epoch=[100,100]) else: print 'Model not defined!' if emulationEnvironment.DRAW: debug('Enabling Graph...\n') plot.instantiateGraph(self.MAX_X, self.MAX_Y) for node in nodes: self.instatiateNodes(node) if node not in staMov or 'accessPoint' == node.type: plot.pltNode[node].set_data(node.position[0],node.position[1]) plot.drawTxt(node) plot.drawCircle(node) if node.type == 'accessPoint': for c in node.connections: line = plot.plotLine2d([node.connections[c].position[0],node.position[0]], \ [node.connections[c].position[1],node.position[1]], 'b') plot.plotLine(line) #Sometimes getting the error: Failed to connect to generic netlink. try: if model!='': for xy in mob: i = 0 for n in range (0,len(nodes)): node = nodes[n] if node in staMov: if 'station' == node.type: node.position = xy[i][0], xy[i][1], 0 i += 1 if emulationEnvironment.DRAW: plot.pltNode[node].set_data(xy[:,0],xy[:,1]) plot.drawTxt(node) plot.drawCircle(node) #self.parameters() if emulationEnvironment.DRAW: plt.title("Mininet-WiFi Graph") plt.draw() except: pass
def models(self, nodes=None, model=None, min_v=None, max_v=None, seed=None, staMov=None, **mobilityparam): np.random.seed(seed) # simulation area (units) MAX_X, MAX_Y = self.MAX_X, self.MAX_Y # max waiting time MAX_WT = 100. for node in nodes: if node.max_x == 0: node.max_x = MAX_X if node.max_y == 0: node.max_y = MAX_Y if node.max_v == 0: node.max_v = max_v if node.min_v == 0: node.min_v = min_v debug('Chossing the mobility model %s' % model) if(model == 'RandomWalk'): # Random Walk model mob = random_walk(staMov) elif(model == 'TruncatedLevyWalk'): # Truncated Levy Walk model mob = truncated_levy_walk(staMov) elif(model == 'RandomDirection'): # Random Direction model mob = random_direction(staMov, dimensions=(MAX_X, MAX_Y)) elif(model == 'RandomWayPoint'): # Random Waypoint model mob = random_waypoint(staMov, wt_max=MAX_WT) elif(model == 'GaussMarkov'): # Gauss-Markov model mob = gauss_markov(staMov, alpha=0.99) elif(model == 'ReferencePoint'): # Reference Point Group model mob = reference_point_group(staMov, dimensions=(MAX_X, MAX_Y), aggregation=0.5) elif(model == 'TimeVariantCommunity'): # Time-variant Community Mobility Model mob = tvc(staMov, dimensions=(MAX_X, MAX_Y), aggregation=[0.5, 0.], epoch=[100, 100]) else: raise Exception("'Model not defined!") if self.DRAW: debug('Enabling Graph...\n') plot.instantiateGraph(self.MAX_X, self.MAX_Y) for node in nodes: self.graphInstantiateNodes(node) if node not in staMov or 'accessPoint' == node.type: plot.pltNode[node].set_data(node.params['position'][0], node.params['position'][1]) plot.drawTxt(node) plot.drawCircle(node) if node.type == 'accessPoint': for c in node.connections: line = plot.plotLine2d([node.connections[c].params['position'][0], node.params['position'][0]], \ [node.connections[c].params['position'][1], node.params['position'][1]], 'b') plot.plotLine(line) for xy in mob: i = 0 for n in range (0, len(nodes)): node = nodes[n] if node in staMov: if 'station' == node.type: node.params['position'] = xy[i][0], xy[i][1], 0 i += 1 if self.DRAW: plot.pltNode[node].set_data(xy[:, 0], xy[:, 1]) plot.drawTxt(node) plot.drawCircle(node) if self.DRAW: plot.graphPause() plot.graphUpdate(node)
def models(self, nodes=None, model=None, max_x=None, max_y=None, min_v=None, max_v=None, seed=None, staMov=None, **mobilityparam): self.modelName = model np.random.seed(seed) # number of nodes nr_nodes = staMov # simulation area (units) MAX_X, MAX_Y = max_x, max_y # max and min velocity MIN_V, MAX_V = min_v, max_v # max waiting time MAX_WT = 100. if(self.modelName=='RandomWalk'): ## Random Walk model mob = random_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) elif(self.modelName=='TruncatedLevyWalk'): ## Truncated Levy Walk model mob = truncated_levy_walk(nr_nodes, dimensions=(MAX_X, MAX_Y)) elif(self.modelName=='RandomDirection'): ## Random Direction model mob = random_direction(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V)) elif(self.modelName=='RandomWayPoint'): ## Random Waypoint model mob = random_waypoint(nr_nodes, dimensions=(MAX_X, MAX_Y), velocity=(MIN_V, MAX_V), wt_max=MAX_WT) elif(self.modelName=='GaussMarkov'): ## Gauss-Markov model mob = gauss_markov(nr_nodes, dimensions=(MAX_X, MAX_Y), alpha=0.99) elif(self.modelName=='ReferencePoint'): ## Reference Point Group model mob = reference_point_group(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=0.5) elif(self.modelName=='TimeVariantCommunity'): ## Time-variant Community Mobility Model mob = tvc(nr_nodes, dimensions=(MAX_X, MAX_Y), aggregation=[0.5,0.], epoch=[100,100]) else: print 'Model not defined!' if self.DRAW: debug('Enabling Graph...\n') plot.instantiateGraph(self.MAX_X, self.MAX_Y) for node in nodes: self.graphInstantiateNodes(node) if node not in staMov or 'accessPoint' == node.type: plot.pltNode[node].set_data(node.params['position'][0],node.params['position'][1]) plot.drawTxt(node) plot.drawCircle(node) if node.type == 'accessPoint': for c in node.connections: line = plot.plotLine2d([node.connections[c].params['position'][0],node.params['position'][0]], \ [node.connections[c].params['position'][1],node.params['position'][1]], 'b') plot.plotLine(line) #Sometimes getting the error: Failed to connect to generic netlink. try: if model!='': for xy in mob: i = 0 for n in range (0,len(nodes)): node = nodes[n] if node in staMov: if 'station' == node.type: node.params['position'] = xy[i][0], xy[i][1], 0 i += 1 if self.DRAW: plot.pltNode[node].set_data(xy[:,0],xy[:,1]) plot.drawTxt(node) plot.drawCircle(node) if self.DRAW: plt.title("Mininet-WiFi Graph") plt.draw() except: pass