From 533f83e2c6bfa7494e3a7fbf5b34376d57475d86 Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Fri, 17 Nov 2023 19:17:43 -0500 Subject: [PATCH] addition of max attempts limit --- app/models/solver_run.py | 1 + app/services/form_generation_service.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/solver_run.py b/app/models/solver_run.py index 2d486dd..85f015f 100644 --- a/app/models/solver_run.py +++ b/app/models/solver_run.py @@ -36,6 +36,7 @@ class SolverRun(BaseModel): theta_cut_score: float = 0.00 drift_style: Literal['constant', 'variable'] = 'constant' allow_enemies: bool = False + max_attempts: int advanced_options: Optional[AdvancedOptions] engine: str diff --git a/app/services/form_generation_service.py b/app/services/form_generation_service.py index 49d67fc..9994700 100644 --- a/app/services/form_generation_service.py +++ b/app/services/form_generation_service.py @@ -72,10 +72,13 @@ class FormGenerationService(Base): for form_count in range(self.solver_run.total_forms): form_number = form_count + 1 current_drift = 0 # FF Tokyo Drift + current_attempt = 0 logging.info(f'Generating Solution for Form {form_number} using the {self.solver_run.irt_model.model} IRT model') - while current_drift <= Target.max_drift(): + # respect max attempts + # this will likely be more built out when we add increment rate & drif limit + while current_drift <= Target.max_drift() or current_attempt <= self.solver_run.max_attempts: drift_percent = current_drift / 100 self.solver_run.objective_function.update_targets_drift( drift_percent) @@ -91,7 +94,7 @@ class FormGenerationService(Base): f'attempt infeasible for drift of {current_drift}%') if current_drift >= Target.max_drift( - ): # this is the last attempt, so lets finalize the solution + ) or current_attempt >= self.solver_run.max_attempts: # this is the last attempt, so lets finalize the solution if ApplicationConfigs.local_dev_env: service_helper.print_problem_variables(problem) @@ -105,6 +108,7 @@ class FormGenerationService(Base): break current_drift += Target.max_drift_increment() + current_attempt += 1 else: if ApplicationConfigs.local_dev_env: service_helper.print_problem_variables(problem)