consolidate constraint types into single type var
This commit is contained in:
parent
eef86369ab
commit
5b4387a04b
app/models
@ -60,7 +60,7 @@ class Problem(BaseModel):
|
||||
# get items from solution
|
||||
solved_items, _ = service_helper.solution_items(self.problem.variables(), solver_run)
|
||||
|
||||
# sacred items will remain the same between solve attempts
|
||||
# sacred items will remain the same (with new items added each run) between solve attempts
|
||||
# but new enemies will be appended
|
||||
sacred_ids, new_enemy_ids = sanctify(solved_items)
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from typing import TYPE_CHECKING, List, Literal, Optional, Union, TypeVar
|
||||
from pulp import lpSum
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
@ -22,11 +21,13 @@ if TYPE_CHECKING:
|
||||
from models.solution import Solution
|
||||
from models.problem import Problem
|
||||
|
||||
ConstraintType = TypeVar('ConstraintType', bound=GenericConstraint)
|
||||
|
||||
class SolverRun(BaseModel):
|
||||
items: List[Item] = []
|
||||
bundles: List[Bundle] = []
|
||||
bundle_first_ordering: bool = True
|
||||
constraints: List[Union[GenericConstraint, MetadataConstraint, BundleConstraint, FormUniquenessConstraint, TotalFormItemsConstraint]]
|
||||
constraints: List[ConstraintType]
|
||||
irt_model: IRTModel
|
||||
objective_function: ObjectiveFunction
|
||||
total_form_items: int
|
||||
@ -42,7 +43,7 @@ class SolverRun(BaseModel):
|
||||
|
||||
# this is all a compensator for dynamically creating objects
|
||||
# ideally we'd change the payload to determine what type it is
|
||||
constraints: [GenericConstraint|MetadataConstraint|BundleConstraint|FormUniquenessConstraint|TotalFormItemsConstraint] = []
|
||||
constraints: [ConstraintType] = []
|
||||
|
||||
# total form items
|
||||
constraints.append(TotalFormItemsConstraint.create(self.total_form_items))
|
||||
@ -70,7 +71,7 @@ class SolverRun(BaseModel):
|
||||
if bundle.id == bundle_id:
|
||||
return bundle
|
||||
|
||||
def get_constraint_by_type(self, type: str) -> GenericConstraint|MetadataConstraint|BundleConstraint|FormUniquenessConstraint|TotalFormItemsConstraint or None:
|
||||
def get_constraint_by_type(self, type: str) -> ConstraintType or None:
|
||||
for constraint in self.constraints:
|
||||
if type == constraint.reference_attribute.type:
|
||||
return constraint
|
||||
@ -131,7 +132,7 @@ class SolverRun(BaseModel):
|
||||
|
||||
logging.info('Bundles Generated...')
|
||||
|
||||
def get_constraint(self, name: str) -> GenericConstraint|MetadataConstraint|BundleConstraint|FormUniquenessConstraint|TotalFormItemsConstraint:
|
||||
def get_constraint(self, name: str) -> ConstraintType:
|
||||
return next((constraint for constraint in self.constraints
|
||||
if constraint.reference_attribute.id == name), None)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user