def __add_relays(self, distance_multiplier):
        for i in self.__segment_list:
            if not i.has_hidden:
                mVal = i.point_a.angle_to(i.point_b)

                [x, y] = i.point_a.position.as_array

                relay_count = int(np.floor(i.distance / distance_multiplier))

                for _ in range(relay_count):
                    x, y = self.__move_along_line(mVal, distance_multiplier, x, y)
                    self.relay_list.append(Node(Pos(x, y)))

                i.has_relays = True

        for i in self.__segment_list:

            if i.has_hidden:
                internal_found = np.inf
                for k in self.relay_list:
                    query_distance = i.point_a.distance_to(k)
                    if query_distance < internal_found:
                        internal_found = query_distance
                        [x, y] = k.position.as_array

                mVal = np.subtract(i.point_b.position.as_array, [x, y])
                mVal = np.arctan2(mVal[1], mVal[0])

                relay_count = int(np.floor(i.distance / distance_multiplier))

                for j in range(relay_count):
                    x, y = self.__move_along_line(mVal, distance_multiplier, x, y)
                    self.relay_list.append(Node(Pos(x, y)))
    def __init__(self, unit_distance, full_list=None):
        self.__search_space = []
        self.unit_distance = unit_distance
        self.grid_resolution = 1
        self.max_iterations = 100

        self.a = Pos(-7, -7)
        self.b = Pos(27, 27)

        super().__init__()
        if full_list is not None:
            self.node_list = full_list
예제 #3
0
    def follow(self):
        try:
            self.proof.node_list = self.environment
            self.proof.execute_pipeline()
        except:
            pass

        # for x in self.environment_relays:
        #     if self.type is NodeType.Relay:
        #         self.move_along_line(self.angle_to(x), (self.distance_to(x) - self.unit_distance) * .2)
        #         try:
        #             self.move_along_line(self.angle_to(self.proof.relay_list[0]),
        #                                  self.distance_to(self.proof.relay_list[0]) * .2)
        #         except:
        #             pass

        for x in self.pursue_target:
            print("we runnning")
            if self.type is NodeType.Relay:
                self.move_along_line(
                    self.angle_to(x),
                    (self.distance_to(x) - self.unit_distance) * .2)
                try:
                    self.move_along_line(
                        self.angle_to(self.proof.relay_list[0]),
                        self.distance_to(self.proof.relay_list[0]) * .6)
                    print("it gets triggered")

                except:
                    pass

            elif self.type is NodeType.Home:
                if self.distance_to(x) > self.unit_distance * .8:
                    new_node = MultiForwardPursueNode(
                        [self.__a, self.__global_relay_link],
                        self.unit_distance,
                        in_node=Node(Pos(0, 0)))

                    new_node.type = NodeType.Relay
                    new_node.move_along_line(new_node.angle_to(x),
                                             self.distance_to(x) * .8)

                    new_node.pursue_target.append(x)
                    self.pursue_target.append(new_node)
                    self.pursue_target.remove(x)
                    self.__global_relay_link.append(new_node)

                # if in call-back range
                if self.distance_to(x) < self.unit_distance * .1:
                    current_target = x
                    little_set = self.pursue_target + current_target.pursue_target
                    self.pursue_target = set(little_set)

                    try:
                        self.__global_relay_link.remove(current_target)
                        print("triggered from the bottom")
                    except:
                        print("form the bottom")

        self.proof.reset()
예제 #4
0
    def move_to(self):
        [xs, ys] = self.move_centroid()
        tmp = Node(Pos(xs, ys))
        self.move_along_line(self.angle_to(tmp),
                             min([self.distance_to(tmp), self.max_velocity]))

        if COMPRESSION_DECOMPRESSION_FIX:
            try:
                [xs, ys] = self.child_centroid()
                tmp = Node(Pos(xs, ys))
                self.move_along_line(
                    self.angle_to(tmp),
                    min([
                        self.distance_to(tmp) - self.critical_range,
                        self.max_velocity
                    ]))
            except:
                pass
