From c7c966296816ec466d276b308aabde349d5a41e6 Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Wed, 15 Dec 2021 20:44:24 +0000 Subject: [PATCH] genericize this! --- app/helpers/solver_helper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/helpers/solver_helper.py b/app/helpers/solver_helper.py index abd0c3f..bce804f 100644 --- a/app/helpers/solver_helper.py +++ b/app/helpers/solver_helper.py @@ -21,13 +21,12 @@ def build_constraints(solver_run, problem, items): * items[item.id] for item in solver_run.items]) <= round(total_form_items * (max / 100)), f'{attribute.id} - {attribute.value} - max' elif attribute.type == 'bundle': - # currently only using passage bundles, but will eventually make more dynamic for many bundle types - bundles = solver_run.bundles('passage') + bundles = solver_run.bundles(attribute.id) total_bundles = randint(constraint.minimum, constraint.maximum) selected_bundles = sample(bundles, total_bundles) for bundle in selected_bundles: - problem += lpSum([items[item.id] for item in solver_run.items if item.passage == bundle['id']]) == bundle['count'], f'Bundle constraint for {bundle["type"]} ({bundle["id"]})' + problem += lpSum([items[item.id] for item in solver_run.items if getattr(item, bundle["type"], None) == bundle['id']]) == bundle['count'], f'Bundle constraint for {bundle["type"]} ({bundle["id"]})' return problem