domain-level constraints
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from physcom.models.combination import Combination
|
||||
from physcom.models.domain import DomainConstraint
|
||||
from physcom.models.entity import Dependency
|
||||
|
||||
|
||||
@@ -158,6 +159,25 @@ class ConstraintResolver:
|
||||
f"(under-density)"
|
||||
)
|
||||
|
||||
def check_domain_constraints(
|
||||
self, combination: Combination, constraints: list[DomainConstraint]
|
||||
) -> ConstraintResult:
|
||||
"""Check if a combo's entity requirements fall within domain-allowed values."""
|
||||
result = ConstraintResult()
|
||||
for dc in constraints:
|
||||
allowed = set(dc.allowed_values)
|
||||
for entity in combination.entities:
|
||||
for dep in entity.dependencies:
|
||||
if dep.key == dc.key and dep.constraint_type == "requires":
|
||||
if dep.value not in allowed:
|
||||
result.violations.append(
|
||||
f"{entity.name} requires {dc.key}={dep.value} "
|
||||
f"but domain only allows {dc.allowed_values}"
|
||||
)
|
||||
if result.violations:
|
||||
result.status = "p1_fail"
|
||||
return result
|
||||
|
||||
def _check_unmet_requirements(
|
||||
self, all_deps: list[tuple[str, Dependency]], result: ConstraintResult
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user