예제 #5
0
    def follow(self):
        if self.type is NodeType.Relay:
            # a propegated velocity is used to move everything around
            self.proof.node_list = self.environment

            self.move_along_line(self.angle_to(self.pursue_target),
                                 (self.distance_to(self.pursue_target) - self.unit_distance))

            try:
                if len(self.environment) is 2:
                    if self.environment[0].distance_to(self.environment[1]) > 0.8 * self.unit_distance:
                        [xs, ys] = self.environment_centroid
                        to_go = Node(Pos(xs, ys))
                        self.move_along_line(self.angle_to(to_go), self.distance_to(to_go))
            except Exception as e:
                print(e)
                pass

            self.proof.reset()


        elif self.type is NodeType.Home:
            if self.distance_to(self.pursue_target) > self.unit_distance * .8:
                new_node = SmartNode([self.__a, self.__global_relay_link], self.unit_distance,
                                             in_node=Node(Pos(0, 0)))

                new_node.type = NodeType.Relay
                new_node.move_along_line(new_node.angle_to(self.pursue_target),
                                         self.distance_to(self.pursue_target) * .8)

                new_node.pursue_target = self.pursue_target
                self.pursue_target = new_node
                self.__global_relay_link.append(new_node)

            # if in call-back range
            if self.distance_to(self.pursue_target) < self.unit_distance * .1:
                current_target = self.pursue_target
                self.pursue_target = current_target.pursue_target
                try:
                    self.__global_relay_link.remove(current_target)
                except Exception as e:
                    print(e)
                    print("Node removal error")
    def spawn_to(self, target):
        new_node = BackwardPursueNode([self.__a, self.__global_relay_link], self.unit_distance,
                                      in_node=Node(Pos(0, 0)))

        new_node.type = NodeType.Relay
        new_node.move_to(target)

        new_node.follower = self
        new_node.depth = self.depth_counter
        target.follower = new_node
        self.__global_relay_link.append(new_node)
    def execute_pipeline(self):
        for i in self.node_list[1:]:
            count = int(
                np.floor(self.node_list[0].distance_to(i) /
                         self.unit_distance))

            [x, y] = self.node_list[0].position.as_array

            for _ in range(count):
                x, y = self.__move_along_line(self.node_list[0].angle_to(i),
                                              self.unit_distance, x, y)
                self.relay_list.append(Node(Pos(x, y)))
    def follow(self):
        if self.type is NodeType.Relay:
            # a propegated velocity is used to move everything around

            print("follow works")
            self.proof.node_list = self.environment

            self.move_along_line(
                self.angle_to(self.pursue_target),
                (self.distance_to(self.pursue_target) - self.unit_distance) *
                .2)

            try:
                self.proof.execute_pipeline()
                self.move_along_line(
                    self.angle_to(self.proof.relay_list[0]),
                    self.distance_to(self.proof.relay_list[0]) * .2)
                self.proof.reset()
            except:
                pass

        elif self.type is NodeType.Home:
            if self.distance_to(self.pursue_target) > self.unit_distance * .8:
                new_node = ForwardPursueNode(
                    [self.__a, self.__global_relay_link],
                    self.unit_distance,
                    in_node=Node(Pos(0, 0)))

                new_node.type = NodeType.Relay
                new_node.move_along_line(
                    new_node.angle_to(self.pursue_target),
                    self.distance_to(self.pursue_target) * .8)

                new_node.pursue_target = self.pursue_target
                self.pursue_target = new_node
                self.__global_relay_link.append(new_node)

            # if in call-back range
            if self.distance_to(self.pursue_target) < self.unit_distance * .1:
                current_target = self.pursue_target
                self.pursue_target = current_target.pursue_target
                try:
                    self.__global_relay_link.remove(current_target)
                except Exception as e:
                    print(e)
                    print("Node removal error")
