close guardrail gaps and fix the scoring pipeline top to bottom
Constraint resolver: aggregate mass/footprint across a combo instead of pairwise-only checks, treat medium/atmosphere as agreement not supply/demand, reduce multi-provider checks by best/sum instead of AND-ing every provider, fail closed on unrecognized mutex values, add a propulsion-viability (thrust-to-weight) rule. Seed data updated to match (nuclear/solar-sail footprint floors, water-medium exclusions, explicit ground/gravity providers). Domain metric units were stored globally per metric name instead of per-domain, silently corrupting cost_efficiency for every domain but the first one seeded — fixed with a schema migration. Stub estimator's cost_efficiency/safety/availability/reliability were a backwards formula and flat constants; replaced with heuristics grounded in each entity's thrust_profile/energy_form/infrastructure. LLM estimate_physics() now receives each metric's unit and expected range instead of a bare name, fixing wildly miscalibrated estimates traced back to the prompt's own hardcoded example anchoring the model to the wrong order of magnitude. Sharpened the safety-estimation and plausibility-review prompts. Deduped provider parsing logic into llm/parsing.py. Web pipeline form can now pick an LLM provider per run instead of only via server env var. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,23 +16,42 @@ MUTEX_VALUES: dict[str, list[set[str]]] = {
|
||||
"medium": [{"ground"}, {"water"}, {"air"}, {"space"}],
|
||||
}
|
||||
|
||||
# Conditions assumed always available (don't need an explicit provides)
|
||||
# Conditions assumed always available (don't need an explicit provides).
|
||||
# ground_surface and gravity are deliberately NOT here — unlike star_proximity
|
||||
# (only relevant to space-adjacent entities) they're things most, but not all,
|
||||
# platforms actually have (a Spaceship in orbital freefall has neither in the
|
||||
# sense a ground-rolling actuator needs); those platforms must `provide` them.
|
||||
AMBIENT_CONDITIONS: set[tuple[str, str]] = {
|
||||
("ground_surface", "true"),
|
||||
("gravity", "true"),
|
||||
("star_proximity", "true"),
|
||||
("water_surface", "true"),
|
||||
}
|
||||
|
||||
# Per-category behavior for unmet requirements:
|
||||
# "block" = hard violation, "warn" = conditional warning, "skip" = ignore
|
||||
CATEGORY_SEVERITY: dict[str, str] = {
|
||||
"energy": "block",
|
||||
"environment": "block",
|
||||
"infrastructure": "skip",
|
||||
}
|
||||
|
||||
# For provides-vs-range_min: deficit > this ratio = hard block, else warning
|
||||
DEFICIT_THRESHOLD: float = 0.25
|
||||
|
||||
# How multiple entities' numbers on the same key combine into one system-level
|
||||
# number. "sum" = extensive (component contributions add into one vehicle);
|
||||
# any key not listed defaults to "max" (today's pairwise behavior — the
|
||||
# strongest/most-demanding single entity wins).
|
||||
KEY_AGGREGATION: dict[str, str] = {
|
||||
"mass": "sum",
|
||||
"footprint": "sum",
|
||||
}
|
||||
|
||||
# Sum-of-floors is an estimate built from independent component minima, not a
|
||||
# measurement. Overrun inside this band warns; beyond it blocks.
|
||||
# ponytail: single global tolerance; per-key band if mass and footprint ever
|
||||
# need different slack.
|
||||
OVERRUN_TOLERANCE: float = 0.10
|
||||
|
||||
|
||||
@dataclass
|
||||
class ConstraintResult:
|
||||
@@ -52,6 +71,8 @@ class ConstraintResolver:
|
||||
ambient_conditions=None,
|
||||
category_severity=None,
|
||||
deficit_threshold=None,
|
||||
key_aggregation=None,
|
||||
overrun_tolerance=None,
|
||||
) -> None:
|
||||
self.mutex = mutex_registry or MUTEX_VALUES
|
||||
self.ambient = ambient_conditions or AMBIENT_CONDITIONS
|
||||
@@ -59,6 +80,10 @@ class ConstraintResolver:
|
||||
self.deficit_threshold = (
|
||||
deficit_threshold if deficit_threshold is not None else DEFICIT_THRESHOLD
|
||||
)
|
||||
self.key_aggregation = key_aggregation or KEY_AGGREGATION
|
||||
self.overrun_tolerance = (
|
||||
overrun_tolerance if overrun_tolerance is not None else OVERRUN_TOLERANCE
|
||||
)
|
||||
|
||||
def resolve(self, combination: Combination) -> ConstraintResult:
|
||||
result = ConstraintResult()
|
||||
@@ -72,6 +97,7 @@ class ConstraintResolver:
|
||||
self._check_range_incompatibility(all_deps, result)
|
||||
self._check_provides_vs_range(combination, result)
|
||||
self._check_unmet_requirements(all_deps, result)
|
||||
self._check_propulsion_viability(combination, result)
|
||||
|
||||
if result.violations:
|
||||
result.status = "p1_fail"
|
||||
@@ -91,11 +117,24 @@ class ConstraintResolver:
|
||||
for exc_name, exc in excludes:
|
||||
if req_name == exc_name:
|
||||
continue
|
||||
if req.key == exc.key and req.value == exc.value:
|
||||
if req.key != exc.key:
|
||||
continue
|
||||
if req.value == exc.value:
|
||||
result.violations.append(
|
||||
f"{req_name} requires {req.key}={req.value} "
|
||||
f"but {exc_name} excludes it"
|
||||
)
|
||||
elif req.key in self.mutex:
|
||||
# Excluding one value in a mutex family excludes the
|
||||
# whole family (e.g. excludes atmosphere=standard also
|
||||
# rules out other "dense" values in the same set).
|
||||
exc_set = self._find_mutex_set(exc.key, exc.value)
|
||||
if exc_set is not None and req.value in exc_set:
|
||||
result.violations.append(
|
||||
f"{req_name} requires {req.key}={req.value} "
|
||||
f"but {exc_name} excludes {exc.key}={exc.value} "
|
||||
f"(same mutex family)"
|
||||
)
|
||||
|
||||
def _check_mutual_exclusion(
|
||||
self, all_deps: list[tuple[str, Dependency]], result: ConstraintResult
|
||||
@@ -111,11 +150,14 @@ class ConstraintResolver:
|
||||
continue
|
||||
if dep_a.value == dep_b.value:
|
||||
continue
|
||||
# Check if values are in different mutex sets
|
||||
# Check if values are in different mutex sets. An unrecognized
|
||||
# value (not in any registered set) is treated as conflicting
|
||||
# with any recognized value on the same key — fail closed
|
||||
# rather than silently letting unknown values through.
|
||||
if dep_a.key in self.mutex:
|
||||
set_a = self._find_mutex_set(dep_a.key, dep_a.value)
|
||||
set_b = self._find_mutex_set(dep_b.key, dep_b.value)
|
||||
if set_a is not None and set_b is not None and set_a is not set_b:
|
||||
if set_a is not set_b:
|
||||
result.violations.append(
|
||||
f"{name_a} requires {dep_a.key}={dep_a.value} "
|
||||
f"but {name_b} requires {dep_b.key}={dep_b.value} "
|
||||
@@ -132,7 +174,13 @@ class ConstraintResolver:
|
||||
def _check_range_incompatibility(
|
||||
self, all_deps: list[tuple[str, Dependency]], result: ConstraintResult
|
||||
) -> None:
|
||||
"""Rule 3: If A range_min > B range_max for the same key → BLOCKED."""
|
||||
"""Rule 3: floors on a key must fit under the tightest ceiling on that key.
|
||||
|
||||
Extensive keys ("sum" in key_aggregation) aggregate every entity's
|
||||
floor before the comparison, since they represent components sharing
|
||||
one physical vehicle (mass, footprint). Every other key keeps the
|
||||
original pairwise floor-vs-ceiling check.
|
||||
"""
|
||||
range_mins: dict[str, list[tuple[str, float]]] = {}
|
||||
range_maxs: dict[str, list[tuple[str, float]]] = {}
|
||||
|
||||
@@ -143,20 +191,43 @@ class ConstraintResolver:
|
||||
range_maxs.setdefault(dep.key, []).append((name, float(dep.value)))
|
||||
|
||||
for key in set(range_mins) & set(range_maxs):
|
||||
for min_name, min_val in range_mins[key]:
|
||||
for max_name, max_val in range_maxs[key]:
|
||||
if min_name == max_name:
|
||||
continue
|
||||
if min_val > max_val:
|
||||
result.violations.append(
|
||||
f"{min_name} requires {key} >= {min_val} "
|
||||
f"but {max_name} limits {key} <= {max_val}"
|
||||
)
|
||||
if self.key_aggregation.get(key) != "sum":
|
||||
for min_name, min_val in range_mins[key]:
|
||||
for max_name, max_val in range_maxs[key]:
|
||||
if min_name == max_name:
|
||||
continue
|
||||
if min_val > max_val:
|
||||
result.violations.append(
|
||||
f"{min_name} requires {key} >= {min_val} "
|
||||
f"but {max_name} limits {key} <= {max_val}"
|
||||
)
|
||||
continue
|
||||
|
||||
total = sum(val for _, val in range_mins[key])
|
||||
ceil_name, ceiling = min(range_maxs[key], key=lambda t: t[1])
|
||||
if total <= ceiling:
|
||||
continue
|
||||
parts = ", ".join(f"{name} {val:g}" for name, val in range_mins[key])
|
||||
msg = (
|
||||
f"combined {key} {total:g} ({parts}) exceeds "
|
||||
f"{ceil_name} limit of {ceiling:g}"
|
||||
)
|
||||
if total > ceiling * (1 + self.overrun_tolerance):
|
||||
result.violations.append(msg)
|
||||
else:
|
||||
result.warnings.append(msg)
|
||||
|
||||
def _check_provides_vs_range(
|
||||
self, combination: Combination, result: ConstraintResult
|
||||
) -> None:
|
||||
"""Generic: provides(key, N) < range_min(key, M) → block/warn."""
|
||||
"""Generic: provides(key, N) < range_min(key, M) → block/warn.
|
||||
|
||||
Multiple providers of the same key are reduced to one number before
|
||||
comparing: summed for extensive keys, otherwise the strongest single
|
||||
provider wins (a weak secondary source, e.g. backup solar panels
|
||||
alongside a nuclear reactor, must not drag down a combo that's
|
||||
already satisfied by its best provider).
|
||||
"""
|
||||
provided: dict[str, list[tuple[str, float]]] = {}
|
||||
required: dict[str, list[tuple[str, float]]] = {}
|
||||
|
||||
@@ -172,20 +243,25 @@ class ConstraintResolver:
|
||||
required.setdefault(dep.key, []).append((entity.name, val))
|
||||
|
||||
for key in set(provided) & set(required):
|
||||
if self.key_aggregation.get(key) == "sum":
|
||||
prov_name = " + ".join(name for name, _ in provided[key])
|
||||
prov_val = sum(val for _, val in provided[key])
|
||||
else:
|
||||
prov_name, prov_val = max(provided[key], key=lambda t: t[1])
|
||||
|
||||
for req_name, req_val in required[key]:
|
||||
for prov_name, prov_val in provided[key]:
|
||||
if prov_val < req_val * self.deficit_threshold:
|
||||
result.violations.append(
|
||||
f"{prov_name} provides {key}={prov_val:.0f} but "
|
||||
f"{req_name} requires {key}>={req_val:.0f} "
|
||||
f"(deficit > {int(1 / self.deficit_threshold)}x)"
|
||||
)
|
||||
elif prov_val < req_val:
|
||||
result.warnings.append(
|
||||
f"{prov_name} provides {key}={prov_val:.0f} but "
|
||||
f"{req_name} requires {key}>={req_val:.0f} "
|
||||
f"(under-provision)"
|
||||
)
|
||||
if prov_val < req_val * self.deficit_threshold:
|
||||
result.violations.append(
|
||||
f"{prov_name} provides {key}={prov_val:.0f} but "
|
||||
f"{req_name} requires {key}>={req_val:.0f} "
|
||||
f"(deficit > {int(1 / self.deficit_threshold)}x)"
|
||||
)
|
||||
elif prov_val < req_val:
|
||||
result.warnings.append(
|
||||
f"{prov_name} provides {key}={prov_val:.0f} but "
|
||||
f"{req_name} requires {key}>={req_val:.0f} "
|
||||
f"(under-provision)"
|
||||
)
|
||||
|
||||
def check_domain_constraints(
|
||||
self, combination: Combination, constraints: list[DomainConstraint]
|
||||
@@ -206,6 +282,86 @@ class ConstraintResolver:
|
||||
result.status = "p1_fail"
|
||||
return result
|
||||
|
||||
def _check_propulsion_viability(
|
||||
self, combination: Combination, result: ConstraintResult
|
||||
) -> None:
|
||||
"""Rule 6: an entity providing specific_thrust (N/kg of its own mass)
|
||||
must be able to mass enough, within the vehicle's mass budget, to
|
||||
accelerate the whole combo past the platform's min_effective_accel
|
||||
(m/s²) — the same physics whether that's overcoming rolling
|
||||
resistance or hovering against gravity, just different constants.
|
||||
|
||||
Skips silently if no entity declares min_effective_accel or no
|
||||
entity declares specific_thrust — this only fires where both
|
||||
numbers are actually known.
|
||||
"""
|
||||
min_accel = next(
|
||||
(
|
||||
float(dep.value)
|
||||
for entity in combination.entities
|
||||
for dep in entity.dependencies
|
||||
if dep.key == "min_effective_accel" and dep.constraint_type == "range_min"
|
||||
),
|
||||
None,
|
||||
)
|
||||
if min_accel is None:
|
||||
return
|
||||
|
||||
for actuator in combination.entities:
|
||||
specific_thrust = next(
|
||||
(
|
||||
float(dep.value)
|
||||
for dep in actuator.dependencies
|
||||
if dep.key == "specific_thrust" and dep.constraint_type == "provides"
|
||||
),
|
||||
None,
|
||||
)
|
||||
if specific_thrust is None:
|
||||
continue
|
||||
|
||||
other_mass = sum(
|
||||
float(dep.value)
|
||||
for entity in combination.entities
|
||||
if entity is not actuator
|
||||
for dep in entity.dependencies
|
||||
if dep.key == "mass" and dep.constraint_type == "range_min"
|
||||
)
|
||||
|
||||
if specific_thrust <= min_accel:
|
||||
result.violations.append(
|
||||
f"{actuator.name} specific thrust {specific_thrust:g} N/kg can "
|
||||
f"never exceed the {min_accel:g} m/s² minimum this vehicle "
|
||||
f"needs, regardless of scale"
|
||||
)
|
||||
continue
|
||||
|
||||
required_mass = min_accel * other_mass / (specific_thrust - min_accel)
|
||||
actuator_floor = next(
|
||||
(
|
||||
float(dep.value)
|
||||
for dep in actuator.dependencies
|
||||
if dep.key == "mass" and dep.constraint_type == "range_min"
|
||||
),
|
||||
0.0,
|
||||
)
|
||||
effective_mass = max(required_mass, actuator_floor)
|
||||
|
||||
ceiling = next(
|
||||
(
|
||||
float(dep.value)
|
||||
for entity in combination.entities
|
||||
for dep in entity.dependencies
|
||||
if dep.key == "mass" and dep.constraint_type == "range_max"
|
||||
),
|
||||
None,
|
||||
)
|
||||
if ceiling is not None and effective_mass + other_mass > ceiling:
|
||||
result.violations.append(
|
||||
f"{actuator.name} would need >= {effective_mass:.0f}kg to move "
|
||||
f"this vehicle at {min_accel:g} m/s², exceeding its "
|
||||
f"{ceiling:g}kg mass ceiling"
|
||||
)
|
||||
|
||||
def _check_unmet_requirements(
|
||||
self, all_deps: list[tuple[str, Dependency]], result: ConstraintResult
|
||||
) -> None:
|
||||
@@ -215,6 +371,11 @@ class ConstraintResolver:
|
||||
for name, dep in all_deps:
|
||||
if dep.constraint_type != "requires":
|
||||
continue
|
||||
if dep.key in self.mutex:
|
||||
# Agreement key (e.g. medium, atmosphere) — entities must
|
||||
# concur, not supply/demand. Rule 2 owns compatibility here;
|
||||
# no entity is expected to "provide" it.
|
||||
continue
|
||||
severity = self.category_severity.get(dep.category, "warn")
|
||||
if severity == "skip":
|
||||
continue
|
||||
|
||||
@@ -12,7 +12,113 @@ from physcom.engine.constraint_resolver import ConstraintResolver, ConstraintRes
|
||||
from physcom.engine.scorer import Scorer
|
||||
from physcom.llm.base import LLMProvider, LLMRateLimitError
|
||||
from physcom.models.combination import Combination, ScoredResult
|
||||
from physcom.models.domain import Domain
|
||||
from physcom.models.domain import Domain, MetricBound
|
||||
|
||||
# Stub-estimator heuristics (used only when no LLM provider is configured).
|
||||
# Keyed by the same categorical vocabulary already used in seed data — never
|
||||
# by entity name, so new entities inherit sensible behavior automatically.
|
||||
|
||||
# How controllable a thrust delivery profile is — bursty/extreme profiles are
|
||||
# harder to control and cost more per use (ammunition, propellant, wear) than
|
||||
# steady ones. Missing values fall back to a neutral 1.0/0.6.
|
||||
THRUST_PROFILE_COST_MULTIPLIER: dict[str, float] = {
|
||||
"low_continuous": 1.0,
|
||||
"continuous_low": 1.0,
|
||||
"moderate_continuous": 1.1,
|
||||
"high_continuous": 1.3,
|
||||
"extreme_continuous": 1.6,
|
||||
"high_burst": 2.5,
|
||||
"extreme_burst": 4.0,
|
||||
}
|
||||
THRUST_PROFILE_SAFETY: dict[str, float] = {
|
||||
"low_continuous": 0.9,
|
||||
"continuous_low": 0.9,
|
||||
"moderate_continuous": 0.75,
|
||||
"high_continuous": 0.6,
|
||||
"extreme_continuous": 0.45,
|
||||
"high_burst": 0.3,
|
||||
"extreme_burst": 0.15,
|
||||
}
|
||||
|
||||
# Baseline hazard of the energy form itself, independent of delivery profile.
|
||||
ENERGY_FORM_SAFETY: dict[str, float] = {
|
||||
"biological": 0.9,
|
||||
"electrical": 0.85,
|
||||
"wind": 0.9,
|
||||
"gravitational": 0.9,
|
||||
"radiation_pressure": 0.85,
|
||||
"kinetic_stored": 0.7,
|
||||
"pneumatic": 0.75,
|
||||
"chemical_combustible": 0.6,
|
||||
"ion_propellant": 0.75,
|
||||
"chemical_propellant": 0.4,
|
||||
"chemical_explosive": 0.3,
|
||||
"nuclear_thermal": 0.35,
|
||||
}
|
||||
|
||||
# Rough $/m base cost by energy form — renewables/muscle power are ~free,
|
||||
# consumables (propellant, ammunition, nuclear fuel) cost real money per use.
|
||||
# This is a categorical placeholder, not a physics formula — energy_density
|
||||
# (J/kg) can't give a $/m figure on its own since it says nothing about price.
|
||||
ENERGY_FORM_BASE_COST: dict[str, float] = {
|
||||
"wind": 1e-6,
|
||||
"gravitational": 1e-6,
|
||||
"radiation_pressure": 1e-6,
|
||||
"electrical": 3e-5,
|
||||
"kinetic_stored": 2e-5,
|
||||
"biological": 5e-5,
|
||||
"pneumatic": 4e-5,
|
||||
"chemical_combustible": 8e-5,
|
||||
"nuclear_thermal": 1e-3,
|
||||
"ion_propellant": 2e-3,
|
||||
"chemical_propellant": 5e-3,
|
||||
"chemical_explosive": 8e-3,
|
||||
}
|
||||
|
||||
# How available the required infrastructure/fuel supply chain is today.
|
||||
# Multiple matches in one combo (e.g. a platform's road_network requirement
|
||||
# plus a storage's fuel_infrastructure requirement) are averaged.
|
||||
INFRASTRUCTURE_AVAILABILITY: dict[tuple[str, str], float] = {
|
||||
("road_network", "true"): 0.95,
|
||||
("rail_network", "true"): 0.8,
|
||||
("runway", "true"): 0.5,
|
||||
("tow_or_winch", "true"): 0.5,
|
||||
("hyperloop_tube", "true"): 0.1,
|
||||
("launch_facility", "true"): 0.05,
|
||||
("fuel_infrastructure", "none"): 1.0,
|
||||
("fuel_infrastructure", "fuel_station"): 0.95,
|
||||
("fuel_infrastructure", "charging_station"): 0.85,
|
||||
("fuel_infrastructure", "cng_station"): 0.5,
|
||||
("fuel_infrastructure", "coal_supply"): 0.5,
|
||||
("fuel_infrastructure", "hydrogen_station"): 0.25,
|
||||
("fuel_infrastructure", "compressed_air_station"): 0.3,
|
||||
("fuel_infrastructure", "ammunition"): 0.3,
|
||||
("fuel_infrastructure", "jet_fuel"): 0.6,
|
||||
("fuel_infrastructure", "solid_propellant"): 0.15,
|
||||
("fuel_infrastructure", "nuclear_fuel"): 0.05,
|
||||
("fuel_infrastructure", "xenon_propellant"): 0.05,
|
||||
}
|
||||
|
||||
# Crude freight-capacity proxy: kg of cargo per kg of vehicle structural mass.
|
||||
CARGO_KG_PER_STRUCTURAL_KG: float = 500
|
||||
|
||||
# How mechanically proven/predictable an energy form is in practice — distinct
|
||||
# from safety (risk when something goes wrong) and thrust_profile (delivery
|
||||
# smoothness). Missing values fall back to a neutral 0.6.
|
||||
ENERGY_FORM_RELIABILITY: dict[str, float] = {
|
||||
"chemical_combustible": 0.85,
|
||||
"electrical": 0.85,
|
||||
"biological": 0.8,
|
||||
"gravitational": 0.7,
|
||||
"pneumatic": 0.7,
|
||||
"kinetic_stored": 0.65,
|
||||
"wind": 0.6,
|
||||
"ion_propellant": 0.6,
|
||||
"nuclear_thermal": 0.55,
|
||||
"chemical_propellant": 0.5,
|
||||
"radiation_pressure": 0.5,
|
||||
"chemical_explosive": 0.45,
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -124,7 +230,6 @@ class Pipeline:
|
||||
self.repo.update_pipeline_run(run_id, total_combos=len(combos))
|
||||
|
||||
# Prepare metric lookup
|
||||
metric_names = [mb.metric_name for mb in domain.metric_bounds]
|
||||
bounds_by_name = {mb.metric_name: mb for mb in domain.metric_bounds}
|
||||
|
||||
# ── Combo-first loop ─────────────────────────────────────
|
||||
@@ -212,10 +317,10 @@ class Pipeline:
|
||||
description = _describe_combination(combo)
|
||||
if self.llm:
|
||||
raw_metrics = self.llm.estimate_physics(
|
||||
description, metric_names
|
||||
description, domain.metric_bounds
|
||||
)
|
||||
else:
|
||||
raw_metrics = self._stub_estimate(combo, metric_names)
|
||||
raw_metrics = self._stub_estimate(combo, domain.metric_bounds)
|
||||
|
||||
# Save raw estimates immediately (crash-safe)
|
||||
estimate_dicts = []
|
||||
@@ -435,15 +540,32 @@ class Pipeline:
|
||||
self.repo.update_pipeline_run(run_id, status="running")
|
||||
|
||||
def _stub_estimate(
|
||||
self, combo: Combination, metric_names: list[str]
|
||||
self, combo: Combination, metric_bounds: list[MetricBound]
|
||||
) -> dict[str, float]:
|
||||
"""Simple heuristic estimation from dependency data (all values in SI base units)."""
|
||||
"""Simple heuristic estimation from dependency data (all values in SI base units).
|
||||
|
||||
cost_efficiency/safety/availability/reliability are driven by the
|
||||
actuator's thrust_profile and energy_form and the combo's
|
||||
infrastructure requirements — categorical properties every entity
|
||||
already declares — rather than flat constants or a formula that
|
||||
conflates power_density (W/kg, intensive) with cost.
|
||||
|
||||
cost_efficiency additionally checks the domain's declared unit:
|
||||
"$/(kg·m)" (freight-style domains) isn't a rescaling of "$/m" — it's
|
||||
a different quantity that needs dividing by cargo mass, not a
|
||||
conversion factor.
|
||||
"""
|
||||
metric_names = [mb.metric_name for mb in metric_bounds]
|
||||
units_by_name = {mb.metric_name: mb.unit for mb in metric_bounds}
|
||||
raw: dict[str, float] = {m: 0.0 for m in metric_names}
|
||||
|
||||
# Extract intrinsic properties from entities
|
||||
power_density = 0.0 # W/kg
|
||||
energy_density = 0.0 # J/kg
|
||||
mass = 100.0 # kg, default
|
||||
mass_total = 0.0 # kg, extensive — components share one vehicle
|
||||
thrust_profile: str | None = None
|
||||
energy_form: str | None = None
|
||||
infra_matches: list[float] = []
|
||||
for entity in combo.entities:
|
||||
for dep in entity.dependencies:
|
||||
if dep.key == "power_density" and dep.constraint_type == "provides":
|
||||
@@ -451,19 +573,44 @@ class Pipeline:
|
||||
if dep.key == "energy_density" and dep.constraint_type == "provides":
|
||||
energy_density = max(energy_density, float(dep.value))
|
||||
if dep.key == "mass" and dep.constraint_type == "range_min":
|
||||
mass = max(mass, float(dep.value))
|
||||
mass_total += float(dep.value)
|
||||
if dep.key == "thrust_profile" and dep.constraint_type == "provides":
|
||||
thrust_profile = dep.value
|
||||
if dep.key == "energy_form" and dep.constraint_type == "requires":
|
||||
energy_form = dep.value
|
||||
if dep.category == "infrastructure" and dep.constraint_type == "requires":
|
||||
match = INFRASTRUCTURE_AVAILABILITY.get((dep.key, dep.value))
|
||||
if match is not None:
|
||||
infra_matches.append(match)
|
||||
mass = mass_total if mass_total > 0 else 100.0 # kg, default if undeclared
|
||||
cargo_capacity_kg = mass * CARGO_KG_PER_STRUCTURAL_KG
|
||||
|
||||
if "power_density" in raw:
|
||||
raw["power_density"] = power_density
|
||||
|
||||
if "cost_efficiency" in raw:
|
||||
raw["cost_efficiency"] = max(1e-5, 2e-3 - power_density / 1e6)
|
||||
base_cost = ENERGY_FORM_BASE_COST.get(energy_form, 5e-4)
|
||||
cost_mult = THRUST_PROFILE_COST_MULTIPLIER.get(thrust_profile, 1.0)
|
||||
cost_per_meter = base_cost * cost_mult
|
||||
if units_by_name.get("cost_efficiency") == "$/(kg·m)":
|
||||
raw["cost_efficiency"] = cost_per_meter / max(cargo_capacity_kg, 1.0)
|
||||
else:
|
||||
raw["cost_efficiency"] = cost_per_meter
|
||||
|
||||
if "safety" in raw:
|
||||
raw["safety"] = 0.5
|
||||
candidates = [
|
||||
v for v in (
|
||||
THRUST_PROFILE_SAFETY.get(thrust_profile),
|
||||
ENERGY_FORM_SAFETY.get(energy_form),
|
||||
)
|
||||
if v is not None
|
||||
]
|
||||
raw["safety"] = min(candidates) if candidates else 0.6
|
||||
|
||||
if "availability" in raw:
|
||||
raw["availability"] = 0.5
|
||||
raw["availability"] = (
|
||||
sum(infra_matches) / len(infra_matches) if infra_matches else 0.5
|
||||
)
|
||||
|
||||
if "range_fuel" in raw:
|
||||
raw["range_fuel"] = min(energy_density * 2.78, 1e13)
|
||||
@@ -472,7 +619,7 @@ class Pipeline:
|
||||
raw["range_degradation"] = 365 * 86400
|
||||
|
||||
if "cargo_capacity" in raw:
|
||||
raw["cargo_capacity"] = mass * 500
|
||||
raw["cargo_capacity"] = cargo_capacity_kg
|
||||
|
||||
if "cargo_capacity_kg" in raw:
|
||||
raw["cargo_capacity_kg"] = mass * 0.3
|
||||
@@ -481,6 +628,6 @@ class Pipeline:
|
||||
raw["environmental_impact"] = max(0.0, power_density * 2e-7)
|
||||
|
||||
if "reliability" in raw:
|
||||
raw["reliability"] = 0.5
|
||||
raw["reliability"] = ENERGY_FORM_RELIABILITY.get(energy_form, 0.6)
|
||||
|
||||
return raw
|
||||
|
||||
Reference in New Issue
Block a user