anyoptimization / pymoo

NSGA2, NSGA3, R-NSGA3, MOEAD, Genetic Algorithms (GA), Differential Evolution (DE), CMAES, PSO
https://pymoo.org
Apache License 2.0
2.27k stars 390 forks source link

Time based termination not working #640

Open acheong08 opened 1 month ago

acheong08 commented 1 month ago

if __name__ == "__main__":

    initial_solution = actions_to_np(get_solution(f"merged/{SEED}.json"))
    algorithm = PatternSearch(x0=initial_solution)
    np.random.seed(2281)
    demand = get_demand()
    problem = MyProblem(demand)
    termination = get_termination("time", 1)
    res: None | Any = minimize(problem, algorithm, termination, verbose=True)  # type: ignore[reportUnknownVariableType]
    if res is None or res.X is None:
        print("No solution found")
        exit()
    best_solution = problem.decode_actions(res.X)
    best_score = Evaluator(
        best_solution, demand, SERVER_MAP, DATACENTER_MAP, SELLING_PRICES_MAP
    ).get_score()
    print(f"Best score: {best_score}")

This doesn't terminate. Swapping the value to 0.x terminates instantly.

blankjul commented 1 month ago

Does providing the full string solve this issue?

termination = get_termination("time", "00:00:03")