예제 #9
0
    def spawn_to(self, target):
        new_node = DecentralizedNode([self.__a, self.__global_relay_link],
                                     self.unit_distance,
                                     in_node=Node(Pos(0, 0)))

        new_node.type = NodeType.Relay

        new_node.parent = self
        new_node.children.append(target)

        self.children.remove(target)
        self.children.append(new_node)

        target.parent = new_node

        new_node.move_to()

        self.__global_relay_link.append(new_node)
    def PointsInCircum(self, reference: Node, radius):

        n = np.multiply(1, np.pi)

        # will always give 6, maybe a useless piece of code
        n_i = int(np.floor(n))

        for i in range(0, n_i):
            h = 2 * np.pi / radius * i
            h = [np.cos(h), np.sin(h)]
            h = np.multiply(h, radius)
            h = np.add(reference.position.as_array, h)

            # if we want a grid locking kind of situation
            # h = np.floor(h)
            # ------------------------------------------

            h = ExhaustiveNode(Pos(h[0], h[1]))
            # print(reference.distance_to(h))
            break_flag = not h.inside_box(self.a, self.b)

            # prove redundancy
            for x in self.relay_list:
                if x.distance_to(h) < radius:
                    if not np.isclose(radius, x.distance_to(h)):
                        break_flag = True
                        break

            for x in self.node_list:

                if np.isclose(x.distance_to(h), 0):
                    break_flag = True
                    break

            if not break_flag:
                self.relay_list.append(h)

                for x in self.node_list:
                    if x.distance_to(h) <= radius:
                        x.data_set()
                        # we also return that node for later processing
                        return h
예제 #11
0
    def execute_pipeline(self):
        execution_list = self.node_list[1:]
        resource_list = [self.node_list[0]]

        for i in execution_list:
            min_acc = 1000000000
            min_pair = [0, 1]
            for j in resource_list:
                if i.distance_to(j) < min_acc:
                    min_acc = i.distance_to(j)
                    min_pair = [i, j]

            [i, j] = min_pair
            count = int(np.floor(i.distance_to(j) / self.unit_distance))
            [x, y] = i.position.as_array
            for _ in range(count):
                x, y = self.__move_along_line(i.angle_to(j),
                                              self.unit_distance, x, y)
                resource_list.append(Node(Pos(x, y)))
        self.relay_list = resource_list[1:]
