From 0e7a6c54aea05419f6e36ddb5ef2e6fd5b6abe76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Sat, 4 Mar 2023 12:04:49 +0100 Subject: [PATCH] Repartition: retry in case of bad assign --- repartir_taches/entrypoint.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/repartir_taches/entrypoint.py b/repartir_taches/entrypoint.py index 0b11802..1db9f23 100644 --- a/repartir_taches/entrypoint.py +++ b/repartir_taches/entrypoint.py @@ -47,7 +47,7 @@ class AssignError(Exception): def assigner_taches(root_task: Category | Task, group_count: int): - """Assigne les tâches aux groupes (round-robin)""" + """Assigne les tâches aux groupes (multiway number partitioning)""" TaskId = t.NewType("TaskId", int) UniqueTask: t.TypeAlias = tuple[TaskId, int] @@ -209,7 +209,23 @@ def main() -> None: if args.bare_tasks: util.write_to_file(args.bare_tasks, export_bare_tasks_md(config)) - groupes = repartition(config) + retry: int = 0 + MAX_RETRY: int = 4 + while retry < MAX_RETRY: + try: + groupes = repartition(config) + break + except AssignError as exn: + retry += 1 + logger.warning( + "[essai %d/%d] Échec de répartition des tâches : %s", + retry, + MAX_RETRY, + exn, + ) + if retry == MAX_RETRY: + logger.critical("Échec de répartition des tâches.") + raise exn from exn if args.to_tex: util.write_to_file(args.to_tex, export_latex(config, groupes))