def create_possibilites(self, node): """ Gets a list of possible new moves, makes sure they are not already in the list, applies heurstic and adds them :type node: (int, Flow) """ new_states = utils.generate_possible_moves_single_gp(node[1]) for new_state in new_states: if new_state not in [new_node[1] for new_node in self.frontier]: # New cost is the cost of the heuristic, plus the cost of the parent node, plus 1. cost = (self.heuristic(new_state) + node[0] + 1) self.frontier.append((cost, new_state))
def create_possibilites(self, node): """ Gets a list of possible new moves, makes sure they are not already in the list, applies heurstic and adds them :type node: (int, Flow) """ new_states = utils.generate_possible_moves_single_gp(node[1]) for new_state in new_states: if new_state not in [new_node[1] for new_node in self.frontier]: # New cost is the cost of the heuristic, plus the cost of the parent node, plus 1. cost = (self.heuristic(new_state) + node[0] + 1) self.frontier.append((cost, new_state))
def solve(self, initial_game_state): """ :type initial_game_state: Flow :return Flow: """ self.queue.put((astar().heuristic(initial_game_state), initial_game_state)) current_cost = 0 while self.queue._qsize() > 0: pop = self.queue.get() game = pop[1] current_cost += pop[0] # print current_cost if utils.at_goal(game): return game possible_moves = utils.generate_possible_moves_single_gp(game) for i, value in enumerate(possible_moves): # print possible_moves[i] self.queue.put((astar().heuristic(possible_moves[i]) + current_cost, possible_moves[i])) return None
def solve(self, initial_game_state): """ :type initial_game_state: Flow :return Flow: """ self.queue.put( (astar().heuristic(initial_game_state), initial_game_state)) current_cost = 0 while self.queue._qsize() > 0: pop = self.queue.get() game = pop[1] current_cost += pop[0] # print current_cost if utils.at_goal(game): return game possible_moves = utils.generate_possible_moves_single_gp(game) for i, value in enumerate(possible_moves): # print possible_moves[i] self.queue.put( (astar().heuristic(possible_moves[i]) + current_cost, possible_moves[i])) return None