예제 #12
0
    def follow(self):
        for x in self.pursue_target:
            if self.distance_to(x) > self.unit_distance * .8:
                if self.type is NodeType.Relay:
                    self.move_along_line(
                        self.angle_to(x),
                        (self.distance_to(x) - self.unit_distance) * .2)

                    try:
                        self.proof.execute_pipeline()
                        self.move_along_line(
                            self.angle_to(self.proof.relay_list[0]),
                            self.distance_to(self.proof.relay_list[0]) * .6)
                        self.proof.reset()
                    except:
                        pass

                elif self.type is NodeType.Home:
                    for r in self.__global_relay_link[1:]:
                        if x.distance_to(r) < self.unit_distance * .7:
                            r.pursue_target.append(x)
                            self.pursue_target.remove(x)
                            if r not in self.pursue_target:
                                self.pursue_target.append(r)
                            break

                    if x in self.pursue_target:
                        new_node = MultiForwardPursueNode(
                            [self.__a, self.__global_relay_link],
                            self.unit_distance,
                            in_node=Node(Pos(0, 0)))

                        new_node.type = NodeType.Relay
                        new_node.move_along_line(new_node.angle_to(x),
                                                 self.distance_to(x) * .8)

                        new_node.pursue_target.append(x)
                        # needs work
                        self.pursue_target.remove(x)
                        self.pursue_target.append(new_node)
                        self.__global_relay_link.append(new_node)
    def move_to(self, target):
        self.call_counter = 0
        self.last_caller = target
        if self.type == NodeType.Relay:
            # chain tightening code
            self.move_along_line(self.angle_to(target), (self.distance_to(target) - self.unit_distance) * .2)

            try:
                if len(self.environment) is 2:
                    if self.environment[0].distance_to(self.environment[1]) > 0.8 * self.unit_distance:
                        [xs, ys] = self.environment_centroid
                        to_go = Node(Pos(xs, ys))
                        self.move_along_line(self.angle_to(to_go), self.distance_to(to_go) * 0.6)

            except IndexError as e:
                log.error("--------------------------------------------------")
                log.error("try failed - couldn't find a solution")
                log.error(e)
                # # force it for now
                if self.home not in self.environment_full:
                    try:
                        for j in self.follower.environment_infrastructure:
                            if self.last_caller is j:
                                self.last_caller.follower = self
                                self.__global_relay_link.remove(self)

                        self.last_caller.follower = self
                        self.__global_relay_link.remove(self)
                        log.error("Problem solved")
                    except Exception as er:
                        log.error(er)
                        log.error("no hope in this one")

        if self.type == NodeType.Home:
            if self.distance_to(target) > self.unit_distance * .8:
                self.spawn_to(target)

        if self.type == NodeType.End:
            # if self.distance_to(target) > self.unit_distance * .8:
            target.follower = self.follower
    def exhaust(self):

        mean = []
        for i in self.node_list:
            mean.append(i.position.as_array)

        [x, y] = np.mean(mean, axis=0)

        start_point = ExhaustiveNode(Pos(x, y))
        self.relay_list.append(start_point)
        self.PointsInCircum(start_point, self.unit_distance)

        # recursion because a pointer to the array is used
        # it keeps changing size every time we run
        # the exit condition is no new items
        for i in tqdm(self.relay_list):
            self.PointsInCircum(i, self.unit_distance)
            self.to_plot()

            holder = list(map(lambda x: x.data, self.node_list))
            if all(holder):
                break
    def move_to(self, target):
        self.call_counter = 0
        self.last_caller = target
        if self.type == NodeType.Relay:
            # chain tightening code
            self.move_along_line(
                self.angle_to(target),
                (self.distance_to(target) - self.unit_distance) * .2)

            if len(self.environment) is 2:
                if self.environment[0].distance_to(
                        self.environment[1]) > 0.8 * self.unit_distance:
                    [xs, ys] = self.environment_centroid
                    to_go = Node(Pos(xs, ys))
                    self.move_along_line(self.angle_to(to_go),
                                         self.distance_to(to_go) * 0.6)

        if self.type == NodeType.Home:
            if self.distance_to(target) > self.unit_distance * .8:
                self.spawn_to(target)

        if self.type == NodeType.End:
            # if self.distance_to(target) > self.unit_distance * .8:
            target.follower = self.follower
from pygame.constants import *

from forward_distributed_solution.MultiForwardDecentralizedSolution import MultiForwardDecentralizedSolution
from greedy_central_solution import GreedyCentralSolution
from fui import WindowManager
from simulation.node import Node, Pos
from simulation.node.Node import NodeType

if __name__ == "__main__":
    node_selector = 1

    move_coefficient = 10

    # create a list of nodes, this is our scenario
    node_list = []
    a_node = Node(Pos(0, 0))
    b_node = Node(Pos(1.7 * 10, 1 * 10))
    c_node = Node(Pos(2 * 10, 2 * 10))

    node_list.append(a_node)
    node_list.append(b_node)
    # node_list.append(c_node)

    # shove the list into a scenario solver
    dist_list = MultiForwardDecentralizedSolution(40, node_list)
    greedy_list = GreedyCentralSolution(40 * .8, node_list)

    game_window = WindowManager()

    while True:
