refactor of model targets and constraints, addition of new constraint types and constraint construction process
This commit is contained in:
33
app/models/constraints/total_form_items_constraint.py
Normal file
33
app/models/constraints/total_form_items_constraint.py
Normal file
@ -0,0 +1,33 @@
|
||||
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 TotalFormItemsConstraint(GenericConstraint):
|
||||
@classmethod
|
||||
def create(cls: Type[_T], total_items: int) -> _T:
|
||||
return cls(
|
||||
minimum=0,
|
||||
maximum=0,
|
||||
reference_attribute=Attribute(
|
||||
value=total_items,
|
||||
type='form_uniqueness',
|
||||
id='form_uniqueness'
|
||||
)
|
||||
)
|
||||
|
||||
def build(self, problem_handler: Problem, **kwargs) -> None:
|
||||
logging.info('Total Form Items Constraint Generating...')
|
||||
|
||||
problem_handler.problem += lpSum(
|
||||
[
|
||||
bundle.count * problem_handler.solver_bundles_var[bundle.id]
|
||||
for bundle in problem_handler.bundles
|
||||
] + [
|
||||
1 * problem_handler.solver_items_var[item.id]
|
||||
for item in problem_handler.items
|
||||
]
|
||||
) == self.reference_attribute.value, f'Total bundle form items for form'
|
Reference in New Issue
Block a user