def moveNodeTo(cls, sta, pos): x = pos[0] y = pos[1] sta.params['position'] = x, y, 0 # mobility.getAPsInRange(sta) if Mininet_wifi.DRAW: try: plot2d.graphUpdate(sta) except: pass
def moveNodeTo(cls, sta, ap, dist, ang): x = float('%.2f' % (dist * cos(ang) + int(ap.params['position'][0]))) y = float('%.2f' % (dist * sin(ang) + int(ap.params['position'][1]))) sta.params['position'] = x, y, 0 mobility.configLinks(sta) if Mininet_wifi.DRAW: try: plot2d.graphUpdate(sta) except: pass
def simulate_car_movement(self, cars, baseStations, scatter, com_lines, mobility): # temporal variables points = [[], []] scatter.remove() nodes = cars + baseStations while com_lines: com_lines[0].remove() del com_lines[0] # iterate over each car for car in cars: # get all the properties of the car velocity = round(np.random.uniform(car.speed[0], car.speed[1])) position_x = car.properties[0] position_y = car.properties[1] car.params['position'] = position_x, position_y, 0 angle = car.properties[2] # calculate new position of the car position_x = position_x + velocity * cos( angle) * self.time_per_iteration position_y = position_y + velocity * sin( angle) * self.time_per_iteration if (position_x < car.properties[3] or position_x > car.properties[4]) \ or (position_y < car.properties[5] or position_y > car.properties[6]): self.repeat(car) points[0].append(car.initial[0]) points[1].append(car.initial[1]) else: car.properties[0] = position_x car.properties[1] = position_y points[0].append(position_x) points[1].append(position_y) for node in nodes: if nodes == car: continue else: # compute to see if vehicle is in range inside = math.pow((node.properties[0] - position_x), 2) + \ math.pow((node.properties[1] - position_y), 2) if inside <= math.pow(node.params['range'][0], 2): if isinstance(node, AP): color = 'black' else: color = 'r' line = plot2d.plotLine2d( [position_x, node.properties[0]], [position_y, node.properties[1]], color=color) com_lines.append(line) plot2d.plotLine(line) plot2d.graphUpdate(car) eval(mobility.continuePlot) scatter = plot2d.plotScatter(points[0], points[1]) plot2d.plotDraw() return [scatter, com_lines]