예제 #17
0
    def tick(self):
        # this is a garbage cleaning step
        for child in self.children:
            # internally make sure there is no reference to a non existent node
            if child not in self.__a[1:] + self.__global_relay_link:
                self.children.remove(child)
                break

        self.messenger.process()
        for x in self.messenger.out_queue:
            for y in self.children:
                y.messenger.receive(x)
            self.messenger.out_queue.remove(x)

        for x in self.children:
            x.tell_depth(self.depth)

        for idx, _ in enumerate(self.endpoints):
            self.endpoints_freshness[idx] += 1

        for idx, x in enumerate(self.endpoints_freshness):
            if x > 120:
                del self.endpoints[idx]
                del self.endpoints_freshness[idx]

        if self.type == NodeType.Relay:
            # call the procedures that make decentralized nodes
            self.update_parent()
            self.move_to()
            if not COMPRESSION_DECOMPRESSION_FIX:
                self.request_parent_proximity()

            if not COMPRESSION_DECOMPRESSION_FIX:
                # the random noise added to all relays so they avoid local minima solutions
                self.position.velocity_add([
                    (random.random() * self.max_random_velocity) -
                    (self.max_random_velocity / 2),
                    (random.random() * self.max_random_velocity) -
                    (self.max_random_velocity / 2)
                ])

            # check if we have multiple children follow only one if two are going in separate directions
            if len(self.children) > 1:
                for child in self.children:
                    if self.distance_to(child) > self.critical_range:
                        # make it only preform this every 20 ticks for stable switching
                        if self.__issue_counter > 20:
                            self.__issue_counter = 0
                            child.change_parent(self.parent)
                            self.change_parent(self.parent.parent)
                            return
                        self.__issue_counter += 1

        if self.type == NodeType.End:
            # the broadcast mechanism to indicate endnode branch
            self.update_parent()
            if self.announcement_counter >= 100:
                self.announcement_counter = 0
                self.announce_endpoint_exist(self)
            self.announcement_counter += 1

        if self.type == NodeType.Home:
            # spawn a relay step
            for x in self.children:
                if self.distance_to(x) > self.critical_range:
                    self.spawn_to(x)
                    return

                # Code to preform the despawn step
                # we measure the distance to parent then despawn if parent is in proximity
                if x.type == NodeType.Relay:
                    if x.children:
                        try:
                            [x_cc, y_cc] = x.child_centroid()
                            cc_as_node = Node(Pos(x_cc, y_cc))
                            if self.distance_to(
                                    cc_as_node) < self.critical_range:
                                for y in x.children:
                                    y.change_parent(self)
                                    self.announce_removal(x)
                                    self.__global_relay_link.remove(x)
                        except Exception as e:
                            # this is reached if there is an issue with removing a node from __global_relay_link
                            pass
            for i in self.environment_infrastructure:
                if self.distance_to(i) < 0.4 * self.unit_distance:
                    for j in self.environment:
                        if i.last_caller is j:
                            i.last_caller.follower = self
                            self.__global_relay_link.remove(i)

if __name__ == "__main__":

    log = logging.getLogger(__name__)
    node_selector = 1
    move_coefficient = 10
    unit_distance = 40

    # create a list of nodes, this is our scenario
    a_node = Node(Pos(0, 0))

    node_list = []
    node_list.append(a_node)

    # shove the list into a scenario solver
    # the way the algorithms work makes for a .85 ratio in comms
    dist_list = BackwardDecentralizedSolution(unit_distance, node_list)
    greedy_list = GreedyCentralSolution(unit_distance, node_list)

    b_node = Node(Pos(1.7 * 10, 1 * 10))
    c_node = Node(Pos(2 * 10, 2 * 10))

    b_node_back = BackwardPursueNode(dist_list.sandbox, unit_distance, in_node=b_node)
    c_node_back = BackwardPursueNode(dist_list.sandbox, unit_distance, in_node=c_node)
예제 #19
0
    def inside_box(self, a: Pos, b: Pos) -> bool:
        if a.x <= self.position.x <= b.x and a.y <= self.position.y <= b.y:
            return True
        else:
            return False

    def relative_quadrant(self, node: Node):
        angle = self.angle_to(target=node)
        pass
        # if angle != 0:
        #     if angle > 0:
        #         # to the right
        #     else:
        #         # to the left
        # else:
        #     # its on the line
        #
        # if ab


