urban_commuting: mission requirements, maintenance, cruise-speed decision
Some checks failed
tests / pytest (3.11) (push) Has been cancelled
tests / pytest (3.13) (push) Has been cancelled

- ratio-log normalization (scale-invariant) replacing log1p
- domain requirements (payload, trip_range) as hard mission constraints
- platform payload_ratio, rotorcraft hover floor (min_specific_power)
- maintenance_multiple + service_life folded into cost per metre
- cruise speed searched between domain speed floor and build top speed
- default-deny "domain" requires: Wind Sail / Gravity Coast need the
  domain to declare prevailing_wind / net_descent
- LOGIC DOCS/004: cost per passenger and infrastructure cost, tabled

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-09-25 23:12:36 -05:00
parent af401d6bc2
commit 60c36e5d27
12 changed files with 421 additions and 178 deletions

View File

@@ -388,3 +388,17 @@ def test_agreement_key_reaches_valid_status(bicycle, human_pedalling, food_calor
result = resolver.resolve(Combination(entities=[bicycle, human_pedalling, food_calories]))
assert result.status == "valid"
assert not any("medium" in w for w in result.warnings)
def test_domain_requirement_is_default_deny():
"""A "domain"-category requires fails unless the domain declares that key."""
resolver = ConstraintResolver()
sail = Entity(name="Wind Sail", dimension="actuator", dependencies=[
Dependency("domain", "prevailing_wind", "true", None, "requires"),
])
combo = Combination(entities=[sail])
medium_only = [DomainConstraint("medium", ["ground"])]
assert resolver.check_domain_constraints(combo, medium_only).status == "p1_fail"
windy = medium_only + [DomainConstraint("prevailing_wind", ["true"])]
assert resolver.check_domain_constraints(combo, windy).status != "p1_fail"
assert resolver.resolve(combo).warnings == []

View File

@@ -75,3 +75,32 @@ def test_blocked_combos_not_scored(seeded_repo):
# block, not a bug (see Pipeline._decide_masses' `feasible` return).
assert result.pass2_estimated < result.total_generated
assert result.pass2_estimated <= result.pass1_valid + result.pass1_conditional
def test_hover_floor_and_mission_payload_are_hard(seeded_repo):
"""Rotorcraft must keep >= its min_specific_power at the build the
optimizer actually picks (payload included), and an actuator that can
never reach it is infeasible rather than silently floored."""
from physcom.models.combination import Combination
from physcom.engine.pipeline import _carried_payload
domain = seeded_repo.get_domain("urban_commuting")
assert domain.requirements == {"payload": 100.0, "trip_range": 50000.0}
bounds = {mb.metric_name: mb for mb in domain.metric_bounds}
units = {mb.metric_name: mb.unit for mb in domain.metric_bounds}
pipeline = Pipeline(seeded_repo, ConstraintResolver(), Scorer(domain))
rotor = seeded_repo.get_entity_by_name("platform", "Rotorcraft")
fuel = seeded_repo.get_entity_by_name("energy_storage", "Liquid Fuel")
piston = seeded_repo.get_entity_by_name("actuator", "Piston Engine")
ctx = pipeline._physics_context(Combination(entities=[rotor, piston, fuel]), bounds, domain.requirements)
a, s, p, feasible = pipeline._decide_masses(ctx, bounds, units)
gross = p + a + s + _carried_payload(ctx, a)
assert feasible
assert ctx.k_act * a / gross >= 140.0 - 1e-6
raw = pipeline._raw_physics_from_masses(ctx, a, s, bounds, units, platform_mass=p)
assert raw["range_fuel"] >= 50000.0
steam = seeded_repo.get_entity_by_name("actuator", "Steam Engine")
ctx = pipeline._physics_context(Combination(entities=[rotor, steam, fuel]), bounds, domain.requirements)
assert pipeline._decide_masses(ctx, bounds, units)[3] is False

View File

@@ -37,9 +37,13 @@ class TestNormalize:
assert normalize(50.0, 100.0, 50.0) == 0.0
def test_zero_min(self):
"""norm_min=0 should work (log1p(0)=0)."""
result = normalize(0.5, 0.0, 1.0)
assert 0.0 < result < 1.0
"""norm_min=0 has no ratio to log -- falls back to linear."""
assert normalize(0.5, 0.0, 1.0) == 0.5
def test_scale_invariant(self):
"""Same ratio within the range -> same score, whatever the magnitude."""
assert abs(normalize(1e-4, 1e-5, 1e-3) - normalize(10.0, 1.0, 100.0)) < 1e-12
assert abs(normalize(10.0, 1.0, 100.0) - 0.5) < 1e-12
class TestCompositeScore:
@@ -110,5 +114,5 @@ class TestScorer:
cost_expensive = next(s for s in result_expensive.scores if s.metric_name == "cost_efficiency")
assert cost_cheap.normalized_score > cost_expensive.normalized_score
assert cost_cheap.normalized_score > 0.9 # near the best
assert cost_cheap.normalized_score > 0.85 # 2x the floor of a 200x range
assert cost_expensive.normalized_score < 0.1 # near the worst