def simulate_car_movement(self, cars, baseStations, scatter, com_lines): # 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_iteraiton position_y = position_y + velocity * sin(angle) * self.time_per_iteraiton 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'], 2): if node.type == 'accessPoint': 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]
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.setPositionWmediumd() 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, 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)