if __name__ == "__main__":
    node1 = ExhaustiveNode(position=Pos(0, 0))

    for x in range(-5, 5):
        for y in range(-5, 5):
            node2 = ExhaustiveNode(position=Pos(x, y))
            print(
                str(x) + " - " + str(y) + " = " +
                str(node1.angle_to(node2) * 180 / np.pi))
            x.tick()

    @property
    def sandbox(self):
        return [self.node_list, self.relay_list]


if __name__ == "__main__":

    log = logging.getLogger(__name__)
    node_selector = 1
    move_coefficient = 10
    unit_distance = 40

    # create a list of nodes, this is our scenario
    a_node = Node(Pos(0, 0))

    node_list = []
    node_list.append(a_node)

    # shove the list into a scenario solver
    # the way the algorithms work makes for a .85 ratio in comms
    dist_list = BackwardDecentralizedSolution(unit_distance, node_list)
    greedy_list = GreedyCentralSolution(unit_distance, node_list)

    b_node = Node(Pos(1.7 * 10, 1 * 10))
    c_node = Node(Pos(2 * 10, 2 * 10))

    b_node_back = BackwardPursueNode(dist_list.sandbox,
                                     unit_distance,
                                     in_node=b_node)
예제 #21
0
        self.relay_list.children = None

    @property
    def sandbox(self):
        return [self.node_list, self.relay_list]


if __name__ == "__main__":

    log = logging.getLogger(__name__)
    node_selector = 1
    move_coefficient = 10
    unit_distance = 40

    # create a list of nodes, this is our scenario
    a_node = Node(Pos(0, 0))

    node_list = []
    node_list.append(a_node)

    # shove the list into a scenario solver
    # the way the algorithms work makes for a .85 ratio in comms
    dist_list = DecentralizedSolution(unit_distance, node_list)
    greedy_list = GreedyCentralSolution(unit_distance, node_list)

    d_node = Node(Pos(2 * 10, 0 * 10))
    d_node_back = DecentralizedNode(dist_list.sandbox,
                                    unit_distance,
                                    in_node=d_node)

    node_list.append(d_node_back)
                    break

            if not break_flag:
                self.relay_list.append(h)

                for x in self.node_list:
                    if x.distance_to(h) <= radius:
                        x.data_set()
                        # we also return that node for later processing
                        return h


if __name__ == "__main__":
    test_list = ExhaustiveCentralSolution(3)

    test_list.add(Node(Pos(0, 0)))
    test_list.add(Node(Pos(10, 11)))
    test_list.add(Node(Pos(9, 20)))
    test_list.add(Node(Pos(25, 18)))
    # test_list.add(Node(Pos(2, 15)))
    # test_list.add(Node(Pos(18, -5)))
    # test_list.add(Node(Pos(25, 25)))
    # test_list.add(Node(Pos(-5, 25)))

    test_list.exhaust()

    # start = time.time()
    # test_list.execute_pipeline()
    # end = time.time()
    # print("execution time - " + str(end - start))
예제 #23
0
import time
from random import randint

from exhaustive_central_solution.ExhaustiveCentralSolution import ExhaustiveCentralSolution
from greedy_central_solution.GreedyCentralSolution import GreedyCentralSolution
from fui import WindowManager
from pursue_central_solution.PursueCentralSolution import PursueCentralSolution
from simulation.node import Node, Pos

