irt-service/app/models/constraints/bundle_constraint.py

16 lines
800 B
Python

from random import randint
from models.constraints.generic_constraint import *
class BundleConstraint(GenericConstraint):
def build(self, problem_handler: Problem, **kwargs) -> 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'