randomize source bundles and items before each solver run
This commit is contained in:
@ -12,7 +12,7 @@ from models.item import Item
|
||||
from lib.errors.item_generation_error import ItemGenerationError
|
||||
|
||||
def build_constraints(solver_run: SolverRun, problem: LpProblem,
|
||||
items: list[Item], bundles: list[Bundle]) -> LpProblem:
|
||||
items: list[Item], bundles: list[Bundle], selected_items, selected_bundles) -> LpProblem:
|
||||
logging.info('Creating Constraints...')
|
||||
|
||||
try:
|
||||
@ -29,28 +29,28 @@ def build_constraints(solver_run: SolverRun, problem: LpProblem,
|
||||
|
||||
problem += lpSum(
|
||||
[
|
||||
len(bundle.items_with_attribute(attribute)) * bundles[bundle.id] for bundle in solver_run.bundles
|
||||
len(bundle.items_with_attribute(attribute)) * bundles[bundle.id] for bundle in selected_bundles
|
||||
] +
|
||||
[
|
||||
item.attribute_exists(attribute).real * items[item.id] for item in solver_run.unbundled_items()
|
||||
item.attribute_exists(attribute).real * items[item.id] for item in selected_items
|
||||
]
|
||||
) >= 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
|
||||
len(bundle.items_with_attribute(attribute)) * bundles[bundle.id] for bundle in selected_bundles
|
||||
] +
|
||||
[
|
||||
item.attribute_exists(attribute).real * items[item.id] for item in solver_run.unbundled_items()
|
||||
item.attribute_exists(attribute).real * items[item.id] for item in selected_items
|
||||
]
|
||||
) <= round(total_form_items * (max / 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
|
||||
if solver_run.bundles != None:
|
||||
if selected_bundles != None:
|
||||
# make sure the total bundles used in generated form is limited between min-max set
|
||||
problem += lpSum([
|
||||
bundles[bundle.id] for bundle in solver_run.bundles
|
||||
bundles[bundle.id] for bundle in selected_bundles
|
||||
]) == randint(int(constraint.minimum),
|
||||
int(constraint.maximum))
|
||||
|
||||
|
Reference in New Issue
Block a user