if __name__ == "__main__":

    # create a list of nodes, this is our scenario
    node_list = []
    node_list.append(Node(Pos(0, 0)))
    node_list.append(Node(Pos(10 * 10, 11 * 10)))
    node_list.append(Node(Pos(9 * 10, 20 * 10)))
    node_list.append(Node(Pos(25 * 10, 18 * 10)))
    node_list.append(Node(Pos(2 * 10, 15 * 10)))
    node_list.append(Node(Pos(18 * 10, -5 * 10)))
    node_list.append(Node(Pos(25 * 10, 25 * 10)))
    node_list.append(Node(Pos(-5 * 10, 25 * 10)))

    # shove the list into a scenario solver
    greedy_list = GreedyCentralSolution(20, node_list)
    pursue_list = PursueCentralSolution(20, node_list)
    exhaustive_list = ExhaustiveCentralSolution(20, node_list)
    game_window = WindowManager()

    while True:
        # execute the scenario solver
        deltaT = time.time()
예제 #24
0
            self.relay_list.append(new_node)

    def execute_pipeline(self):
        for x in self.relay_list:
            x.follow()

    @property
    def sandbox(self):
        return [self.node_list, self.relay_list]


if __name__ == "__main__":
    # create a list of nodes, this is our scenario
    node_list = []

    a_node = Node(Pos(0, 0))
    b_node = Node(Pos(1.7, 1))
    c_node = Node(Pos(1.3, 1))

    node_list.append(a_node)
    node_list.append(b_node)

    test_dist = MultiForwardDecentralizedSolution(2, node_list)

    a_relay = MultiForwardPursueNode(test_dist.sandbox,
                                     2,
                                     in_node=Node(Pos(1, 1)))
    a_relay.type = NodeType.Relay

    node_list.append(c_node)
예제 #25
0
        np.savetxt('relay-list.csv', relay_pos, delimiter=',')
        np.savetxt('node-list.csv', node_pos, delimiter=',')

    def to_plot(self):
        node_pos, relay_pos = self.to_points()

        relay_pos = np.array(relay_pos)
        node_pos = np.array(node_pos)

        import matplotlib.pyplot as plt
        plt.scatter(node_pos[:, 0], node_pos[:, 1], c="r")
        plt.scatter(relay_pos[:, 0], relay_pos[:, 1], c="b")

        plt.axis('equal')
        plt.show()


if __name__ == "__main__":
    test_list = NodeNetwork()

    test_list.add(Node(Pos(0, 0)))
    test_list.add(Node(Pos(10, 11)))
    test_list.add(Node(Pos(9, 20)))
    test_list.add(Node(Pos(25, 18)))
    test_list.add(Node(Pos(2, 15)))
    test_list.add(Node(Pos(18, -5)))
    test_list.add(Node(Pos(25, 25)))
    test_list.add(Node(Pos(-5, 25)))

    print(test_list.list)
예제 #26
0
                            break

                    if x in self.pursue_target:
                        new_node = MultiForwardPursueNode(
                            [self.__a, self.__global_relay_link],
                            self.unit_distance,
                            in_node=Node(Pos(0, 0)))

                        new_node.type = NodeType.Relay
                        new_node.move_along_line(new_node.angle_to(x),
                                                 self.distance_to(x) * .8)

                        new_node.pursue_target.append(x)
                        # needs work
                        self.pursue_target.remove(x)
                        self.pursue_target.append(new_node)
                        self.__global_relay_link.append(new_node)


if __name__ == "__main__":
    node_list = []
    node_list.append(Node(Pos(0, 0)))
    node_list.append(Node(Pos(1, 1.5)))
    node_list.append(Node(Pos(3, 3)))

    new_test = Node(Pos(1, 1))
    ai_test = MultiForwardPursueNode(node_list, 2, in_node=Node(Pos(1, 1)))
    print(ai_test.environment)

    print("Dont mess with the order -.-")
예제 #27
0
        for x in relays:
            tmp_count = 0
            for y in relays:
                if x != y:
                    if x.type != NodeType.End:
                        if x.distance_to(y) <= unit_dis * 1:
                            tmp_count += 1
                            if tmp_count > 2:
                                multi_link_count += 1
        return multi_link_count


