From 4acb9545d451ad6275c343edfb7f21dcec1ccf40 Mon Sep 17 00:00:00 2001 From: Adrian Manteza Date: Tue, 22 Mar 2022 20:33:20 +0000 Subject: [PATCH] tweak the metadata constraints to always consider bundles --- app/helpers/solver_helper.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/helpers/solver_helper.py b/app/helpers/solver_helper.py index f6ea4e4..9e20be0 100644 --- a/app/helpers/solver_helper.py +++ b/app/helpers/solver_helper.py @@ -31,26 +31,24 @@ def build_constraints(solver_run: SolverRun, problem: LpProblem, boolean_to_int(item.attribute_exists(attribute)) for item in solver_run.items ])) + problem += lpSum( [ len(bundle.items_with_attribute(attribute)) * bundles[bundle.id] for bundle in solver_run.bundles ] + [ - con[item.id] * items[item.id] for item in solver_run.unbundled_items + con[item.id] * items[item.id] for item in solver_run.unbundled_items() ] - ) >= round( - total_form_items * - (min / 100)), f'{attribute.id} - {attribute.value} - min' - # problem += lpSum([ - # con[item.id] * items[item.id] for item in solver_run.items - # ]) >= round( - # total_form_items * - # (min / 100)), f'{attribute.id} - {attribute.value} - min' - problem += lpSum([ - con[item.id] * items[item.id] for item in solver_run.items - ]) <= round( - total_form_items * - (max / 100)), f'{attribute.id} - {attribute.value} - max' + ) >= round(total_form_items * (min / 100)), f'{attribute.id} - {attribute.value} - min' + + problem += lpSum( + [ + len(bundle.items_with_attribute(attribute)) * bundles[bundle.id] for bundle in solver_run.bundles + ] + + [ + con[item.id] * items[item.id] for item in solver_run.unbundled_items() + ] + ) <= round(total_form_items * (min / 100)), f'{attribute.id} - {attribute.value} - max' elif attribute.type == 'bundle': logging.info('Bundles Constraint Generating...') # TODO: account for many different bundle types, since the id condition in L33 could yield duplicates