BOM-Aware Consequence Scoring¶
The score-based allocation engine is a greedy, single-level allocator: by default it scores each (demand, supply) pair with static per-item weights and never traverses the bill of material. It therefore cannot express the planner intuition that shorting a component has high value only when it is the sole missing part for an otherwise-buildable finished good — and zero value when the FG build is already doomed by another component shortage.
The Consequence Component (opt-in, OFF by default)¶
A new consequence_component is added to the score breakdown. It is a no-op unless a caller opts in via environment variables, so existing allocation runs remain bit-identical:
| Env var | Default | Effect |
|---|---|---|
ALLOCATION_CONSEQUENCE_FACTOR |
0.0 |
Global multiplier on each demand's consequence_weight; set > 0 (e.g. 1.0) to enable |
ALLOCATION_INCLUDE_INDIRECT_DEMAND |
0 |
When truthy, kit/make indirect component demand from PIPE_indirect_demand is unioned into the demand set so components needed by FG builds compete for the same supply pool, tagged with the parent FG's priority class |
How the Value Is Computed¶
files/utils/consequence.py runs a 1-level (immediate-parent) where-used pre-pass before the Rust engine runs:
load_where_used(conn)builds{child_item_id → [ParentLink(parent_item, parent_site, ratio)]}frommaster.bill_of_material.compute_consequence_weights(demands, supplies, where_used, priority_scores)aggregates total demand/supply per(item, location); then for each parent FG:- walks its immediate children; a child is binding when
required − supply_available > 0; - exactly one binding child → that component demand inherits the parent FG's priority score as its consequence weight (allocating it unblocks the FG);
- ≥ 2 binding children → the parent is already doomed; no child gets any consequence from this parent (zero marginal value).
Data Flow & Schema¶
load_demands → (optional) load_indirect_demands union
→ compute_consequence_weights annotation
→ Rust run_allocation
→ write_results_ch writes score_consequence
→ explain/detail endpoints surface it
PIPE_allocation_results gains score_consequence Float64 DEFAULT 0 (idempotent ADD COLUMN via historization.migrations.apply_allocation_consequence_migration, wired into apply_history_schema).
Key Files¶
| File | Role |
|---|---|
files/utils/consequence.py |
load_where_used(), compute_consequence_weights(), ParentLink |
files/allocation_runner.py |
CONSEQUENCE_FACTOR / INCLUDE_INDIRECT_DEMAND toggles, load_indirect_demands(), pre-pass wiring, score_consequence in write_results_ch |
files/supply/src/score_alloc/models.rs |
consequence_weight on Demand; consequence_component in ScoreBreakdown + AllocationExplanation |
files/supply/src/score_alloc/scoring.rs |
The consequence_component score term |
files/api/main.py |
/api/allocation/explain/{demand_id} + supply-detail breakdowns surface score_consequence |