Beispiel #1
0
    def get_all_successor_nodes(self, astar_state):
        """
        Fetches all successor nodes from a given CSP state
        In this spesific problem that means all states with a domain
        length greater than 1 for a random node
        :return: The generated successor nodes
        """
        csp_state = astar_state.state
        successor_nodes = []

        for node, domains in csp_state.nodes.items():
            if len(domains) > 1:
                for d in range(len(domains)):

                    child_state = deepcopy(csp_state)
                    child_state.nodes[node] = {list(domains)[d]}

                    if DEBUG:
                        print("Domain for %s is now %s" %
                              (node, str(child_state.nodes[node])))

                    self.gac.csp_state = child_state
                    self.gac.run_again(node)

                    if not child_state.contradiction:
                        astar_state = AStarState()
                        astar_state.state = child_state
                        successor_nodes.append(astar_state)

                return successor_nodes
    def get_all_successor_nodes(self, astar_state):
        """
        Fetches all successor nodes from a given CSP state
        In this spesific problem that means all states with a domain
        length greater than 1 for a random node
        :return: The generated successor nodes
        """
        csp_state = astar_state.state
        successor_nodes = []

        for node, domains in csp_state.nodes.items():
            if len(domains) > 1:
                for d in range(len(domains)):
                    child_state = deepcopy(csp_state)
                    child_state.nodes[node] = [list(domains)[d]]

                    if DEBUG:
                        print("Domain for %s is now %s" % (node, str(child_state.nodes[node])))

                    self.gac.csp_state = child_state
                    self.gac.run_again(node)

                    if not child_state.contradiction:
                        astar_state = AStarState()
                        astar_state.state = child_state
                        successor_nodes.append(astar_state)

                return successor_nodes
 def get_node(self, x, y):
     """
     Returnes a given node in the grid representation
     It used the x and y coordinates to achieve this
     :param x: x-coordinate
     :param y: y-coordinate
     :return:
     """
     a = AStarState(index=0, x=x, y=y)
     a.state = self.grid[y][x]
     return a
Beispiel #4
0
 def get_node(self, x, y):
     """
     Returnes a given node in the grid representation
     It used the x and y coordinates to achieve this
     :param x: x-coordinate
     :param y: y-coordinate
     :return:
     """
     a = AStarState(index=0, x=x, y=y)
     a.state = self.grid[y][x]
     return a