Functional Weave
Code in TypeScript

manufacturing.yield-scrap@1.0.0

README.md

1,408 bytes · view raw

# manufacturing.yield-scrap

How many units to start so that, at a process yield, enough good units come
out:

    input = ceil(requiredOutput / yield)
    scrap = input - requiredOutput

With a 95% yield, 100 good units need 106 starts (105.26 rounded up), and the
plan allows 6 to be scrapped.

**Rounded up, exactly.** You cannot start part of a unit, and rounding down
would leave you short, so the input is always rounded up. The division is done
in integers (`requiredOutput * 10000 / yieldBasisPoints`, rounded up by
`math.round-div`), never as a float: 563 good units at a 56.3% yield need
exactly 1000 starts, but `563 / 0.563` in floating point is
1000.0000000000001, and its ceiling is 1001.

**Scrap is the allowance.** At the stated yield, `input` starts are expected to
give at least `requiredOutput` good units and fewer than `requiredOutput + 1`
(the rounding never buys a whole extra unit), so `scrap` is the whole number of
units the plan expects to lose. The actual scrap is whatever the process does
on the day.

**Yield is in basis points**, 1 to 10000 (0.01% to 100%). A yield of 0 is an
error: no number of starts gives any good output. A required output of 0 needs
no input.

For a routing with several steps, apply this from the last step backwards: the
input of one step is the required output of the one before, rounded up at each
step, because each step has to start whole units.