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:
|
||||
|
||||
@@ -164,6 +164,26 @@ class Pipeline:
|
||||
else:
|
||||
combo.status = "valid"
|
||||
self.repo.update_combination_status(combo.id, "valid")
|
||||
|
||||
# Domain constraint check (per-domain block only)
|
||||
if domain.constraints:
|
||||
dc_result = self.resolver.check_domain_constraints(
|
||||
combo, domain.constraints
|
||||
)
|
||||
if dc_result.status == "p1_fail":
|
||||
self.repo.save_result(
|
||||
combo.id, domain.id,
|
||||
composite_score=0.0, pass_reached=1,
|
||||
domain_block_reason="; ".join(
|
||||
dc_result.violations
|
||||
),
|
||||
)
|
||||
result.pass1_failed += 1
|
||||
self._update_run_counters(
|
||||
run_id, result, current_pass=1
|
||||
)
|
||||
continue
|
||||
|
||||
if cr.status == "conditional":
|
||||
result.pass1_conditional += 1
|
||||
else:
|
||||
@@ -175,8 +195,11 @@ class Pipeline:
|
||||
if combo.status.endswith("_fail"):
|
||||
result.pass1_failed += 1
|
||||
continue
|
||||
else:
|
||||
result.pass1_valid += 1
|
||||
# Check if domain-blocked from a prior run
|
||||
if existing_result and existing_result["pass_reached"] == 1:
|
||||
result.pass1_failed += 1
|
||||
continue
|
||||
result.pass1_valid += 1
|
||||
else:
|
||||
# Pass 1 not requested; check if failed from a prior run
|
||||
if combo.status.endswith("_fail"):
|
||||
|
||||
Reference in New Issue
Block a user