def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 pursue_target=None):
        #
        # if type(in_node) is type(Node):
        #     self = in_node

        self.__a, self.__global_relay_link = environment
        self.pursue_target = None
        if pursue_target is not None:
            self.pursue_target.append(pursue_target)

        self.unit_distance = unit_distance

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()

        self.proof = GreedyCentralSolution(self.unit_distance * .8)
    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None):
        self.__a, self.__global_relay_link = environment

        self.parent = None
        self.children = []

        self.perceived_environment = NodeRecord()

        self.unit_distance = unit_distance
        self.proof = GreedyCentralSolution(self.unit_distance)
        self.last_caller = None
        self.depth = 0
        self.__depth_counter = 0
        self.tick_tock = 0
        try:
            self.home = self.__global_relay_link[0]
        except:
            self.home = self

        self.call_counter = 0

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()
Example #3
0
    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 parent=None,
                 node_name=None):
        self.__a, self.__global_relay_link = environment
        self.parent = parent
        self.children = []
        self.endpoints = []
        self.endpoints_freshness = []
        self.announcement_counter = 0

        self.messenger = Messenger(node_name)
        # self.perceived_environment = NodeRecord()

        self.unit_distance = unit_distance
        self.critical_range = self.unit_distance
        self.safe_range = self.unit_distance * 0.8
        self.max_velocity = 10
        self.max_random_velocity = self.unit_distance / 50

        self.proof = GreedyCentralSolution(self.unit_distance)
        self.depth = 0
        self.__issue_counter = 0

        try:
            self.home = self.__global_relay_link[0]
        except:
            self.home = self

        self.call_counter = 0

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()
        self.node_name = self.ID
    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:

        # execute the scenario solver
        deltaT = time.time()
        dist_list.execute_pipeline()
        greedy_list.execute_pipeline()
        deltaT = time.time() - deltaT

        # take the solutions into the window rendered
        for x in node_list:
            game_window.nodes.append(x.position.as_int_array)
class ForwardPursueNode(Node):
    __environment: List[Node]

    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 pursue_target=None):
        #
        # if type(in_node) is type(Node):
        #     self = in_node

        self.__a, self.__global_relay_link = environment
        self.pursue_target = None
        if pursue_target is not None:
            self.pursue_target.append(pursue_target)

        self.unit_distance = unit_distance

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()

        self.proof = GreedyCentralSolution(self.unit_distance * .8)

    @property
    def environment(self):
        accumulator = []
        for x in self.__a + self.__global_relay_link:
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance * 1.2:
                    accumulator.append(x)
        return accumulator

    @property
    def environment_centroid(self):
        points = list(map(lambda x: x.position.as_array, self.environment))
        points = np.sum(points, axis=0)
        return np.divide(points, len(self.environment))

    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")
    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)

    node_list.append(b_node_back)
    # node_list.append(c_node_back)

    dist_list.prepare()

    game_window = WindowManagerTypeThree()

    while True:
Example #7
0
class MultiForwardPursueNode(Node):
    pursue_target: List[Node]
    __environment: List[Node]

    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 pursue_target=None):
        self.__a, self.__global_relay_link = environment
        self.pursue_target = []

        if pursue_target is not None:
            self.pursue_target.append(pursue_target)

        self.unit_distance = unit_distance

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()

        self.proof = GreedyCentralSolution(self.unit_distance * .8)

    @property
    def environment(self):
        accumulator = []
        for x in self.__a + self.__global_relay_link:
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance:
                    accumulator.append(x)

        return accumulator

    @property
    def environment_relays(self):
        accumulator = []
        for x in self.__global_relay_link:
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance:
                    accumulator.append(x)

        return accumulator

    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()
Example #8
0
class MultiForwardPursueNode(Node):
    pursue_target: List[Node]
    __environment: List[Node]

    def __init__(self,
                 environment,
                 unit_distance,
                 position=None,
                 in_node=None,
                 pursue_target=None):
        self.__a, self.__global_relay_link = environment
        self.pursue_target = []
        if pursue_target is not None:
            self.pursue_target.append(pursue_target)

        self.unit_distance = unit_distance

        if in_node is not None:
            super().__init__(in_node.position)
        elif position is not None:
            super().__init__(position)
        else:
            super().__init__()

        self.proof = GreedyCentralSolution(self.unit_distance * .8)

    @property
    def environment(self):
        accumulator = []
        for x in self.__a + self.__global_relay_link:
            print(self.distance_to(x))
            if not self.ID == x.ID:
                if self.distance_to(x) < self.unit_distance:
                    accumulator.append(x)

        return accumulator

    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)