refactor create constraints for targets

This commit is contained in:
Joshua Burman
2023-11-10 18:39:16 -05:00
parent 6d3639a0c1
commit 1dbf672383
13 changed files with 92 additions and 260 deletions

View File

@ -1,15 +1,18 @@
from __future__ import annotations
from pydantic import BaseModel
from typing import Dict, List, AnyStr
from models.target import Target
from models.tif_target import TifTarget
from models.tcc_target import TccTarget
class ObjectiveFunction(BaseModel):
# minimizing tif/tcc target value is only option currently
# as we add more we can build this out to be more dynamic
# likely with models representing each objective function type
tif_targets: List[Target]
tcc_targets: List[Target]
tif_targets: List[TifTarget]
tcc_targets: List[TccTarget]
target_variance_percentage: int = 10
objective: AnyStr = "minimize"
weight: Dict = {'tif': 1, 'tcc': 1}
@ -18,7 +21,7 @@ class ObjectiveFunction(BaseModel):
limit: float or bool,
all: bool = False,
amount: float = 0.1,
targets: list[Target] = []) -> bool:
targets: list[TifTarget|TccTarget] = []) -> bool:
if all:
for target in self.tif_targets:
target.drift = round(target.drift + amount, 2)
@ -44,5 +47,5 @@ class ObjectiveFunction(BaseModel):
return minimum_drift
def all_targets(self) -> list[Target]:
def all_targets(self) -> list[TifTarget|TccTarget]:
return self.tif_targets + self.tcc_targets