refactor of model targets and constraints, addition of new constraint types and constraint construction process
This commit is contained in:
29
app/models/constraints/metadata_constraint.py
Normal file
29
app/models/constraints/metadata_constraint.py
Normal file
@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from models.constraints.generic_constraint import *
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models.solver_run import SolverRun
|
||||
|
||||
class MetadataConstraint(GenericConstraint):
|
||||
def build(self, problem_handler: Problem, **kwargs) -> None:
|
||||
logging.info('Metadata Constraint Generating...')
|
||||
|
||||
problem_handler.problem += lpSum(
|
||||
[
|
||||
len(bundle.items_with_attribute(self.reference_attribute)) * problem_handler.solver_bundles_var[bundle.id] for bundle in problem_handler.bundles
|
||||
] +
|
||||
[
|
||||
item.attribute_exists(self.reference_attribute).real * problem_handler.solver_items_var[item.id] for item in problem_handler.items
|
||||
]
|
||||
) >= round(kwargs['solver_run'].total_form_items * (self.minimum / 100)), f'{self.reference_attribute.id} - {self.reference_attribute.value} - min'
|
||||
|
||||
problem_handler.problem += lpSum(
|
||||
[
|
||||
len(bundle.items_with_attribute(self.reference_attribute)) * problem_handler.solver_bundles_var[bundle.id] for bundle in problem_handler.bundles
|
||||
] +
|
||||
[
|
||||
item.attribute_exists(self.reference_attribute).real * problem_handler.solver_items_var[item.id] for item in problem_handler.items
|
||||
]
|
||||
) <= round(kwargs['solver_run'].total_form_items * (self.maximum / 100)), f'{self.reference_attribute.id} - {self.reference_attribute.value} - max'
|
Reference in New Issue
Block a user