Exemplo n.º 1
0
    def mobility(self, nodes):
        if nodes is None:
            nodes = self.net.stations + self.net.aps
        for node in nodes:
            if isinstance(node, Station):
                if hasattr(node, 'position') and node not in self.stations:
                    self.stations.append(node)
            if isinstance(node, AP):
                if hasattr(node, 'position') and node not in self.aps:
                    self.aps.append(node)

        if self.net.draw:
            self.net.isReplaying = False
            self.net.check_dimension(nodes)

        currentTime = time()
        for node in nodes:
            if 'speed' not in node.params:
                node.params['speed'] = 1.0
            node.currentTime = 1 / node.params['speed']
            node.timestamp = float(1.0 / node.params['speed'])
            if hasattr(node, 'time'):
                self.timestamp = True

        calc_pos = self.notimestamp_
        if self.timestamp:
            calc_pos = self.timestamp_

        while self.thread_._keep_alive:
            time_ = time() - currentTime
            if len(nodes) == 0:
                break
            for node in nodes:
                if node in self.stations:
                    calc_pos(node, time_)
                    if len(node.p) == 0:
                        nodes.remove(node)
                    ConfigMobLinks()
                    if self.net.draw:
                        node.update_2d()
            if self.net.draw:
                PlotGraph.pause()
Exemplo n.º 2
0
    def simulate_car_movement(self, cars, aps, scatter, com_lines):
        # temporal variables
        points = [[], []]
        scatter.remove()

        nodes = cars + aps

        while com_lines:
            com_lines[0].remove()
            del com_lines[0]

        while self.pause_simulation:
            pass

        # iterate over each car
        for car in cars:
            # get all the properties of the car
            vel = round(np.random.uniform(car.speed[0], car.speed[1]))
            pos_x = car.prop[0]
            pos_y = car.prop[1]

            car.position = pos_x, pos_y, 0
            car.set_pos_wmediumd(car.position)
            angle = car.prop[2]

            # calculate new position of the car
            pos_x = pos_x + vel * cos(angle) * self.time_per_iteration
            pos_y = pos_y + vel * sin(angle) * self.time_per_iteration

            if (pos_x < car.prop[3] or pos_x > car.prop[4]) \
                or (pos_y < car.prop[5] or pos_y > car.prop[6]):
                self.repeat(car)
                points[0].append(car.initial[0])
                points[1].append(car.initial[1])
            else:
                car.prop[0] = pos_x
                car.prop[1] = pos_y
                points[0].append(pos_x)
                points[1].append(pos_y)

                for node in nodes:
                    if nodes == car:
                        continue
                    else:
                        # compute to see if vehicle is in range
                        inside = math.pow((node.prop[0] - pos_x), 2) + \
                                 math.pow((node.prop[1] - pos_y), 2)
                        if inside <= math.pow(node.wintfs[0].range, 2):
                            if isinstance(node, AP):
                                color = 'black'
                            else:
                                color = 'r'
                            line = Plot2D.line2d([pos_x, node.prop[0]],
                                                 [pos_y, node.prop[1]],
                                                 color=color)
                            com_lines.append(line)
                            Plot2D.line(line)

            car.update_2d()

        PlotGraph.pause()
        if not self.thread_._keep_alive:
            exit()

        scatter = Plot2D.scatter(points[0], points[1])
        Plot2D.draw()

        return [scatter, com_lines]