pick

fun pick(edges: List<PolicyEdge>, config: PolicyConfig, localHoldings: Long): Grant?

Pick the single child to delegate the next quantum to, or null when no child is both eligible and demanding.

The steps, all in exact rational arithmetic (design §7.3):

  1. Candidates — edges whose additionalNeed = targetOutstanding − outstanding is positive, each with a quantum trimmed to demand, holdings, and the caps; a zero quantum drops the edge.

  2. Parent virtual time — the weighted mean V = Σ w·ev / Σ w over the fixed candidate set, where ev is effectiveVirtualService.

  3. Eligibility — keep candidates with ev ≤ V. Non-empty by construction: V is the weighted mean of these same candidates' ev over strictly positive weights, so min(ev) ≤ V always holds, and no rounding can lose the margin — the arithmetic is exact and an overflow throws rather than returning a wrong order. An empty set would mean step 2 averaged a different set than this filter, or admitted a non-positive weight; either makes the round's whole ordering untrustworthy, so it fails loudly instead of scheduling against it (design §7.3 step 3).

  4. Deadline — among the eligible, the minimum (ev + q/w, attachmentId); the stable id is the deterministic tie-break.

Parameters

edges

the parent's immediate children.

config

the round's quantum and caps.

localHoldings

service this peer may itself delegate right now; caps the quantum.

Throws

if step 3's eligible set is empty — a policy bug, not an input the caller can provoke (issue #1737).