From eef86369ab87ef7fc566d4f147e6988b28f2acb5 Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Wed, 15 Nov 2023 11:14:35 -0500 Subject: [PATCH] handle n enemy cleansing runs --- app/models/problem.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/problem.py b/app/models/problem.py index fac4dec..879e10c 100644 --- a/app/models/problem.py +++ b/app/models/problem.py @@ -41,7 +41,7 @@ class Problem(BaseModel): upBound=1, cat='Binary') - def solve(self, solver_run: SolverRun) -> LpProblem: + def solve(self, solver_run: SolverRun, enemy_ids: List[int] = []) -> LpProblem: logging.info('solving problem...') # if we allow enemies, go through the normal solving process if solver_run.allow_enemies: @@ -60,11 +60,17 @@ class Problem(BaseModel): # get items from solution solved_items, _ = service_helper.solution_items(self.problem.variables(), solver_run) - sacred_ids, enemy_ids = sanctify(solved_items) + # sacred items will remain the same between solve attempts + # but new enemies will be appended + sacred_ids, new_enemy_ids = sanctify(solved_items) - if enemy_ids: + # the current solve run found new enemies + if new_enemy_ids: logging.info('enemies found, adding constraints...') + # append the new enemies to the enemies_id list + enemy_ids = list(set(enemy_ids+new_enemy_ids)) + # remove old enemy/sacred constraints if 'Exclude_enemy_items' in self.problem.constraints.keys(): self.problem.constraints.pop('Exclude_enemy_items') if 'Include_sacred_items' in self.problem.constraints.keys(): self.problem.constraints.pop('Include_sacred_items')