irt-service/app/models/bundle_constraint.py
2023-11-10 18:39:16 -05:00

16 lines
766 B
Python

from random import randint
from models.constraint import *
class BundleConstraint(Constraint):
def build(self, problem_handler: Problem, _) -> None:
logging.info('Bundles Constraint Generating...')
# TODO: account for many different bundle types, since the id condition in L33 could yield duplicates
if problem_handler.bundles != None and len(problem_handler.bundles) > 0:
# make sure the total bundles used in generated form is limited between min-max set
problem_handler.problem += lpSum([
problem_handler.solver_bundles_var[bundle.id] for bundle in problem_handler.bundles
]) == randint(int(self.minimum),
int(self.maximum)), f'Allowing min - max bundles'