def solve(self, problem_instance, verbose=False, return_infos=False): """ Solve the given MAPF problem with the Cooperative A* algorithm and it returns, if exists, a solution. :param problem_instance: instance of the problem to solve. :param verbose: if True, infos will be printed on terminal. :param return_infos: if True in addition to the paths will be returned also a structure with output infos. :return the solution as list of paths, and, if return_infos is True, a tuple composed by the solution and a struct with output information. """ self._stop_event = Event() start = time.time() thread = Thread(target=self.solve_problem, args=( problem_instance, verbose, )) thread.start() thread.join(timeout=self._solver_settings.get_time_out()) self._stop_event.set() soc = calculate_soc(self._solution, self._solver_settings.stay_at_goal(), self._solver_settings.get_goal_occupation_time()) makespan = calculate_makespan( self._solution, self._solver_settings.stay_at_goal(), self._solver_settings.get_goal_occupation_time()) output_infos = self.generate_output_infos(soc, makespan, 0, 0, time.time() - start) if verbose: print("Problem ended: ", output_infos) return self._solution if not return_infos else (self._solution, output_infos)
def calculate_cost(self): """ Compute the cost of the solution based on the objective function we are minimizing. :return: """ if self._solver_settings.get_objective_function() == "SOC": return calculate_soc( self._solution, self._solver_settings.stay_at_goal(), self._solver_settings.get_goal_occupation_time()) if self._solver_settings.get_objective_function() == "Makespan": return calculate_makespan( self._solution, self._solver_settings.stay_at_goal(), self._solver_settings.get_goal_occupation_time())