def __make_node(self, state: State, env_conf: EnvironmentConfiguration): name = state.get_current_vertex_name() vertex = env_conf.get_vertexes()[name] vertex.set_state(state) vertex.set_cost( len(state.get_required_vertexes()) - sum(state.get_required_vertexes().values())) return vertex
def get_saved_people_num(state: State, current_traveled_states, env_conf: EnvironmentConfiguration) -> List[int]: score = 0 traveled_vertexes = [vertex_name for vertex_name in StateUtils.get_state_traveled_vertexes(state) if vertex_name not in current_traveled_states] current_traveled_states.append(state.get_current_vertex_name()) vertexes_dict = env_conf.get_vertexes() for vertex in traveled_vertexes: score += vertexes_dict[vertex].get_people_num() return score
def get_possible_moves(current_state: State, env_config: EnvironmentConfiguration) -> List[Edge]: current_vertex_name = current_state.get_current_vertex_name() vertexes_dict = env_config.get_vertexes() edges_dict = {k: v for k, v in env_config.get_edges().items() if k not in env_config.get_blocked_edges()} current_vertex = vertexes_dict[current_vertex_name] names_of_edges = [edge for edge in current_vertex.get_edges() if edge not in env_config.get_blocked_edges()] possible_edges = [] for edge_name in names_of_edges: possible_edges.append(edges_dict[edge_name]) return possible_edges
def update_func(self, agent: IAgent, action: str, current_state: State, costs_info: Tuple[List, int], env_conf: EnvironmentConfiguration): vertex = env_conf.get_vertexes()[current_state.get_current_vertex_name()] vertex.set_state(current_state) new_state = EnvironmentUtils.get_next_vertex(vertex, action, agent.step_cost, env_conf).get_state() new_state.set_visited_vertex(new_state.get_current_vertex_name()) costs, agent_num = costs_info edges_dict = env_conf.get_edges() if action in edges_dict.keys(): costs[agent_num] += edges_dict[action].get_weight() return new_state
def __result(self, action: str, state: State, is_max: bool, env_config: EnvironmentConfiguration) -> State: """ :param action: edge name :param state: current state :return: next state after moving on edge action from the given state """ next_vertex = env_config.get_vertexes()[ state.get_current_vertex_name()] next_vertex.set_state(state) return EnvironmentUtils.get_next_vertex(next_vertex, action, self.step_cost, env_config, is_max).get_state()