if __name__ == "__main__":
    nodes_list = []
    random.seed(9001)
    a_node = Node(Pos(0, 0))
    nodes_list.append(a_node)

    combined_simulator = []
    combined_simulator.append(
        PursueCentralSmarterSolution(UNIT_DISTANCE, nodes_list))
    combined_simulator.append(GreedyCentralSolution(UNIT_DISTANCE, nodes_list))
    combined_simulator.append(DecentralizedSolution(UNIT_DISTANCE, nodes_list))
    combined_simulator.append(PursueCentralSolution(UNIT_DISTANCE, nodes_list))

    nodes_list.append(
        DecentralizedNode(combined_simulator[2].sandbox,
                          UNIT_DISTANCE,
                          in_node=Node(Pos(10, 10))))
    combined_simulator[2].prepare()
    average_list = [np.zeros(len(combined_simulator))]
    return unit_distance * dist_ratio


def broken_links_counts(solutions, relays: List[Node], unit_dist):
    link_count = 0
    for x in relays:
        for y in relays:
            if x != y:
                if x.distance_to(y) <= unit_dist * 1.05:
                    link_count += 1


if __name__ == "__main__":
    nodes_list = []

    a_node = Node(Pos(0, 0))
    nodes_list.append(a_node)

    combined_simulator = []
    combined_simulator.append(PursueCentralSolution(UNIT_DISTANCE, nodes_list))

    nodes_list.append(Node(Pos(10, 10)))
    average_list = [np.zeros(2)]

    for v in tqdm(range(MAX_NODE_COUNT)):
        value_list = []
        for _ in range(AVERAGE_SAMPLES):
            for x in nodes_list[1:]:
                x.position.velocity_add([
                    random.randint(-VELOCITY, VELOCITY),
                    random.randint(-VELOCITY, VELOCITY)
예제 #29
0
import time
from pygame.constants import *

from forward_distributed_solution.ForwardDecentralizedSolution import ForwardDecentralizedSolution, ForwardPursueNode
from greedy_central_solution import GreedyCentralSolution
from fui import WindowManager
from simulation.node import Node, Pos

if __name__ == "__main__":
    node_selector = 1

    move_coefficient = 10

    # create a list of nodes, this is our scenario
    node_list = []
    a_node = Node(Pos(0, 0))
    b_node = Node(Pos(1.7 * 10, 1 * 10))
    c_node = Node(Pos(2 * 10, 2 * 10))

    node_list.append(a_node)
    node_list.append(b_node)
    # node_list.append(c_node)

    # shove the list into a scenario solver
    dist_list = ForwardDecentralizedSolution(40, node_list)
    greedy_list = GreedyCentralSolution(40 * .8, node_list)

    game_window = WindowManager()

    while True:
    else:
        for x in relays :
            tmp_count = 0
            for y in relays:
                if x != y:
                    if x.type != NodeType.End:
                        if x.distance_to(y) <= unit_dis * 1:
                            tmp_count += 1
                            if tmp_count > 2:
                                multi_link_count += 1
        return multi_link_count

if __name__ == "__main__":
    nodes_list = []

    a_node = Node(Pos(0, 0))
    nodes_list.append(a_node)

    combined_simulator = []
    combined_simulator.append(PursueCentralSmarterSolution(UNIT_DISTANCE, nodes_list))
    combined_simulator.append(GreedyCentralSolution(UNIT_DISTANCE, nodes_list))
    combined_simulator.append(DecentralizedSolution(UNIT_DISTANCE, nodes_list))

    nodes_list.append(DecentralizedNode(combined_simulator[2].sandbox, UNIT_DISTANCE, in_node=Node(Pos(10, 10))))
    combined_simulator[2].prepare()
    average_list = [np.zeros(len(combined_simulator))]

    for v in tqdm(range(MAX_NODE_COUNT)):
        value_list = []
        for _ in range(AVERAGE_SAMPLES):
            for x in nodes_list[1:]: