def search(self, problem): self.clear_instrumentation() self.failure = True self.last_state = None # current <- MAKE-NODE(problem.INITIAL-STATE) current_node = Node(problem.get_initial_state()) # for t = 1 to INFINITY do time_step = 0 while True: # temperature <- schedule(t) temperature = self.scheduler.get_temp(time_step) time_step += 1 # if temperature = 0 then return current if temperature == 0: if search.utils.is_goal_state(problem, current_node): self.failure = False self.last_state = current_node.get_state() return search.utils.actions_from_nodes(current_node.get_path_from_root()) children = self.expand_node(current_node, problem) number_of_children = len(children) if number_of_children != 0: # next <- a randomly selected successor of current next = children[randint(0, number_of_children - 1)] # /\E <- next.VALUE - current.value delta_e = self._get_value(current_node) - self._get_value(next) if self._should_accept(temperature, delta_e): current_node = next
def search(self, problem): """ Search solution for a problem with Depth First Search strategy with a specified depth limit. problem - problem to find solution for returns list of actions to execute from initial state to reach goal state. If search failed return a list that represents failure. If search ended because of cutoff returns a list that represents that cutoff occurred """ # return RECURSIVE-DLS(MAKE-NODE(INITIAL-STATE[problem]), problem, limit) return self._recursive_dls(Node(problem.get_initial_state()), problem, self._limit)
def search(self, problem): self.clear_instrumentation() self.failure = True self.last_state = None # current <- MAKE-NODE(problem.INITIAL-STATE) current_node = Node(problem.get_initial_state()) while True: children = self.expand_node(current_node, problem) # neighbor <- a highest-valued successor of current neighbor = self._get_lowest_valued_node(children) # if neighbor.VALUE <= current.VALUE then return current.STATE if neighbor == None or self._get_value(current_node) <= self._get_value(neighbor): if search.utils.is_goal_state(problem, current_node): self.failure = False self.last_state = current_node.get_state() return search.utils.actions_from_nodes(current_node.get_path_from_root()) # current <- neighbor current_node = neighbor
def search(self, problem): self.clear_instrumentation() # RBFS(problem, MAKE-NODE(INITIAL-STATE[problem]), infinity) root_node = Node(problem.get_initial_state()) sr = self._rbfs(problem, root_node, self._evaluation_function.f(root_node), PlusInfinity(), 0) if sr.found_solution(): goal_node = sr.get_solution() return utils.actions_from_nodes(goal_node.get_path_from_root()) else: return self._failure()
def search(self, problem): self.clear_instrumentation() self.failure = True self.last_state = None # current <- MAKE-NODE(problem.INITIAL-STATE) current_node = Node(problem.get_initial_state()) while True: children = self.expand_node(current_node, problem) # neighbor <- a highest-valued successor of current neighbor = self._get_lowest_valued_node(children) # if neighbor.VALUE <= current.VALUE then return current.STATE if neighbor == None or self._get_value( current_node) <= self._get_value(neighbor): if search.utils.is_goal_state(problem, current_node): self.failure = False self.last_state = current_node.get_state() return search.utils.actions_from_nodes( current_node.get_path_from_root()) # current <- neighbor current_node = neighbor