@mark1russell7/stack-endurance 0.8.14 → 0.8.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/add-on.js +1 -1
- package/build/index.d.ts +30 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +39 -5
- package/build/index.js.map +1 -1
- package/build/{join-Cc6JzE5G.js → join-C9nJDe7B.js} +4 -2
- package/build/{join-Cc6JzE5G.js.map → join-C9nJDe7B.js.map} +1 -1
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +6 -1
- package/build/schema.js.map +1 -1
- package/package.json +2 -2
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["horizonOf"],"sources":["../src/joint.ts","../src/best.ts","../src/stops.ts","../src/shortfall.ts","../src/sample.ts"],"sourcesContent":["import { type Objective, solveLexicographic } from \"@mark1russell7/linear\";\nimport { add, div, equals, mul, neg, ONE, type Rational, sign, toNumber, ZERO } from \"@mark1russell7/rational\";\nimport { type CaseOptions, caseDraws, caseStopped, drawDemand, storeAmounts } from \"./endurance.ts\";\nimport type { CaseCuts, Converter, EnduranceLayer, IsoDate } from \"./layer.ts\";\nimport { caseParts, deviceUse, drawBlock, fewestRow, Program, reachOf, valueAt } from \"./program.ts\";\nimport { addTo, dense, exact, type Row } from \"./rows.ts\";\n\n// The joint days: the largest count of days that a set of draws holds together, with the best share of the stores.\n// The query is a linear program over the totals of the span, with exact rationals (@mark1russell7/linear).\n\n/** The joint days of a set of draws in a case, with the share of the stores at the optimum. */\nexport interface JointDays {\n readonly case: string;\n readonly at: IsoDate;\n /**\n * The largest count of days that each draw of `plan` holds at the same time. It is `Infinity` when `plan` is empty,\n * or when the stores give each draw of `plan` without end.\n */\n readonly days: number;\n /** The needs of the set that take from the stores: the case stops their supply, and their demand is more than 0. The order is the order of `caseDraws`. */\n readonly plan: readonly string[];\n /** The needs of the set that take nothing from the stores, in the order of their codes. The case does not stop their supply, or their demand is 0. */\n readonly holds: readonly string[];\n /**\n * The amount of each resource that each draw of `plan` takes from the stores in `days`. The keys are the code of the need, then the code of the resource.\n * A take through a converter that makes a resource counts the inputs of the converter. A resource with no take is not in the record.\n * The record is empty when `days` is `Infinity`.\n */\n readonly takes: Readonly<Record<string, Readonly<Record<string, number>>>>;\n /**\n * The resources that limit `days`, in the order of their codes. Each one has a store in the layer, is an input of `plan` through each chain,\n * and has no stock left at the optimum. The list is empty when `days` is `Infinity`.\n */\n readonly binding: readonly string[];\n /** The count of runs of each converter at the optimum, by the `id` of the converter. A converter with no run is not in the record. */\n readonly runs: Readonly<Record<string, number>>;\n /**\n * The converters of the plan whose limit `perDay` stops more runs at the optimum, in the order of their `id`. A converter of the plan\n * gives a need of the plan, or makes an input of the plan through each chain.\n * The list is empty when `days` is `Infinity` or 0. Else it has each converter of the plan with a limit of 0.\n */\n readonly capped: readonly string[];\n}\n\n/**\n * This function gives the joint days of a set of draws. These are the largest count of days `d` at which each draw holds `d` days.\n * The draws hold at the same time, with the best share of the stores and of the runs of the converters.\n *\n * - The function solves a linear program over the totals of the span. Its variables are `d`, the take of each direct use,\n * the runs of each converter, and the share of each stock.\n * - Each draw of the plan gets `d` times its demand (`drawDemand`) from its direct uses and from the converters that give its need.\n * - The takes of each resource are not more than its stock (`storeAmounts` at `at`) plus the gifts of the converters that make it.\n * - A converter whose device stops gives nothing, and a store whose part stops gives nothing, as in `enduranceOf`.\n * - The runs of a converter with a limit `perDay` are not more than `perDay` times `devices` times `d`. The converters of one device share it, as in `enduranceOf`.\n * - A store counts with all of its amount when its due date is after `at`, as in `enduranceOf`. A due date in the span has no effect.\n * - After the largest `d`, a second objective takes the smallest sum of the shares of the stocks. Thus the takes have no waste.\n * - A third objective takes the fewest device-days of the converters. Thus the runs are not more than the plan uses.\n * - The draws that are not in the set are outside this plan. They take nothing in the program.\n * - A need of the set whose supply works, or whose demand is 0, holds without end. It goes in `holds`, as `enduranceOf` leaves it out.\n *\n * The take order of `enduranceOf` gives the stores to a higher draw first. This function gives one share for the whole set.\n * Thus a draw of the set can get fewer days here than alone, and a lower draw can get more.\n *\n * The program uses exact rationals, so the result has no error of the method. Only the change back to a number rounds.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, and the stack or the parts that are also down\n * @param needs - The codes of the needs of the draws of the set\n * @returns The joint days, the takes of each draw, the binding resources and the runs of each converter\n * @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`.\n */\nexport function jointDays(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions, needs: readonly string[]): JointDays {\n const known = new Set(layer.draws.map((draw) => draw.need));\n const unknown = needs.filter((need) => !known.has(need));\n if (unknown.length > 0) throw new RangeError(`The needs ${unknown.map((need) => `\"${need}\"`).join(\", \")} are not the needs of draws of the layer.`);\n const stoppedParts = caseStopped(caseCuts, options);\n const stock = storeAmounts(layer, options.at, stoppedParts);\n const wanted = new Set(needs);\n const plan = caseDraws(layer, caseCuts, stoppedParts).filter((draw) => wanted.has(draw.need));\n const planned = new Set(plan.map((draw) => draw.need));\n const base = { case: caseCuts.case, at: options.at, plan: plan.map((draw) => draw.need), holds: [...wanted].filter((need) => !planned.has(need)).sort() };\n const endless: JointDays = { ...base, days: Infinity, takes: {}, binding: [], runs: {}, capped: [] };\n if (plan.length === 0) return endless;\n\n const parts = caseParts(layer, stoppedParts, stock, planned);\n const program = new Program();\n const days = program.next();\n const blocks = plan.map((draw) => {\n const block = drawBlock(program, parts, draw);\n // The need of the draw: its gifts are not less than its demand times the days.\n const need: Row = new Map(block.gifts);\n addTo(need, days, neg(exact(drawDemand(draw, caseCuts))));\n program.push(need, \">=\", ZERO);\n return block;\n });\n // The limit of each device: the runs use `devices` times `d` device-days or less. A limit of 0 stops the converter.\n const runCols = blocks.flatMap((block) => [...block.runs]);\n const { limits, stopped } = deviceUse(runCols);\n for (const index of stopped) program.push(new Map([[index, ONE]]), \"<=\", ZERO);\n for (const limit of limits.values()) {\n const row: Row = new Map(limit.row);\n addTo(row, days, neg(exact(limit.devices)));\n program.push(row, \"<=\", ZERO);\n }\n // The shares of each stock are not more than the stock.\n for (const resource of parts.stocked) {\n const row: Row = new Map();\n // A draw has a share only of a resource that it can use (`drawBlock`).\n for (const block of blocks) {\n const index = block.shares.get(resource);\n if (index !== undefined) addTo(row, index, ONE);\n }\n if (row.size > 0) program.push(row, \"<=\", exact(stock.get(resource) ?? 0));\n }\n\n const most: Row = new Map([[days, ONE]]);\n const least: Row = new Map();\n for (const block of blocks) for (const [resource, index] of block.shares) addTo(least, index, div(ONE, exact(stock.get(resource) ?? 1)));\n // The third objective takes the fewest device-days. Thus a converter whose inputs cost no stock does not give more runs than the plan uses,\n // and `runs` and `capped` have one value.\n const objectives: Objective[] = [\n { sense: \"max\", coefficients: dense(most, program.count) },\n { sense: \"min\", coefficients: dense(least, program.count) },\n { sense: \"min\", coefficients: dense(fewestRow(runCols), program.count) },\n ];\n const solved = solveLexicographic(program.constraints(), objectives);\n // The point 0 is feasible and the later objectives are not less than 0. So only an unbounded first stage has no optimum.\n if (solved.status !== \"optimal\") return endless;\n\n const x = solved.x;\n const takes: Record<string, Record<string, number>> = {};\n for (const block of blocks) {\n const record: Record<string, number> = {};\n for (const [resource, index] of block.shares) if (sign(x[index] ?? ZERO) > 0) record[resource] = toNumber(x[index] ?? ZERO);\n takes[block.draw.need] = record;\n }\n // A converter gives a need or a resource, so it is a cook or a maker, not the two.\n const total = new Map<Converter, Rational>();\n for (const [converter, index] of runCols) total.set(converter, add(total.get(converter) ?? ZERO, x[index] ?? ZERO));\n const runs: Record<string, number> = {};\n for (const [converter, value] of total) if (sign(value) > 0) runs[converter.id] = toNumber(value);\n\n const withStore = new Set(layer.stores.map((store) => store.resource));\n // The converters that the plan can use: the converters that give a need of the plan, and the makers of the resources of the closure.\n const { closure, reach } = reachOf(parts, planned);\n const binding = [...closure]\n .filter((resource) => withStore.has(resource))\n .filter((resource) => {\n // A resource with no live stock has no share, so its take is 0 and it is used up.\n const taken = blocks.reduce((sum, block) => {\n const index = block.shares.get(resource);\n return index === undefined ? sum : add(sum, x[index] ?? ZERO);\n }, ZERO);\n return equals(taken, exact(stock.get(resource) ?? 0));\n })\n .sort();\n const best = solved.values[0] ?? ZERO;\n const capped = sign(best) > 0\n ? [\n ...[...total.keys()].filter((converter) => converter.perDay !== undefined && !(converter.perDay > 0)),\n ...[...limits.values()].filter((limit) => equals(valueAt(limit.row, x), mul(exact(limit.devices), best))).flatMap((limit) => limit.converters),\n ]\n .filter((converter) => reach.has(converter))\n .map((converter) => converter.id)\n .sort()\n : [];\n return { ...base, days: toNumber(best), takes, binding, runs, capped };\n}\n","import { type Objective, solveLexicographic } from \"@mark1russell7/linear\";\nimport { add, div, equals, mul, neg, ONE, type Rational, sign, sub, toNumber, ZERO } from \"@mark1russell7/rational\";\nimport { type CaseOptions, caseDraws, caseStopped, drawDemand, storeAmounts } from \"./endurance.ts\";\nimport type { CaseCuts, Converter, Draw, DrawEndurance, Endurance, EnduranceLayer } from \"./layer.ts\";\nimport { type CaseParts, caseParts, deviceUse, drawBlock, type DrawBlock, fewestRow, Program, reachOf, valueAt } from \"./program.ts\";\nimport { addTo, dense, exact, type Row } from \"./rows.ts\";\n\n// The best endurance: the days of each draw with the best share of the stores, the most important level first.\n// Each step is a linear program over the totals of the spans, with exact rationals (@mark1russell7/linear).\n\n/** A draw whose days are fixed. */\ninterface Fixed {\n /** The span of the draw in the programs: its days, or 1 for a draw with no end. */\n readonly span: Rational;\n /** True for a draw that holds without end. It takes no stock, and its span is one day. */\n readonly endless: boolean;\n /** The device-days of each day that the draw keeps, by the key of the device. */\n readonly keep: ReadonlyMap<string, Rational>;\n /** The `id` of each converter whose limit stops more runs at the step that fixes the draw. */\n readonly capped: readonly string[];\n /** True for a draw that holds the horizon. */\n readonly atHorizon: boolean;\n}\n\n/** The options of `bestEndurance`: the options of a case, and a horizon. */\nexport interface BestOptions extends CaseOptions {\n /**\n * The horizon in days, more than 0. The default is no horizon. A draw holds the horizon at most, thus it keeps back\n * only the horizon times its demand. The rest of the stores goes to the lower levels. Use the target of a plan, for\n * example 14 days, to ask if each draw holds the target.\n */\n readonly horizon?: number | undefined;\n}\n\n/** This function gives the horizon as a rational, or undefined for no horizon. It throws a `RangeError` for a horizon that is not more than 0. */\nfunction horizonOf(horizon: number | undefined): Rational | undefined {\n if (horizon === undefined || horizon === Infinity) return undefined;\n if (!(horizon > 0) || !Number.isFinite(horizon)) throw new RangeError(`The horizon ${String(horizon)} is not a number of days more than 0.`);\n return exact(horizon);\n}\n\n/** A program of one step, with the indexes of its parts. */\ninterface Step {\n readonly program: Program;\n readonly blocks: readonly DrawBlock[];\n /** The column of the common days of the open draws. */\n readonly floor: number;\n /** The row `days - floor >= 0` of each open draw, by the code of its need. */\n readonly floors: ReadonlyMap<string, number>;\n /** The run columns of the open draws. */\n readonly openRuns: readonly (readonly [Converter, number])[];\n /** The device-days of the open draws for each device, with the device-days of each day that the fixed draws leave. */\n readonly shared: ReadonlyMap<string, { readonly row: Row; readonly room: Rational; readonly converters: readonly Converter[] }>;\n}\n\n/**\n * This function gives the days that each draw holds when a case stops its supply. The stores and the devices have their best share.\n * The result has the form of `enduranceOf`, so `caseShortfall` takes it.\n *\n * The share is lexicographic. The draws of the first level get their best days, then the draws of the next level get theirs, and so on.\n * In one level, the share is the best for the draw with the fewest days, then for the next draw, and so on (the leximin share).\n * Thus a draw of a level cannot take a store that another draw of the level needs more.\n *\n * - The function solves a sequence of linear programs over the totals of the spans. Each program has the days of the open draws\n * and their common floor. For each draw, it has the take of each direct use, the runs of each converter and the share of each stock.\n * - Each step takes the largest floor. A draw whose floor row has a dual value that is not 0 cannot get more days. The step fixes its days.\n * The dual values of the floor rows add to 1, so each step fixes one draw or more.\n * - A fixed draw keeps its days in each later step. Its share of the stocks can change, so a later draw can get a store that it does not need.\n * - The stores, the direct uses, the converters and the devices follow the rules of `jointDays`. A store counts with all of its amount when its due date is after `at`.\n * - A fixed draw keeps the device-days of each day that it uses at its step, for all the days of the later draws. This is the safe side, as in `enduranceOf`.\n * The exact share of a device between two spans is not a linear program: the device-days of a day are the runs over the span.\n * - A step with no largest floor gives the open draws no end. Each of them takes no stock, and keeps the fewest device-days of each day.\n * - At the end, a program takes the smallest sum of the shares of the stocks, each over its stock, then the fewest device-days.\n * These are the takes of the result. A resource in `binding` has no stock left at this point.\n * - A draw in `capped` used a device with no device-days left at the step that fixed it.\n * - With a horizon, the floor of each step is the horizon at most. A step whose floor is the horizon fixes each of its\n * open draws at the horizon, with `atHorizon`. Such a draw takes only the horizon times its demand. A draw with no\n * end also holds the horizon. With no horizon, the result is the same as before the option.\n *\n * The programs use exact rationals, so the result has no error of the method. Only the change back to a number rounds.\n * The fewest days of the first level are the joint days (`jointDays`) of the draws of that level.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, the stack or the parts that are also down, and the horizon\n * @returns The endurance of each draw whose supply stops\n * @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.\n */\nexport function bestEndurance(layer: EnduranceLayer, caseCuts: CaseCuts, options: BestOptions): Endurance {\n const horizon = horizonOf(options.horizon);\n const stoppedParts = caseStopped(caseCuts, options);\n const stock = storeAmounts(layer, options.at, stoppedParts);\n const draws = caseDraws(layer, caseCuts, stoppedParts);\n const parts = caseParts(layer, stoppedParts, stock, new Set(draws.map((draw) => draw.need)));\n // The count of devices of each key. The gate refuses two counts for one device.\n const devices = new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0] as const)).limits].map(([key, limit]) => [key, limit.devices] as const));\n const fixed = new Map<string, Fixed>();\n\n for (const level of levelGroups(layer, draws)) {\n let open = level;\n while (open.length > 0) {\n const step = buildStep(parts, caseCuts, draws, fixed, open, devices, \"span\", horizon);\n const solved = solveLexicographic(step.program.constraints(), [\n { sense: \"max\", coefficients: dense(new Map([[step.floor, ONE]]), step.program.count) },\n { sense: \"min\", coefficients: dense(fewestRow(step.openRuns), step.program.count) },\n ]);\n if (solved.status !== \"optimal\") {\n if (solved.status === \"infeasible\") throw new Error(\"The step of the best endurance has no point. The point of the last step is a point of it.\");\n fixEndless(parts, caseCuts, draws, fixed, open, devices);\n break;\n }\n const floor = solved.values[0] ?? ZERO;\n const first = solved.stages[0]?.result;\n const dual = first?.status === \"optimal\" ? first.dual : [];\n const atHorizon = horizon !== undefined && equals(floor, horizon);\n let done = atHorizon ? open : open.filter((draw) => sign(dual[step.floors.get(draw.need) as number] ?? ZERO) !== 0);\n // The dual values of the floor rows add to 1. Thus `done` is not empty. The fallback fixes each open draw at the floor.\n if (done.length === 0) done = open;\n const full = new Set([...step.shared].filter(([, limit]) => equals(valueAt(limit.row, solved.x), mul(limit.room, floor))).map(([key]) => key));\n for (const draw of done) {\n const block = step.blocks.find((item) => item.draw.need === draw.need) as DrawBlock;\n const keep = new Map<string, Rational>();\n for (const [key, limit] of deviceUse(block.runs).limits) keep.set(key, sign(floor) > 0 ? div(valueAt(limit.row, solved.x), floor) : ZERO);\n const { reach } = reachOf(parts, new Set([draw.need]));\n const capped = sign(floor) > 0\n ? [...reach]\n .filter((converter) => converter.perDay !== undefined && (!(converter.perDay > 0) || [...full].some((key) => step.shared.get(key)?.converters.includes(converter))))\n .map((converter) => converter.id)\n .sort()\n : [];\n fixed.set(draw.need, { span: floor, endless: false, keep, capped, atHorizon });\n }\n const fixedNow = new Set(done.map((draw) => draw.need));\n open = open.filter((draw) => !fixedNow.has(draw.need));\n }\n }\n\n const needs: Record<string, DrawEndurance> = {};\n if (draws.length === 0) return { case: caseCuts.case, at: options.at, needs };\n const last = buildStep(parts, caseCuts, draws, fixed, [], devices, \"span\");\n const least: Row = new Map();\n for (const block of last.blocks) for (const [resource, index] of block.shares) addTo(least, index, div(ONE, exact(stock.get(resource) ?? 1)));\n const objectives: Objective[] = [\n { sense: \"min\", coefficients: dense(least, last.program.count) },\n { sense: \"min\", coefficients: dense(fewestRow(last.blocks.flatMap((block) => [...block.runs])), last.program.count) },\n ];\n const solved = solveLexicographic(last.program.constraints(), objectives);\n if (solved.status !== \"optimal\") throw new Error(\"The last program of the best endurance has no optimum. The point of the last step is a point of it.\");\n const withStore = new Set(layer.stores.map((store) => store.resource));\n for (const block of last.blocks) {\n const need = block.draw.need;\n const fix = fixed.get(need) as Fixed;\n if (fix.endless) {\n needs[need] = { days: Infinity, binding: [], takes: {} };\n continue;\n }\n const takes: Record<string, number> = {};\n for (const [resource, index] of block.shares) if (sign(solved.x[index] ?? ZERO) > 0) takes[resource] = toNumber(solved.x[index] ?? ZERO);\n const { closure } = reachOf(parts, new Set([need]));\n const binding = [...closure]\n .filter((resource) => withStore.has(resource))\n .filter((resource) => {\n // A resource with no live stock has no share, so its take is 0 and it is used up.\n const taken = last.blocks.reduce((sum, item) => {\n const index = item.shares.get(resource);\n return index === undefined ? sum : add(sum, solved.x[index] ?? ZERO);\n }, ZERO);\n return equals(taken, exact(stock.get(resource) ?? 0));\n })\n .sort();\n const days = toNumber(fix.span);\n needs[need] = { days, binding, takes, ...(fix.capped.length === 0 ? {} : { capped: fix.capped }), ...(fix.atHorizon ? { atHorizon: true as const } : {}) };\n }\n return { case: caseCuts.case, at: options.at, needs };\n}\n\n/** This function gives the draws of each level, in the order of `levels`. The draws of a level that is not in `levels` come last, together. */\nfunction levelGroups(layer: EnduranceLayer, draws: readonly Draw[]): Draw[][] {\n const rank = (draw: Draw): number => {\n const index = layer.levels.indexOf(draw.level);\n return index < 0 ? layer.levels.length : index;\n };\n const out: Draw[][] = [];\n let previous = -1;\n for (const draw of draws) {\n if (rank(draw) !== previous) out.push([]);\n previous = rank(draw);\n out[out.length - 1]?.push(draw);\n }\n return out;\n}\n\n/**\n * This function gives the program of one step. The fixed draws keep their spans and their device-days. The open draws have a common floor.\n *\n * - With `\"span\"`, each open draw has a column of its days, not less than the floor. Its runs share the device-days that the fixed draws leave, for the floor.\n * The device-days of each day are the runs over the span. A span not less than the floor uses fewer of them, so this is the safe side.\n * - With `\"day\"`, each open draw has a span of one day and takes no stock. Its runs share the device-days of one day.\n * - With a horizon, the floor is the horizon at most.\n */\nfunction buildStep(\n parts: CaseParts,\n caseCuts: CaseCuts,\n draws: readonly Draw[],\n fixed: ReadonlyMap<string, Fixed>,\n open: readonly Draw[],\n devices: ReadonlyMap<string, number>,\n mode: \"span\" | \"day\",\n horizon?: Rational,\n): Step {\n const program = new Program();\n const floor = program.next();\n if (horizon !== undefined) program.push(new Map([[floor, ONE]]), \"<=\", horizon);\n const opened = new Set(open.map((draw) => draw.need));\n const blocks: DrawBlock[] = [];\n const floors = new Map<string, number>();\n const openRuns: (readonly [Converter, number])[] = [];\n const kept = new Map<string, Rational>();\n for (const draw of draws) {\n const fix = fixed.get(draw.need);\n if (fix === undefined && !opened.has(draw.need)) continue;\n const endless = fix?.endless ?? mode === \"day\";\n const block = drawBlock(program, parts, draw, !endless);\n blocks.push(block);\n const demand = exact(drawDemand(draw, caseCuts));\n const need: Row = new Map(block.gifts);\n if (fix !== undefined) {\n program.push(need, \">=\", mul(demand, fix.span));\n const { limits, stopped } = deviceUse(block.runs);\n for (const index of stopped) program.push(new Map([[index, ONE]]), \"<=\", ZERO);\n for (const [key, limit] of limits) program.push(limit.row, \"<=\", mul(fix.keep.get(key) ?? ZERO, fix.span));\n for (const [key, value] of fix.keep) kept.set(key, add(kept.get(key) ?? ZERO, value));\n continue;\n }\n openRuns.push(...block.runs);\n if (mode === \"day\") {\n program.push(need, \">=\", demand);\n continue;\n }\n const days = program.next();\n addTo(need, days, neg(demand));\n program.push(need, \">=\", ZERO);\n floors.set(draw.need, program.push(new Map([[days, ONE], [floor, neg(ONE)]]), \">=\", ZERO));\n }\n const shared = new Map<string, { row: Row; room: Rational; converters: readonly Converter[] }>();\n const { limits, stopped } = deviceUse(openRuns);\n for (const index of stopped) program.push(new Map([[index, ONE]]), \"<=\", ZERO);\n for (const [key, limit] of limits) {\n const left = sub(exact(devices.get(key) ?? limit.devices), kept.get(key) ?? ZERO);\n const room = sign(left) > 0 ? left : ZERO;\n shared.set(key, { row: limit.row, room, converters: limit.converters });\n if (mode === \"day\") {\n program.push(limit.row, \"<=\", room);\n continue;\n }\n const row: Row = new Map(limit.row);\n addTo(row, floor, neg(room));\n program.push(row, \"<=\", ZERO);\n }\n for (const resource of parts.stocked) {\n const row: Row = new Map();\n for (const block of blocks) {\n const index = block.shares.get(resource);\n if (index !== undefined) addTo(row, index, ONE);\n }\n if (row.size > 0) program.push(row, \"<=\", exact(parts.stock.get(resource) ?? 0));\n }\n return { program, blocks, floor, floors, openRuns, shared };\n}\n\n/**\n * This function fixes the open draws with no end. Each open draw takes no stock, and keeps the fewest device-days of each day.\n * A step with no largest floor has a direction with no take of a stock, so this program has a point.\n */\nfunction fixEndless(parts: CaseParts, caseCuts: CaseCuts, draws: readonly Draw[], fixed: Map<string, Fixed>, open: readonly Draw[], devices: ReadonlyMap<string, number>): void {\n const step = buildStep(parts, caseCuts, draws, fixed, open, devices, \"day\");\n const solved = solveLexicographic(step.program.constraints(), [{ sense: \"min\", coefficients: dense(fewestRow(step.openRuns), step.program.count) }]);\n if (solved.status !== \"optimal\") throw new Error(\"The draws with no end of the best endurance have no point of one day.\");\n for (const draw of open) {\n const block = step.blocks.find((item) => item.draw.need === draw.need) as DrawBlock;\n const keep = new Map<string, Rational>();\n for (const [key, limit] of deviceUse(block.runs).limits) keep.set(key, valueAt(limit.row, solved.x));\n fixed.set(draw.need, { span: ONE, endless: true, keep, capped: [], atHorizon: false });\n }\n}\n","import { DEFAULT_MAX_SETS, stopSets, type Stack } from \"@mark1russell7/system-stack\";\n\n// The minimal stop sets of a supply from the structure of the needs. The index does not give this entry: `stopCurves` uses it.\n\n/**\n * This function gives the minimal sets of cuts that stop a supply, from the paths of the needs of the stack (`stopSets` of the core).\n * A set is a list of indexes of `parts`, from the smallest set. Two sets of one size are in the order of `minimalStops`.\n *\n * - `parts` has the part of each cut that counts. Two cuts of one part are two cuts: each one stops what the part stops.\n * - A cut of the supply stops it alone. The other sets come from `stopSets` with the cut parts as `among`, so no other part can fail.\n * - The parts of `down` are down for the full event. The caller makes sure that they do not stop the supply with no cut.\n * - The result is `undefined` when the search passes its budget, or when the sets of cuts are more than `maxSets`.\n *\n * @param stack - The base stack\n * @param supply - The part of the supply of a draw\n * @param parts - The part of each cut that counts\n * @param down - The parts that are down for the full event\n * @param maxSets - The largest count of sets in one step of the search, and of the sets of cuts (`maxSets` of `stopSets`)\n */\nexport function stackStops(stack: Stack, supply: string, parts: readonly string[], down: readonly string[] = [], maxSets: number = DEFAULT_MAX_SETS): number[][] | undefined {\n const cutsOf = new Map<string, number[]>();\n for (const [index, part] of parts.entries()) cutsOf.set(part, [...(cutsOf.get(part) ?? []), index]);\n const own = (cutsOf.get(supply) ?? []).map((index) => [index]);\n const among = [...cutsOf.keys()].filter((part) => part !== supply);\n const found = stopSets(stack, supply, { down, among, size: among.length, maxSets });\n if (found.kind === \"budget\") return undefined;\n // The empty set: the supply is not in the stack, or it does not work in the base stack.\n // In both, `stopped` of the core does not count it as stopped, so only a cut of the supply stops it.\n if (found.sets.some((set) => set.length === 0)) return own;\n const out = [...own];\n for (const set of found.sets) {\n // Each choice of one cut for each part of the set is a minimal set of cuts.\n let choices: number[][] = [[]];\n for (const part of set) {\n const cuts = cutsOf.get(part) ?? [];\n if (choices.length * cuts.length + out.length > maxSets) return undefined;\n choices = choices.flatMap((choice) => cuts.map((cut) => [...choice, cut]));\n }\n out.push(...choices.map((choice) => choice.sort((x, y) => x - y)));\n }\n return out.sort(byMask);\n}\n\n/** The order of `minimalStops`: the smaller set first, then the set whose largest different index is smaller. */\nfunction byMask(a: readonly number[], b: readonly number[]): number {\n if (a.length !== b.length) return a.length - b.length;\n for (let index = a.length - 1; index >= 0; index -= 1) {\n const difference = (a[index] ?? 0) - (b[index] ?? 0);\n if (difference !== 0) return difference;\n }\n return 0;\n}\n","import { type OrderedRing, pathSetReliability, stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { DEFAULT_MAX_SETS, neededParts, survivalAt, weakestBound, type CutBound, type PathOptions } from \"@mark1russell7/system-stack\";\nimport { bestEndurance } from \"./best.ts\";\nimport { caseDraws, caseStopped, enduranceOf, type CaseOptions } from \"./endurance.ts\";\nimport type { CaseCuts, Draw, Endurance, EnduranceLayer, Prior, Survival } from \"./layer.ts\";\nimport { stackStops } from \"./stops.ts\";\n\n// The shortfall: the user-days in which a draw does not get its need, for one case and for one year.\n\n/** The read of a curve at a time is in the core since system-stack 0.1.13. This package gives it again, so its API does not change. */\nexport { survivalAt };\n\n/**\n * This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.\n * It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.\n * With no horizon, the area goes to the end of the curve.\n */\nexport function tailDays(curve: Survival, from: number, to: number = Infinity): number {\n let area = 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0] = curve[index - 1] ?? [0, 1];\n const [t1] = curve[index] ?? [0, 0];\n const start = Math.max(t0, from);\n const end = Math.min(t1, to);\n if (start < end) area += ((survivalAt(curve, start) + survivalAt(curve, end)) / 2) * (end - start);\n }\n return area;\n}\n\n/**\n * The options of a shortfall: the stack or the parts that are also down, as for `enduranceOf`, and a horizon.\n * With a horizon of `h` days, the shortfall counts only the first `h` days of each cut. A draw that holds `h` days has no shortfall.\n * Thus a plan can aim at a target, for example 14 days and then 90 days.\n */\n/**\n * The options of `stopCurves`. With a stack, `maxSets` is the budget of the search of the needs (`stopSets` of the core).\n * When the search passes it, `minimalStops` gives the sets.\n */\nexport interface StopCurveOptions extends Pick<CaseOptions, \"stack\" | \"down\">, Pick<PathOptions, \"maxSets\"> {\n /** The budget of `independentStop` for the curve of each draw, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`. */\n readonly maxWork?: number | undefined;\n}\n\nexport interface ShortfallOptions extends StopCurveOptions {\n /** The horizon in days, more than 0. The default is no horizon. */\n readonly horizon?: number | undefined;\n}\n\nfunction horizonOf(options: ShortfallOptions): number {\n const horizon = options.horizon ?? Infinity;\n if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);\n return horizon;\n}\n\nfunction budgetsOf(options: StopCurveOptions): { readonly maxSets: number; readonly maxWork: number } {\n const maxSets = options.maxSets ?? DEFAULT_MAX_SETS;\n if (!Number.isInteger(maxSets) || maxSets < 1) throw new RangeError(`The option maxSets is ${String(options.maxSets)}: it is not a whole number from 1.`);\n const maxWork = options.maxWork ?? INDEPENDENT_MAX_WORK;\n if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The option maxWork is ${String(options.maxWork)}: it is not a whole number from 1.`);\n return { maxSets, maxWork };\n}\n\n/**\n * This function gives the days at which the chance of the curve falls to `chance`. With `0.1`, it is the 90th percentile of the duration.\n * When the curve does not fall to `chance`, the result is `Infinity`.\n */\nexport function survivalQuantile(curve: Survival, chance: number): number {\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (p0 <= chance) return t0;\n if (p1 <= chance) return t0 + ((p0 - chance) * (t1 - t0)) / (p0 - p1);\n }\n return Infinity;\n}\n\n/** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */\nexport function yearChance(prior: Prior): number {\n return 1 - Math.exp(-prior.perYear * prior.reach);\n}\n\n/** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */\nexport function yearRate(prior: Prior): number {\n return prior.perYear * prior.reach;\n}\n\n/** This function gives the times at which a curve of the result can bend: each point of each curve, and each crossing of two curves. */\nfunction bendTimes(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const out = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n for (const [i, a] of curves.entries()) {\n for (const b of curves.slice(i + 1)) {\n const d0 = survivalAt(a, t0) - survivalAt(b, t0);\n const d1 = survivalAt(a, t1) - survivalAt(b, t1);\n if (d0 * d1 < 0) out.add(t0 + ((t1 - t0) * d0) / (d0 - d1));\n }\n }\n }\n return [...out].sort((x, y) => x - y);\n}\n\n/**\n * This function makes a survival curve from a chance at each time. It stops at the first chance of 0, and it removes an increase of rounding.\n *\n * @throws RangeError when the chance at the last time is more than 0, as for curves that do not end at a chance of 0\n */\nfunction curveFrom(times: readonly number[], chanceAt: (days: number) => number): Survival {\n const out: [number, number][] = [];\n for (const days of times) {\n const chance = Math.min(out[out.length - 1]?.[1] ?? 1, chanceAt(days));\n out.push([days, chance]);\n if (chance === 0) return out;\n }\n throw new RangeError(\"The curves do not fall to a chance of 0 at their last point.\");\n}\n\n/**\n * This function gives the curve of a stop of some cuts when one event makes each cut longer together.\n * At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.\n *\n * - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).\n * - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.\n * - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.\n * - When no set of cuts stops the supply, the result is `[[0, 0]]`. This curve does not start at `[0, 1]`, so `checkEndurance` refuses it.\n *\n * The result is not a limit. When the cuts are independent, a stop of two cuts in series can be longer. A stop through a need of `any` can be shorter.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param stops - This function tells if the cuts of a list of indexes stop the supply. A larger list stops it when a smaller list does.\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function eventStop(curves: readonly Survival[], stops: (cuts: readonly number[]) => boolean): Survival {\n return curveFrom(bendTimes(curves), (days) => {\n const chances = curves.map((curve) => survivalAt(curve, days));\n for (const level of [...new Set(chances)].sort((x, y) => y - x)) {\n if (stops(chances.flatMap((chance, index) => (chance >= level ? [index] : [])))) return level;\n }\n return 0;\n });\n}\n\n/**\n * This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.\n * It is `eventStop` when any one cut stops the supply.\n *\n * @param curves - The curves, each one good for `checkEndurance`\n * @throws RangeError when there is no curve, or when a curve does not end at a chance of 0\n */\nexport function longestStop(curves: readonly Survival[]): Survival {\n const first = curves[0];\n if (first === undefined) throw new RangeError(\"longestStop needs one or more curves.\");\n return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);\n}\n\n/**\n * The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop` adds the chance of each state.\n * With a stack, `stopCurves` finds the minimal sets from the needs, so a larger count of cuts can have exact sets.\n */\nexport const MINIMAL_STOP_CUTS = 12;\n\n/**\n * This function gives the minimal sets of cuts that stop the supply: each set stops it, and no smaller part of a set stops it.\n * With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.\n */\nexport function minimalStops(count: number, stops: (cuts: readonly number[]) => boolean): number[][] | undefined {\n if (count > MINIMAL_STOP_CUTS) return undefined;\n const found: number[][] = [];\n const masks: number[] = [];\n const all = Array.from({ length: 1 << count }, (_, mask) => mask).sort((x, y) => popCount(x) - popCount(y) || x - y);\n for (const mask of all) {\n if (mask === 0 || masks.some((other) => (other & mask) === other)) continue;\n const cuts = Array.from({ length: count }, (_, index) => index).filter((index) => (mask >> index) & 1);\n if (!stops(cuts)) continue;\n masks.push(mask);\n found.push(cuts);\n }\n return found;\n}\n\nfunction popCount(mask: number): number {\n let total = 0;\n for (let rest = mask; rest > 0; rest &= rest - 1) total += 1;\n return total;\n}\n\n/**\n * This function gives an upper limit of the curve of a stop for each dependence of the cuts.\n * At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.\n * With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.\n *\n * @param curves - The curves of the cuts\n * @param sets - The minimal sets of `minimalStops`, or `undefined`\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function upperStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival {\n const groups = sets ?? curves.map((_, index) => [index]);\n const sum = (days: number): number => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);\n // The sum is linear between two times of bendTimes. A point where it falls through 1 is a bend of min(1, sum).\n const times = bendTimes(curves);\n const bends = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n const s0 = sum(t0) - 1;\n const s1 = sum(t1) - 1;\n if (s0 * s1 < 0) bends.add(t0 + ((t1 - t0) * s0) / (s0 - s1));\n }\n return curveFrom([...bends].sort((x, y) => x - y), (days) => Math.min(1, sum(days)));\n}\n\n/** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */\nexport const INDEPENDENT_TOLERANCE = 1e-6;\n\n/**\n * The default budget of `independentStop` for its groups of more than `MINIMAL_STOP_CUTS` cuts.\n * The budget counts the steps of the expansion times the count of points of the curve.\n * It is near the work of the sum over the states of 12 cuts.\n */\nexport const INDEPENDENT_MAX_WORK: number = 2 ** 26;\n\n/**\n * This function gives the curve of a stop of some cuts when the cuts are independent.\n * At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.\n * Its chance is a sum over each set of cuts that stops the supply.\n * Each term is the product of `s(t)` for the cuts that are on, and of `1 - s(t)` for the other cuts.\n *\n * - When any one cut stops the supply, the result is `1 - prod(1 - s)`. It is not less than the longest cut (`eventStop`).\n * - When the supply needs `any` of two parts, the stop of the two is `s1 * s2`. It is not more than the shorter cut.\n * - The result is not more than `upperStop` of the same sets, because `upperStop` is a limit for each dependence.\n * - Between two points of the curves the chance is a polynomial, not a line. The function splits each such segment into equal pieces.\n * The chance is linear in each `s`, and each mixed second derivative is between -1 and 1.\n * Thus `|f''| <= (sum |s'|)^2 - sum s'^2`, and the line of a piece of length `h` is within `h^2 |f''| / 8` of the chance.\n * The count of pieces keeps each line within `INDEPENDENT_TOLERANCE`. With a margin of 10 %, the count of points is less than `n / sqrt(7.2 * INDEPENDENT_TOLERANCE)` plus the segments, for `n` cuts.\n *\n * - Up to `MINIMAL_STOP_CUTS` cuts in the sets, the function adds the chance of each of the 2 to the power of that count of states.\n * - Two groups of cuts that share no set are independent, so the chance that the supply works is the product over the groups.\n * For example, 20 stages of 2 feeds give 20 groups of 2 cuts.\n * - In a group of more than `MINIMAL_STOP_CUTS` cuts, it uses the Shannon expansion of `pathSetReliability` of collections.\n * The expansion merges two states with the same sets left, and it drops a set that holds another set.\n * - The expansion is exponential in the worst case. The groups share one budget, `maxWork`.\n * When the steps of the expansions times the count of points of the curve pass it, the result is `undefined`.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param sets - The minimal sets of the cuts. With `undefined`, as for no minimal sets, the result is `undefined`. With no sets, it is `[[0, 0]]`\n * @param maxWork - The budget of the expansions of the groups of more than `MINIMAL_STOP_CUTS` cuts, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`\n * @throws RangeError when a curve does not end at a chance of 0, or for a bad `maxWork`\n */\nexport function independentStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined, maxWork: number = INDEPENDENT_MAX_WORK): Survival | undefined {\n if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The budget maxWork is ${String(maxWork)}: it is not a whole number from 1.`);\n if (sets === undefined) return undefined;\n // With no set, no cuts stop the supply, as for `eventStop` and `upperStop`.\n if (sets.length === 0) return [[0, 0]];\n // Only the cuts of a set change the chance. Their place in `used` is their index in the sets of the cuts that count.\n const used = [...new Set(sets.flat())].sort((x, y) => x - y);\n const usedCurves = used.map((index) => curves[index] ?? []);\n const usedSets = sets.map((set) => set.map((index) => used.indexOf(index)));\n const points = independentPoints(usedCurves);\n // Two groups of cuts that share no set are independent: the supply works when it works in each group.\n const groupChances: ((days: number) => number)[] = [];\n // The expansions of all groups share one budget.\n let work = maxWork;\n for (const group of cutGroups(used.length, usedSets)) {\n const curvesOf = group.map((index) => usedCurves[index] ?? []);\n const setsOf = usedSets.filter((set) => group.includes(set[0] ?? -1)).map((set) => set.map((index) => group.indexOf(index)));\n // Up to MINIMAL_STOP_CUTS cuts, the sum over the states is exact with a fixed cost. Past them, the expansion is exact within its budget.\n if (group.length <= MINIMAL_STOP_CUTS) {\n groupChances.push(stateChance(curvesOf, setsOf));\n continue;\n }\n const expanded = expandedChances(curvesOf, setsOf, points, work);\n if (expanded === undefined) return undefined;\n work -= expanded.steps * points.length;\n const chanceOf = new Map(points.map((days, index) => [days, expanded.chances[index] ?? 0]));\n groupChances.push((days) => {\n const chance = chanceOf.get(days);\n if (chance === undefined) throw new Error(`The expansion has no chance at ${String(days)} days.`);\n return chance;\n });\n }\n // With one group, the chance of the group is the result, with no rounding of 1 - (1 - chance).\n const [only] = groupChances;\n if (groupChances.length === 1 && only !== undefined) return curveFrom(points, only);\n return curveFrom(points, (days) => Math.min(1, Math.max(0, 1 - groupChances.reduce((works, chanceAt) => works * (1 - chanceAt(days)), 1))));\n}\n\n/** The groups of the cuts `0` to `count - 1`: two cuts are in one group when a chain of sets joins them. Each set has its cuts in one group. */\nfunction cutGroups(count: number, sets: readonly (readonly number[])[]): number[][] {\n const next = Array.from({ length: count }, () => new Set<number>());\n // A cycle through the cuts of each set joins them both ways, so the strongly connected components are the groups.\n for (const set of sets) for (const [at, index] of set.entries()) next[index]?.add(set[(at + 1) % set.length] ?? index);\n return stronglyConnectedComponents(\n Array.from({ length: count }, (_, index) => index),\n (index) => next[index] ?? [],\n );\n}\n\n/** The times of `independentStop`: the points of the curves, and the pieces that keep each line within `INDEPENDENT_TOLERANCE`. */\nfunction independentPoints(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const points: number[] = [];\n for (const [index, t1] of times.entries()) {\n const t0 = times[index - 1];\n if (t0 !== undefined) {\n const h = t1 - t0;\n const slopes = curves.map((curve) => Math.abs(survivalAt(curve, t1) - survivalAt(curve, t0)) / h);\n const sum = slopes.reduce((total, slope) => total + slope, 0);\n const bound = Math.max(0, sum * sum - slopes.reduce((total, slope) => total + slope * slope, 0));\n // A margin of 10 % keeps the rounding of the chance under the tolerance.\n const pieces = Math.ceil(h * Math.sqrt(bound / (8 * 0.9 * INDEPENDENT_TOLERANCE)));\n for (let piece = 1; piece < pieces; piece += 1) {\n const days = t0 + (h * piece) / pieces;\n // Two times that are next to each other as floats have no time between them.\n if (days > (points[points.length - 1] ?? t0) && days < t1) points.push(days);\n }\n }\n points.push(t1);\n }\n return points;\n}\n\n/** The chance of a stop at a time, as the sum over each state of `MINIMAL_STOP_CUTS` cuts or fewer. Bit k of a state is 1 when cut k is on. */\nfunction stateChance(curves: readonly Survival[], sets: readonly (readonly number[])[]): (days: number) => number {\n const setMasks = sets.map((set) => set.reduce((mask, index) => mask | (1 << index), 0));\n const stopping = Array.from({ length: 1 << curves.length }, (_, mask) => setMasks.some((set) => (set & mask) === set));\n const states = new Float64Array(1 << curves.length);\n return (days) => {\n // The chance of each state of the cuts, one cut at a time.\n states[0] = 1;\n let length = 1;\n for (const curve of curves) {\n const on = survivalAt(curve, days);\n for (let mask = 0; mask < length; mask += 1) {\n const chance = states[mask] ?? 0;\n states[mask + length] = chance * on;\n states[mask] = chance * (1 - on);\n }\n length *= 2;\n }\n let total = 0;\n for (let mask = 0; mask < length; mask += 1) if (stopping[mask]) total += states[mask] ?? 0;\n return Math.min(1, Math.max(0, total));\n };\n}\n\n/** The count of times in one expansion of `expandedChances`: the length of the vectors of its ring. */\nconst EXPANSION_WIDTH = 64;\n\n/**\n * The ring of the vectors of `width` chances, one for each time, for `pathSetReliability` of collections.\n * Each operation is on each time alone. In the order, `a` is less than `b` when it is less or equal at each time, and not equal.\n */\nfunction vectorRing(width: number): OrderedRing<Float64Array> {\n const zip = (a: Float64Array, b: Float64Array, op: (x: number, y: number) => number): Float64Array => {\n const out = new Float64Array(width);\n for (let index = 0; index < width; index += 1) out[index] = op(a[index] ?? 0, b[index] ?? 0);\n return out;\n };\n return {\n zero: new Float64Array(width),\n one: new Float64Array(width).fill(1),\n add: (a, b) => zip(a, b, (x, y) => x + y),\n sub: (a, b) => zip(a, b, (x, y) => x - y),\n mul: (a, b) => zip(a, b, (x, y) => x * y),\n compare: (a, b) => {\n let less = false;\n let more = false;\n for (let index = 0; index < width; index += 1) {\n const [x, y] = [a[index] ?? 0, b[index] ?? 0];\n if (x < y) less = true;\n else if (x > y) more = true;\n else if (x !== y) return Number.NaN;\n }\n return less ? (more ? Number.NaN : -1) : more ? 1 : 0;\n },\n };\n}\n\n/**\n * The chance of a stop at each point, from the Shannon expansion of `pathSetReliability`. A set works when each of its cuts is on.\n * One call gives `EXPANSION_WIDTH` points. When the steps of one expansion times the count of points pass `maxWork`, the result is `undefined`.\n * Else `steps` is the count of steps of one expansion.\n */\nfunction expandedChances(\n curves: readonly Survival[],\n sets: readonly (readonly number[])[],\n points: readonly number[],\n maxWork: number,\n): { readonly chances: number[]; readonly steps: number } | undefined {\n const maxSteps = Math.floor(maxWork / points.length);\n if (maxSteps < 1) return undefined;\n const out: number[] = [];\n let steps = 0;\n for (let start = 0; start < points.length; start += EXPANSION_WIDTH) {\n const times = points.slice(start, start + EXPANSION_WIDTH);\n const chances = curves.map((curve) => Float64Array.from(times, (days) => survivalAt(curve, days)));\n const result = pathSetReliability(sets, chances, vectorRing(times.length), { maxSteps });\n // Each call has the same sets, so the first call tells if the expansion is in the budget.\n if (result.kind === \"budget\") return undefined;\n steps = result.steps;\n for (const chance of result.value) out.push(Math.min(1, Math.max(0, chance)));\n }\n return { chances: out, steps };\n}\n\n/**\n * The curves of the stop of a draw. `event` is for one event that makes each cut longer together, and `independent` is for independent cuts.\n * `upper` is an upper limit for each dependence.\n */\nexport interface StopCurves {\n readonly event: Survival;\n /** The stop when the cuts are independent (`independentStop`). When `independentUpper` is true, it is `upper`. */\n readonly independent: Survival;\n readonly upper: Survival;\n /**\n * This is true when `upper` is the sum of the curves of the cuts that count, because the query has no minimal sets.\n * With a stack, the search of the needs passed its budget. With no stack, more than `MINIMAL_STOP_CUTS` cuts count.\n */\n readonly coarse: boolean;\n /** This is true when `independent` is `upper`: `coarse` is true, or the expansion of `independentStop` passed its budget. */\n readonly independentUpper: boolean;\n /**\n * The weakest bound (`weakestBound` of the core) of the curves of the cuts that the stop uses. Since 0.8.4.\n * With minimal sets, the stop uses the cuts of the sets. With no minimal sets, it uses each cut with a curve.\n * Each of the three curves does not decrease when a cut lasts longer, so it has this bound.\n */\n readonly bound: CutBound;\n}\n\n/** This function gives the parts of the stack that are down for a list of cut indexes. A case uses one memo for each of its draws. */\ntype StoppedOf = (cuts: readonly number[]) => ReadonlySet<string>;\n\nfunction stoppedMemo(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): StoppedOf {\n const memo = new Map<string, ReadonlySet<string>>();\n return (cuts) => {\n const key = cuts.join(\",\");\n let found = memo.get(key);\n if (found === undefined) {\n found = caseStopped({ ...caseCuts, cuts: cuts.flatMap((index) => caseCuts.cuts[index] ?? []) }, options);\n memo.set(key, found);\n }\n return found;\n };\n}\n\n/** This function gives the parts whose cut can stop a supply: the supply, and each part that it needs through the stack. */\nfunction supplyReach(supply: string, options: Pick<CaseOptions, \"stack\">): Set<string> {\n const reach = options.stack === undefined ? new Set<string>() : neededParts(options.stack, supply);\n reach.add(supply);\n return reach;\n}\n\nfunction stopCurvesWith(caseCuts: CaseCuts, draw: Draw, options: StopCurveOptions, stoppedOf: StoppedOf): StopCurves | undefined {\n const reach = supplyReach(draw.supply, options);\n const relevant = caseCuts.cuts.flatMap((cut, index) => (reach.has(cut.part) ? [index] : []));\n const stops = (cuts: readonly number[]): boolean => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);\n if (stops([])) return undefined;\n if (!stops(relevant.map((_, index) => index))) return undefined;\n const given = relevant.map((index) => caseCuts.cuts[index]?.duration);\n // With a stack, the needs give the minimal sets. When their search passes its budget, the sets of each list of cuts are the check.\n const parts = relevant.map((index) => caseCuts.cuts[index]?.part ?? \"\");\n const structural = options.stack === undefined ? undefined : stackStops(options.stack, draw.supply, parts, options.down, budgetsOf(options).maxSets);\n const sets = structural ?? minimalStops(given.length, stops);\n // The stop has no curve when a cut with no curve can be part of it. With no minimal sets, the query cannot tell.\n const unsourced = given.flatMap((curve, index) => (curve === undefined ? [index] : []));\n if (unsourced.length > 0 && (sets === undefined || sets.some((set) => set.some((index) => unsourced.includes(index))))) return undefined;\n // A cut with no curve is in no minimal set here, so it does not change a stop. The curves do not include it.\n const kept = given.flatMap((curve, index) => (curve === undefined ? [] : [index]));\n const curves = kept.map((index) => given[index] ?? []);\n const keptStops = (cuts: readonly number[]): boolean => stops(cuts.map((index) => kept[index] ?? -1));\n const keptSets = sets?.map((set) => set.map((index) => kept.indexOf(index)));\n const upper = upperStop(curves, keptSets);\n const independent = independentStop(curves, keptSets, budgetsOf(options).maxWork);\n // A cut in no minimal set does not change a stop, so its bound does not weaken the bound of the stop.\n const used = sets === undefined ? kept : kept.filter((index) => sets.some((set) => set.includes(index)));\n const bound = weakestBound(used.map((index) => caseCuts.cuts[relevant[index] ?? -1]?.bound ?? \"law\"));\n return { event: eventStop(curves, keptStops), independent: independent ?? upper, upper, coarse: keptSets === undefined, independentUpper: independent === undefined, bound };\n}\n\n/**\n * This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.\n *\n * - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.\n * - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.\n * - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.\n * - With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core), so the count of cuts has no limit of `MINIMAL_STOP_CUTS`.\n * When that search passes its budget (the option `maxSets`), `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.\n * - A cut with no `duration` gives no curve when it is in a minimal set, or when the query has no minimal sets.\n * - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.\n * - With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` is true.\n * - When the expansion of `independentStop` passes its budget, `independent` is `upper`, and `independentUpper` is true.\n * - `bound` is the weakest bound of the curves of the cuts that the stop uses. A cut with no `bound` has a law.\n */\nexport function stopCurves(caseCuts: CaseCuts, draw: Draw, options: StopCurveOptions = {}): StopCurves | undefined {\n budgetsOf(options);\n return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));\n}\n\n/** The shortfall of each level, in user-days, and the draws that the query cannot read. */\nexport interface Shortfall {\n /**\n * The user-days of each level of the layer, when one event makes each cut longer together. The query does not add two levels.\n * This value is not a limit. The true value can be more or less. `upper` is the limit.\n */\n readonly levels: Readonly<Record<string, number>>;\n /** The user-days of each level when the cuts are independent (`StopCurves.independent`). This value is not more than `upper`. */\n readonly independent: Readonly<Record<string, number>>;\n /** The upper limit of the user-days of each level, for each dependence of the cuts. A gate of a high level can use it. */\n readonly upper: Readonly<Record<string, number>>;\n /**\n * The needs of the draws whose stop has no curve (`stopCurves`).\n * The query has no curve of their duration, so their shortfall is not in `levels`. A gate shows them as no read.\n */\n readonly unread: readonly string[];\n /** The needs of the draws whose `upper` is coarse (`StopCurves.coarse`). A gate on `upper` shows them. */\n readonly coarse: readonly string[];\n /** The needs of the draws whose `independent` is `upper` (`StopCurves.independentUpper`). A gate on `independent` shows them. */\n readonly independentUpper: readonly string[];\n /**\n * The bound of the shortfall: the weakest bound (`weakestBound` of the core) of the curves that the query uses. Since 0.8.4.\n * The shortfall does not decrease when a cut lasts longer. So with `upper`, each value is too high or equal, and with `lower` too low or equal.\n * With `none`, a value can be too high or too low.\n *\n * A draw in `unread` and a case that adds 0 do not change the bound. With no curve, the bound is `law`.\n * The bound is for each of `levels`, `independent` and `upper`, each with its own rule of the dependence of the cuts.\n */\n readonly bound: CutBound;\n}\n\nfunction zeroLevels(layer: EnduranceLayer): Record<string, number> {\n return Object.fromEntries(layer.levels.map((level) => [level, 0]));\n}\n\n/**\n * This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.\n * `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param endurance - The endurance of the case, from `enduranceOf`\n * @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon\n * @throws RangeError when the horizon is not a number more than 0, or `maxSets` is not a whole number from 1\n */\nexport function caseShortfall(layer: EnduranceLayer, caseCuts: CaseCuts, endurance: Endurance, options: ShortfallOptions = {}): Shortfall {\n const horizon = horizonOf(options);\n budgetsOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const bounds: CutBound[] = [];\n const stoppedOf = stoppedMemo(caseCuts, options);\n for (const draw of caseDraws(layer, caseCuts, caseStopped(caseCuts, options))) {\n const held = endurance.needs[draw.need];\n const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);\n if (held === undefined || curves === undefined) {\n unread.push(draw.need);\n continue;\n }\n if (curves.coarse) coarse.push(draw.need);\n if (curves.independentUpper) independentUpper.push(draw.need);\n bounds.push(curves.bound);\n const users = draw.users ?? 1;\n levels[draw.level] = (levels[draw.level] ?? 0) + tailDays(curves.event, held.days, horizon) * users;\n independent[draw.level] = (independent[draw.level] ?? 0) + tailDays(curves.independent, held.days, horizon) * users;\n upper[draw.level] = (upper[draw.level] ?? 0) + tailDays(curves.upper, held.days, horizon) * users;\n }\n return { levels, independent, upper, unread, coarse, independentUpper, bound: weakestBound(bounds) };\n}\n\n/**\n * The share of the stores in a case. `take` is the take order of `enduranceOf`. `best` is the leximin share of\n * `bestEndurance`, level by level.\n */\nexport type Share = \"take\" | \"best\";\n\n/** The shares, with the default first. */\nexport const SHARES: readonly Share[] = [\"take\", \"best\"];\n\n/** This function gives the share of the options. The default is `take`. */\nfunction shareOf(options: { readonly share?: Share | undefined }): Share {\n const share = options.share ?? \"take\";\n if (!SHARES.includes(share)) throw new RangeError(`The share ${String(options.share)} is not ${SHARES.join(\" or \")}.`);\n return share;\n}\n\n/** This function gives the endurance of a case with a share: `enduranceOf` for `take`, `bestEndurance` with the horizon for `best`. */\nfunction shareEndurance(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions & ShortfallOptions, share: Share): Endurance {\n return share === \"best\" ? bestEndurance(layer, caseCuts, options) : enduranceOf(layer, caseCuts, options);\n}\n\n/** The options of `yearShortfall`: the date, the stack or the parts that are also down, the horizon and the share. */\nexport interface YearShortfallOptions extends CaseOptions, ShortfallOptions {\n /**\n * The share of the stores in each case. The default `take` gives the endurance from `enduranceOf`. With `best`,\n * the endurance comes from `bestEndurance`, and the horizon of the shortfall is the horizon of the share. Thus a\n * draw at the horizon keeps back only the horizon times its demand, and the lower levels get the rest.\n */\n readonly share?: Share | undefined;\n}\n\n/** The shortfall of one year at one place, with the part of each case. */\nexport interface YearShortfall extends Shortfall {\n readonly place: string;\n /** The part of each case. `rate` is the expected count of its events in one year. */\n readonly cases: readonly { readonly case: string; readonly rate: number; readonly endurance: Endurance; readonly shortfall: Shortfall }[];\n}\n\n/**\n * This function gives the shortfall of one year at one place.\n * It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.\n *\n * - The expected count of a case is `perYear * reach`, from the first prior of the case at the place. Thus the result is the expected user-days of one year.\n * - A case with no prior at the place is not in the sum.\n * - `unread` is the union of the needs that a case cannot read, in the order of the cases. `coarse` and `independentUpper` are unions too.\n * - `bound` is the weakest bound of the cases in the sum. A case with no prior, or with an expected count of 0, adds 0, so it does not change the bound.\n *\n * - With `share: \"best\"`, the endurance of each case comes from `bestEndurance` with the horizon of the shortfall.\n *\n * @param layer - The endurance layer, with its cases and priors\n * @param place - The place of the priors\n * @param options - The date, the stack or the parts that are also down, the horizon and the share\n * @throws RangeError for a bad date, horizon, `maxSets` or share: refer to `caseShortfall` and `enduranceOf`\n */\nexport function yearShortfall(layer: EnduranceLayer, place: string, options: YearShortfallOptions): YearShortfall {\n horizonOf(options);\n budgetsOf(options);\n const share = shareOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const cases: YearShortfall[\"cases\"][number][] = [];\n const bounds: CutBound[] = [];\n for (const caseCuts of layer.cases ?? []) {\n const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);\n if (prior === undefined) continue;\n const rate = yearRate(prior);\n const endurance = shareEndurance(layer, caseCuts, options, share);\n const shortfall = caseShortfall(layer, caseCuts, endurance, options);\n for (const [level, days] of Object.entries(shortfall.levels)) levels[level] = (levels[level] ?? 0) + rate * days;\n for (const [level, days] of Object.entries(shortfall.independent)) independent[level] = (independent[level] ?? 0) + rate * days;\n for (const [level, days] of Object.entries(shortfall.upper)) upper[level] = (upper[level] ?? 0) + rate * days;\n for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);\n for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);\n for (const need of shortfall.independentUpper) if (!independentUpper.includes(need)) independentUpper.push(need);\n if (rate > 0) bounds.push(shortfall.bound);\n cases.push({ case: caseCuts.case, rate, endurance, shortfall });\n }\n return { place, levels, independent, upper, unread, coarse, independentUpper, bound: weakestBound(bounds), cases };\n}\n\n/** The options of `caseOutlook`: the date, the stack or the parts that are also down, the horizon and the share. */\nexport type OutlookOptions = YearShortfallOptions;\n\n/** A value for each curve of the stop of a draw (`StopCurves`). */\nexport interface CurveValues {\n /** The value when one event makes each cut longer together. */\n readonly event: number;\n /** The value when the cuts are independent. */\n readonly independent: number;\n /** The value of the upper curve: the safe side for each dependence of the cuts. */\n readonly upper: number;\n}\n\n/** The chance and the shortfall of a draw at one end of the sampling bands of its cuts. Since 0.8.14. */\nexport interface BandValues {\n readonly lasts: CurveValues;\n readonly shortfall: CurveValues;\n}\n\n/**\n * The values of a draw at the two ends of the sampling bands of its cuts (`Cut.band`). Since 0.8.14.\n * `shorter` puts each cut at the low end of its band, and `longer` puts each cut at the high end.\n * Each end holds only pointwise, so the two values are a range of the sampling error, not a joint interval.\n */\nexport interface DrawBand {\n readonly shorter: BandValues;\n readonly longer: BandValues;\n}\n\n/** The outlook of one draw in one event of a case. */\nexport interface DrawOutlook {\n readonly need: string;\n readonly level: string;\n readonly supply: string;\n readonly users: number;\n /** The days that the stores give the draw (`DrawEndurance.days`). */\n readonly days: number;\n /** This is true when the draw holds to the horizon of a best share. */\n readonly atHorizon?: true;\n /**\n * The chance that the draw gets its need through the event: `P(min(D, h) <= T)`, for each curve of the stop.\n * `D` is the duration of the stop, `T` is `days` and `h` is the horizon. A draw that holds to the horizon has the chance 1.\n * The chance of `upper` is not more than the true chance, for each dependence of the cuts.\n */\n readonly lasts: CurveValues;\n /** The user-days of the shortfall in one event, `E[max(0, min(D, h) - T)] * users`, for each curve. */\n readonly shortfall: CurveValues;\n /** The bound of the curves of the stop (`StopCurves.bound`). */\n readonly bound: CutBound;\n /** This is true when the upper curve is coarse (`StopCurves.coarse`). */\n readonly coarse: boolean;\n /**\n * The values at the two ends of the sampling bands of the cuts, with the same days. Since 0.8.14.\n * It is missing when a cut that can be part of the stop has a curve and no band. Then the sampling error has no read.\n */\n readonly band?: DrawBand | undefined;\n}\n\n/** The outlook of one event of a case: the days, the chance and the shortfall of each draw. */\nexport interface CaseOutlook {\n readonly case: string;\n readonly title: string;\n readonly at: string;\n readonly share: Share;\n /** The horizon in days, or `undefined` for no horizon. */\n readonly horizon: number | undefined;\n /** Each draw whose supply the case stops and whose stop has a curve, in the order of the layer. */\n readonly draws: readonly DrawOutlook[];\n /** The needs of the draws whose supply the case does not stop. They get their need through the event. */\n readonly holds: readonly string[];\n /** The needs of the draws whose stop has no curve (`stopCurves`). They are no read, not a pass. */\n readonly unread: readonly string[];\n /** The weakest bound of the curves of `draws`. */\n readonly bound: CutBound;\n}\n\n/**\n * This function gives the outlook of one event of a case. For each draw, it gives the days, the chance that the\n * stores last through the stop, and the shortfall. A page of a place can show it for each case of its region.\n *\n * - The days come from the share of the stores: `enduranceOf` for `take`, `bestEndurance` with the horizon for `best`.\n * - The chance and the shortfall use the curves of `stopCurves`. They count the stop only up to the horizon.\n * - `upper` is the safe side: its chance is not more, and its shortfall is not less, than the true value for each dependence.\n * - `band` gives the same values with each cut at each end of its sampling band (`Cut.band`). The days do not change.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, the stack or the parts that are also down, the horizon and the share\n * @throws RangeError for a bad date, horizon, `maxSets` or share: refer to `caseShortfall` and `enduranceOf`\n */\nexport function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, options: OutlookOptions): CaseOutlook {\n const horizon = horizonOf(options);\n budgetsOf(options);\n const share = shareOf(options);\n const endurance = shareEndurance(layer, caseCuts, options, share);\n const stopped = caseDraws(layer, caseCuts, caseStopped(caseCuts, options));\n const stoppedNeeds = new Set(stopped.map((draw) => draw.need));\n const stoppedOf = stoppedMemo(caseCuts, options);\n // Each end of the bands: a cut with a band takes that end as its curve, and a cut with no band has no curve.\n const banded = caseCuts.cuts.some((cut) => cut.band !== undefined);\n const endCuts = (end: \"low\" | \"high\"): CaseCuts => ({ ...caseCuts, cuts: caseCuts.cuts.map(({ duration: _, band, ...cut }) => (band === undefined ? cut : { ...cut, duration: band[end], band })) });\n const ends = banded ? { shorter: endCuts(\"low\"), longer: endCuts(\"high\") } : undefined;\n const draws: DrawOutlook[] = [];\n const unread: string[] = [];\n const bounds: CutBound[] = [];\n for (const draw of stopped) {\n const held = endurance.needs[draw.need];\n const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);\n if (held === undefined || curves === undefined) {\n unread.push(draw.need);\n continue;\n }\n const users = draw.users ?? 1;\n const lasts = (curve: Survival): number => (held.days >= horizon ? 1 : 1 - survivalAt(curve, held.days));\n const short = (curve: Survival): number => tailDays(curve, held.days, horizon) * users;\n const values = (stop: StopCurves): BandValues => ({\n lasts: { event: lasts(stop.event), independent: lasts(stop.independent), upper: lasts(stop.upper) },\n shortfall: { event: short(stop.event), independent: short(stop.independent), upper: short(stop.upper) },\n });\n const shorter = ends === undefined ? undefined : stopCurvesWith(ends.shorter, draw, options, stoppedOf);\n const longer = ends === undefined ? undefined : stopCurvesWith(ends.longer, draw, options, stoppedOf);\n const band = shorter === undefined || longer === undefined ? {} : { band: { shorter: values(shorter), longer: values(longer) } };\n bounds.push(curves.bound);\n draws.push({\n need: draw.need,\n level: draw.level,\n supply: draw.supply,\n users,\n days: held.days,\n ...(held.atHorizon === true ? { atHorizon: true as const } : {}),\n ...values(curves),\n bound: curves.bound,\n coarse: curves.coarse,\n ...band,\n });\n }\n const holds = layer.draws.filter((draw) => !stoppedNeeds.has(draw.need)).map((draw) => draw.need);\n return {\n case: caseCuts.case,\n title: caseCuts.title,\n at: endurance.at,\n share,\n horizon: Number.isFinite(horizon) ? horizon : undefined,\n draws,\n holds,\n unread,\n bound: weakestBound(bounds),\n };\n}\n","import { STACK_SCHEMA, type Stack } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// A sample: a building with 3 users, and a storm that cuts the grid, the road and the water main.\n// Each name and each value is an example, except the grid curve (NREL, technical report 83092). The tests, the README files and the site use it.\n\n/** The base stack of the sample: the supplies of the building and a camp stove. */\nexport const SAMPLE_ENDURANCE_STACK: Stack = {\n schema: STACK_SCHEMA,\n parts: [\n { id: \"grid\", kind: \"power\", name: \"The power grid\" },\n { id: \"water-main\", kind: \"water\", name: \"The water main\" },\n { id: \"road\", kind: \"road\", name: \"The local road to the shops\" },\n { id: \"stove\", kind: \"device\", name: \"The camp stove\" },\n ],\n};\n\n/**\n * The endurance layer of the sample.\n *\n * - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.\n * - The food holds 4800 / 5400 = 0.889 days. The rice needs 2 L of water for each kg, and the drinking water keeps back all the water.\n * - The power holds 1000 Wh / 150 Wh a day = 6.667 days.\n * - The filled bottles are past their due date, so they give nothing.\n */\nexport const SAMPLE_ENDURANCE: EnduranceLayer = {\n schema: ENDURANCE_SCHEMA,\n levels: [\"life\", \"health\", \"comfort\"],\n resources: [\n { code: \"water.stored\", unit: \"L\" },\n { code: \"food.ready\", unit: \"kcal\" },\n { code: \"food.grain-dry\", unit: \"kg\" },\n { code: \"fuel.propane\", unit: \"kg\" },\n { code: \"energy.battery\", unit: \"Wh\" },\n ],\n stores: [\n { id: \"jugs\", resource: \"water.stored\", amount: 75.7, due: \"2028-06-01\" },\n { id: \"bottles\", resource: \"water.stored\", amount: 20, due: \"2026-09-30\" },\n { id: \"cans\", resource: \"food.ready\", amount: 4800, due: \"2028-10-01\" },\n { id: \"rice\", resource: \"food.grain-dry\", amount: 9, due: \"2036-09-28\" },\n { id: \"propane\", resource: \"fuel.propane\", amount: 0.908, due: \"2036-10-01\" },\n { id: \"battery\", resource: \"energy.battery\", amount: 1000, due: \"2031-10-01\" },\n ],\n draws: [\n { need: \"hydration.drink\", level: \"life\", perDay: 11.355, users: 3, supply: \"water-main\" },\n { need: \"food.energy\", level: \"health\", perDay: 5400, users: 3, supply: \"road\" },\n { need: \"power.electric\", level: \"comfort\", perDay: 150, users: 3, supply: \"grid\" },\n ],\n direct: [\n { resource: \"water.stored\", need: \"hydration.drink\", amount: 1 },\n { resource: \"food.ready\", need: \"food.energy\", amount: 1 },\n { resource: \"energy.battery\", need: \"power.electric\", amount: 1 },\n ],\n converters: [\n {\n id: \"cook-rice\",\n device: \"stove\",\n takes: [\n { resource: \"food.grain-dry\", amount: 1 },\n { resource: \"water.stored\", amount: 2 },\n { resource: \"fuel.propane\", amount: 0.05 },\n ],\n gives: { need: \"food.energy\", amount: 3600 },\n },\n ],\n cases: [\n {\n case: \"storm\",\n title: \"Winter storm\",\n cuts: [\n { part: \"grid\", title: \"Power outage\", duration: [[0, 1], [0.5, 0.5], [1, 0.36], [7, 0.013], [30, 0]], source: \"nrel-83092\" },\n { part: \"road\", title: \"Closed local road\", duration: [[0, 1], [1, 0.6], [3, 0.2], [10, 0]], source: \"sample\" },\n { part: \"water-main\", title: \"No water from the main\", duration: [[0, 1], [2, 0.3], [7, 0]], source: \"sample\" },\n ],\n leadSeconds: 86_400,\n },\n { case: \"fire\", title: \"Fire\", cuts: [] },\n ],\n priors: [\n { case: \"storm\", place: \"home\", perYear: 0.8, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n { case: \"fire\", place: \"home\", perYear: 0.003, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n ],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB,UAAU,OAAuB,UAAoB,SAAsB,OAAqC;CAC9H,MAAM,QAAQ,IAAI,IAAI,MAAM,MAAM,KAAK,SAAS,KAAK,IAAI,CAAC;CAC1D,MAAM,UAAU,MAAM,QAAQ,SAAS,CAAC,MAAM,IAAI,IAAI,CAAC;CACvD,IAAI,QAAQ,SAAS,GAAG,MAAM,IAAI,WAAW,aAAa,QAAQ,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,0CAA0C;CAClJ,MAAM,eAAe,YAAY,UAAU,OAAO;CAClD,MAAM,QAAQ,aAAa,OAAO,QAAQ,IAAI,YAAY;CAC1D,MAAM,SAAS,IAAI,IAAI,KAAK;CAC5B,MAAM,OAAO,UAAU,OAAO,UAAU,YAAY,CAAC,CAAC,QAAQ,SAAS,OAAO,IAAI,KAAK,IAAI,CAAC;CAC5F,MAAM,UAAU,IAAI,IAAI,KAAK,KAAK,SAAS,KAAK,IAAI,CAAC;CACrD,MAAM,OAAO;EAAE,MAAM,SAAS;EAAM,IAAI,QAAQ;EAAI,MAAM,KAAK,KAAK,SAAS,KAAK,IAAI;EAAG,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,SAAS,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK;CAAE;CACxJ,MAAM,UAAqB;EAAE,GAAG;EAAM,MAAM;EAAU,OAAO,CAAC;EAAG,SA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E,MAAM;IAAc,OAAO;IAA0B,UAAU;KAAC,CAAC,GAAG,CAAC;KAAG,CAAC,GAAG,EAAG;KAAG,CAAC,GAAG,CAAC;IAAC;IAAG,QAAQ;GAAS;EAChH;EACA,aAAa;CACf,GACA;EAAE,MAAM;EAAQ,OAAO;EAAQ,MAAM,CAAC;CAAE,CAC1C;CACA,QAAQ,CACN;EAAE,MAAM;EAAS,OAAO;EAAQ,SAAS;EAAK,OAAO;EAAG,QAAQ;EAAU,MAAM;CAAa,GAC7F;EAAE,MAAM;EAAQ,OAAO;EAAQ,SAAS;EAAO,OAAO;EAAG,QAAQ;EAAU,MAAM;CAAa,CAChG;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["horizonOf"],"sources":["../src/joint.ts","../src/best.ts","../src/stops.ts","../src/shortfall.ts","../src/sample.ts"],"sourcesContent":["import { type Objective, solveLexicographic } from \"@mark1russell7/linear\";\nimport { add, div, equals, mul, neg, ONE, type Rational, sign, toNumber, ZERO } from \"@mark1russell7/rational\";\nimport { type CaseOptions, caseDraws, caseStopped, drawDemand, storeAmounts } from \"./endurance.ts\";\nimport type { CaseCuts, Converter, EnduranceLayer, IsoDate } from \"./layer.ts\";\nimport { caseParts, deviceUse, drawBlock, fewestRow, Program, reachOf, valueAt } from \"./program.ts\";\nimport { addTo, dense, exact, type Row } from \"./rows.ts\";\n\n// The joint days: the largest count of days that a set of draws holds together, with the best share of the stores.\n// The query is a linear program over the totals of the span, with exact rationals (@mark1russell7/linear).\n\n/** The joint days of a set of draws in a case, with the share of the stores at the optimum. */\nexport interface JointDays {\n readonly case: string;\n readonly at: IsoDate;\n /**\n * The largest count of days that each draw of `plan` holds at the same time. It is `Infinity` when `plan` is empty,\n * or when the stores give each draw of `plan` without end.\n */\n readonly days: number;\n /** The needs of the set that take from the stores: the case stops their supply, and their demand is more than 0. The order is the order of `caseDraws`. */\n readonly plan: readonly string[];\n /** The needs of the set that take nothing from the stores, in the order of their codes. The case does not stop their supply, or their demand is 0. */\n readonly holds: readonly string[];\n /**\n * The amount of each resource that each draw of `plan` takes from the stores in `days`. The keys are the code of the need, then the code of the resource.\n * A take through a converter that makes a resource counts the inputs of the converter. A resource with no take is not in the record.\n * The record is empty when `days` is `Infinity`.\n */\n readonly takes: Readonly<Record<string, Readonly<Record<string, number>>>>;\n /**\n * The resources that limit `days`, in the order of their codes. Each one has a store in the layer, is an input of `plan` through each chain,\n * and has no stock left at the optimum. The list is empty when `days` is `Infinity`.\n */\n readonly binding: readonly string[];\n /** The count of runs of each converter at the optimum, by the `id` of the converter. A converter with no run is not in the record. */\n readonly runs: Readonly<Record<string, number>>;\n /**\n * The converters of the plan whose limit `perDay` stops more runs at the optimum, in the order of their `id`. A converter of the plan\n * gives a need of the plan, or makes an input of the plan through each chain.\n * The list is empty when `days` is `Infinity` or 0. Else it has each converter of the plan with a limit of 0.\n */\n readonly capped: readonly string[];\n}\n\n/**\n * This function gives the joint days of a set of draws. These are the largest count of days `d` at which each draw holds `d` days.\n * The draws hold at the same time, with the best share of the stores and of the runs of the converters.\n *\n * - The function solves a linear program over the totals of the span. Its variables are `d`, the take of each direct use,\n * the runs of each converter, and the share of each stock.\n * - Each draw of the plan gets `d` times its demand (`drawDemand`) from its direct uses and from the converters that give its need.\n * - The takes of each resource are not more than its stock (`storeAmounts` at `at`) plus the gifts of the converters that make it.\n * - A converter whose device stops gives nothing, and a store whose part stops gives nothing, as in `enduranceOf`.\n * - The runs of a converter with a limit `perDay` are not more than `perDay` times `devices` times `d`. The converters of one device share it, as in `enduranceOf`.\n * - A store counts with all of its amount when its due date is after `at`, as in `enduranceOf`. A due date in the span has no effect.\n * - After the largest `d`, a second objective takes the smallest sum of the shares of the stocks. Thus the takes have no waste.\n * - A third objective takes the fewest device-days of the converters. Thus the runs are not more than the plan uses.\n * - The draws that are not in the set are outside this plan. They take nothing in the program.\n * - A need of the set whose supply works, or whose demand is 0, holds without end. It goes in `holds`, as `enduranceOf` leaves it out.\n *\n * The take order of `enduranceOf` gives the stores to a higher draw first. This function gives one share for the whole set.\n * Thus a draw of the set can get fewer days here than alone, and a lower draw can get more.\n *\n * The program uses exact rationals, so the result has no error of the method. Only the change back to a number rounds.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, and the stack or the parts that are also down\n * @param needs - The codes of the needs of the draws of the set\n * @returns The joint days, the takes of each draw, the binding resources and the runs of each converter\n * @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`.\n */\nexport function jointDays(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions, needs: readonly string[]): JointDays {\n const known = new Set(layer.draws.map((draw) => draw.need));\n const unknown = needs.filter((need) => !known.has(need));\n if (unknown.length > 0) throw new RangeError(`The needs ${unknown.map((need) => `\"${need}\"`).join(\", \")} are not the needs of draws of the layer.`);\n const stoppedParts = caseStopped(caseCuts, options);\n const stock = storeAmounts(layer, options.at, stoppedParts);\n const wanted = new Set(needs);\n const plan = caseDraws(layer, caseCuts, stoppedParts).filter((draw) => wanted.has(draw.need));\n const planned = new Set(plan.map((draw) => draw.need));\n const base = { case: caseCuts.case, at: options.at, plan: plan.map((draw) => draw.need), holds: [...wanted].filter((need) => !planned.has(need)).sort() };\n const endless: JointDays = { ...base, days: Infinity, takes: {}, binding: [], runs: {}, capped: [] };\n if (plan.length === 0) return endless;\n\n const parts = caseParts(layer, stoppedParts, stock, planned);\n const program = new Program();\n const days = program.next();\n const blocks = plan.map((draw) => {\n const block = drawBlock(program, parts, draw);\n // The need of the draw: its gifts are not less than its demand times the days.\n const need: Row = new Map(block.gifts);\n addTo(need, days, neg(exact(drawDemand(draw, caseCuts))));\n program.push(need, \">=\", ZERO);\n return block;\n });\n // The limit of each device: the runs use `devices` times `d` device-days or less. A limit of 0 stops the converter.\n const runCols = blocks.flatMap((block) => [...block.runs]);\n const { limits, stopped } = deviceUse(runCols);\n for (const index of stopped) program.push(new Map([[index, ONE]]), \"<=\", ZERO);\n for (const limit of limits.values()) {\n const row: Row = new Map(limit.row);\n addTo(row, days, neg(exact(limit.devices)));\n program.push(row, \"<=\", ZERO);\n }\n // The shares of each stock are not more than the stock.\n for (const resource of parts.stocked) {\n const row: Row = new Map();\n // A draw has a share only of a resource that it can use (`drawBlock`).\n for (const block of blocks) {\n const index = block.shares.get(resource);\n if (index !== undefined) addTo(row, index, ONE);\n }\n if (row.size > 0) program.push(row, \"<=\", exact(stock.get(resource) ?? 0));\n }\n\n const most: Row = new Map([[days, ONE]]);\n const least: Row = new Map();\n for (const block of blocks) for (const [resource, index] of block.shares) addTo(least, index, div(ONE, exact(stock.get(resource) ?? 1)));\n // The third objective takes the fewest device-days. Thus a converter whose inputs cost no stock does not give more runs than the plan uses,\n // and `runs` and `capped` have one value.\n const objectives: Objective[] = [\n { sense: \"max\", coefficients: dense(most, program.count) },\n { sense: \"min\", coefficients: dense(least, program.count) },\n { sense: \"min\", coefficients: dense(fewestRow(runCols), program.count) },\n ];\n const solved = solveLexicographic(program.constraints(), objectives);\n // The point 0 is feasible and the later objectives are not less than 0. So only an unbounded first stage has no optimum.\n if (solved.status !== \"optimal\") return endless;\n\n const x = solved.x;\n const takes: Record<string, Record<string, number>> = {};\n for (const block of blocks) {\n const record: Record<string, number> = {};\n for (const [resource, index] of block.shares) if (sign(x[index] ?? ZERO) > 0) record[resource] = toNumber(x[index] ?? ZERO);\n takes[block.draw.need] = record;\n }\n // A converter gives a need or a resource, so it is a cook or a maker, not the two.\n const total = new Map<Converter, Rational>();\n for (const [converter, index] of runCols) total.set(converter, add(total.get(converter) ?? ZERO, x[index] ?? ZERO));\n const runs: Record<string, number> = {};\n for (const [converter, value] of total) if (sign(value) > 0) runs[converter.id] = toNumber(value);\n\n const withStore = new Set(layer.stores.map((store) => store.resource));\n // The converters that the plan can use: the converters that give a need of the plan, and the makers of the resources of the closure.\n const { closure, reach } = reachOf(parts, planned);\n const binding = [...closure]\n .filter((resource) => withStore.has(resource))\n .filter((resource) => {\n // A resource with no live stock has no share, so its take is 0 and it is used up.\n const taken = blocks.reduce((sum, block) => {\n const index = block.shares.get(resource);\n return index === undefined ? sum : add(sum, x[index] ?? ZERO);\n }, ZERO);\n return equals(taken, exact(stock.get(resource) ?? 0));\n })\n .sort();\n const best = solved.values[0] ?? ZERO;\n const capped = sign(best) > 0\n ? [\n ...[...total.keys()].filter((converter) => converter.perDay !== undefined && !(converter.perDay > 0)),\n ...[...limits.values()].filter((limit) => equals(valueAt(limit.row, x), mul(exact(limit.devices), best))).flatMap((limit) => limit.converters),\n ]\n .filter((converter) => reach.has(converter))\n .map((converter) => converter.id)\n .sort()\n : [];\n return { ...base, days: toNumber(best), takes, binding, runs, capped };\n}\n","import { type Objective, solveLexicographic } from \"@mark1russell7/linear\";\nimport { add, div, equals, mul, neg, ONE, type Rational, sign, sub, toNumber, ZERO } from \"@mark1russell7/rational\";\nimport { type CaseOptions, caseDraws, caseStopped, drawDemand, storeAmounts } from \"./endurance.ts\";\nimport type { CaseCuts, Converter, Draw, DrawEndurance, Endurance, EnduranceLayer } from \"./layer.ts\";\nimport { type CaseParts, caseParts, deviceUse, drawBlock, type DrawBlock, fewestRow, Program, reachOf, valueAt } from \"./program.ts\";\nimport { addTo, dense, exact, type Row } from \"./rows.ts\";\n\n// The best endurance: the days of each draw with the best share of the stores, the most important level first.\n// Each step is a linear program over the totals of the spans, with exact rationals (@mark1russell7/linear).\n\n/** A draw whose days are fixed. */\ninterface Fixed {\n /** The span of the draw in the programs: its days, or 1 for a draw with no end. */\n readonly span: Rational;\n /** True for a draw that holds without end. It takes no stock, and its span is one day. */\n readonly endless: boolean;\n /** The device-days of each day that the draw keeps, by the key of the device. */\n readonly keep: ReadonlyMap<string, Rational>;\n /** The `id` of each converter whose limit stops more runs at the step that fixes the draw. */\n readonly capped: readonly string[];\n /** True for a draw that holds the horizon. */\n readonly atHorizon: boolean;\n}\n\n/** The options of `bestEndurance`: the options of a case, and a horizon. */\nexport interface BestOptions extends CaseOptions {\n /**\n * The horizon in days, more than 0. The default is no horizon. A draw holds the horizon at most, thus it keeps back\n * only the horizon times its demand. The rest of the stores goes to the lower levels. Use the target of a plan, for\n * example 14 days, to ask if each draw holds the target.\n */\n readonly horizon?: number | undefined;\n}\n\n/** This function gives the horizon as a rational, or undefined for no horizon. It throws a `RangeError` for a horizon that is not more than 0. */\nfunction horizonOf(horizon: number | undefined): Rational | undefined {\n if (horizon === undefined || horizon === Infinity) return undefined;\n if (!(horizon > 0) || !Number.isFinite(horizon)) throw new RangeError(`The horizon ${String(horizon)} is not a number of days more than 0.`);\n return exact(horizon);\n}\n\n/** A program of one step, with the indexes of its parts. */\ninterface Step {\n readonly program: Program;\n readonly blocks: readonly DrawBlock[];\n /** The column of the common days of the open draws. */\n readonly floor: number;\n /** The row `days - floor >= 0` of each open draw, by the code of its need. */\n readonly floors: ReadonlyMap<string, number>;\n /** The run columns of the open draws. */\n readonly openRuns: readonly (readonly [Converter, number])[];\n /** The device-days of the open draws for each device, with the device-days of each day that the fixed draws leave. */\n readonly shared: ReadonlyMap<string, { readonly row: Row; readonly room: Rational; readonly converters: readonly Converter[] }>;\n}\n\n/**\n * This function gives the days that each draw holds when a case stops its supply. The stores and the devices have their best share.\n * The result has the form of `enduranceOf`, so `caseShortfall` takes it.\n *\n * The share is lexicographic. The draws of the first level get their best days, then the draws of the next level get theirs, and so on.\n * In one level, the share is the best for the draw with the fewest days, then for the next draw, and so on (the leximin share).\n * Thus a draw of a level cannot take a store that another draw of the level needs more.\n *\n * - The function solves a sequence of linear programs over the totals of the spans. Each program has the days of the open draws\n * and their common floor. For each draw, it has the take of each direct use, the runs of each converter and the share of each stock.\n * - Each step takes the largest floor. A draw whose floor row has a dual value that is not 0 cannot get more days. The step fixes its days.\n * The dual values of the floor rows add to 1, so each step fixes one draw or more.\n * - A fixed draw keeps its days in each later step. Its share of the stocks can change, so a later draw can get a store that it does not need.\n * - The stores, the direct uses, the converters and the devices follow the rules of `jointDays`. A store counts with all of its amount when its due date is after `at`.\n * - A fixed draw keeps the device-days of each day that it uses at its step, for all the days of the later draws. This is the safe side, as in `enduranceOf`.\n * The exact share of a device between two spans is not a linear program: the device-days of a day are the runs over the span.\n * - A step with no largest floor gives the open draws no end. Each of them takes no stock, and keeps the fewest device-days of each day.\n * - At the end, a program takes the smallest sum of the shares of the stocks, each over its stock, then the fewest device-days.\n * These are the takes of the result. A resource in `binding` has no stock left at this point.\n * - A draw in `capped` used a device with no device-days left at the step that fixed it.\n * - With a horizon, the floor of each step is the horizon at most. A step whose floor is the horizon fixes each of its\n * open draws at the horizon, with `atHorizon`. Such a draw takes only the horizon times its demand. A draw with no\n * end also holds the horizon. With no horizon, the result is the same as before the option.\n *\n * The programs use exact rationals, so the result has no error of the method. Only the change back to a number rounds.\n * The fewest days of the first level are the joint days (`jointDays`) of the draws of that level.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, the stack or the parts that are also down, and the horizon\n * @returns The endurance of each draw whose supply stops\n * @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.\n */\nexport function bestEndurance(layer: EnduranceLayer, caseCuts: CaseCuts, options: BestOptions): Endurance {\n const horizon = horizonOf(options.horizon);\n const stoppedParts = caseStopped(caseCuts, options);\n const stock = storeAmounts(layer, options.at, stoppedParts);\n const draws = caseDraws(layer, caseCuts, stoppedParts);\n const parts = caseParts(layer, stoppedParts, stock, new Set(draws.map((draw) => draw.need)));\n // The count of devices of each key. The gate refuses two counts for one device.\n const devices = new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0] as const)).limits].map(([key, limit]) => [key, limit.devices] as const));\n const fixed = new Map<string, Fixed>();\n\n for (const level of levelGroups(layer, draws)) {\n let open = level;\n while (open.length > 0) {\n const step = buildStep(parts, caseCuts, draws, fixed, open, devices, \"span\", horizon);\n const solved = solveLexicographic(step.program.constraints(), [\n { sense: \"max\", coefficients: dense(new Map([[step.floor, ONE]]), step.program.count) },\n { sense: \"min\", coefficients: dense(fewestRow(step.openRuns), step.program.count) },\n ]);\n if (solved.status !== \"optimal\") {\n if (solved.status === \"infeasible\") throw new Error(\"The step of the best endurance has no point. The point of the last step is a point of it.\");\n fixEndless(parts, caseCuts, draws, fixed, open, devices);\n break;\n }\n const floor = solved.values[0] ?? ZERO;\n const first = solved.stages[0]?.result;\n const dual = first?.status === \"optimal\" ? first.dual : [];\n const atHorizon = horizon !== undefined && equals(floor, horizon);\n let done = atHorizon ? open : open.filter((draw) => sign(dual[step.floors.get(draw.need) as number] ?? ZERO) !== 0);\n // The dual values of the floor rows add to 1. Thus `done` is not empty. The fallback fixes each open draw at the floor.\n if (done.length === 0) done = open;\n const full = new Set([...step.shared].filter(([, limit]) => equals(valueAt(limit.row, solved.x), mul(limit.room, floor))).map(([key]) => key));\n for (const draw of done) {\n const block = step.blocks.find((item) => item.draw.need === draw.need) as DrawBlock;\n const keep = new Map<string, Rational>();\n for (const [key, limit] of deviceUse(block.runs).limits) keep.set(key, sign(floor) > 0 ? div(valueAt(limit.row, solved.x), floor) : ZERO);\n const { reach } = reachOf(parts, new Set([draw.need]));\n const capped = sign(floor) > 0\n ? [...reach]\n .filter((converter) => converter.perDay !== undefined && (!(converter.perDay > 0) || [...full].some((key) => step.shared.get(key)?.converters.includes(converter))))\n .map((converter) => converter.id)\n .sort()\n : [];\n fixed.set(draw.need, { span: floor, endless: false, keep, capped, atHorizon });\n }\n const fixedNow = new Set(done.map((draw) => draw.need));\n open = open.filter((draw) => !fixedNow.has(draw.need));\n }\n }\n\n const needs: Record<string, DrawEndurance> = {};\n if (draws.length === 0) return { case: caseCuts.case, at: options.at, needs };\n const last = buildStep(parts, caseCuts, draws, fixed, [], devices, \"span\");\n const least: Row = new Map();\n for (const block of last.blocks) for (const [resource, index] of block.shares) addTo(least, index, div(ONE, exact(stock.get(resource) ?? 1)));\n const objectives: Objective[] = [\n { sense: \"min\", coefficients: dense(least, last.program.count) },\n { sense: \"min\", coefficients: dense(fewestRow(last.blocks.flatMap((block) => [...block.runs])), last.program.count) },\n ];\n const solved = solveLexicographic(last.program.constraints(), objectives);\n if (solved.status !== \"optimal\") throw new Error(\"The last program of the best endurance has no optimum. The point of the last step is a point of it.\");\n const withStore = new Set(layer.stores.map((store) => store.resource));\n for (const block of last.blocks) {\n const need = block.draw.need;\n const fix = fixed.get(need) as Fixed;\n if (fix.endless) {\n needs[need] = { days: Infinity, binding: [], takes: {} };\n continue;\n }\n const takes: Record<string, number> = {};\n for (const [resource, index] of block.shares) if (sign(solved.x[index] ?? ZERO) > 0) takes[resource] = toNumber(solved.x[index] ?? ZERO);\n const { closure } = reachOf(parts, new Set([need]));\n const binding = [...closure]\n .filter((resource) => withStore.has(resource))\n .filter((resource) => {\n // A resource with no live stock has no share, so its take is 0 and it is used up.\n const taken = last.blocks.reduce((sum, item) => {\n const index = item.shares.get(resource);\n return index === undefined ? sum : add(sum, solved.x[index] ?? ZERO);\n }, ZERO);\n return equals(taken, exact(stock.get(resource) ?? 0));\n })\n .sort();\n const days = toNumber(fix.span);\n needs[need] = { days, binding, takes, ...(fix.capped.length === 0 ? {} : { capped: fix.capped }), ...(fix.atHorizon ? { atHorizon: true as const } : {}) };\n }\n return { case: caseCuts.case, at: options.at, needs };\n}\n\n/** This function gives the draws of each level, in the order of `levels`. The draws of a level that is not in `levels` come last, together. */\nfunction levelGroups(layer: EnduranceLayer, draws: readonly Draw[]): Draw[][] {\n const rank = (draw: Draw): number => {\n const index = layer.levels.indexOf(draw.level);\n return index < 0 ? layer.levels.length : index;\n };\n const out: Draw[][] = [];\n let previous = -1;\n for (const draw of draws) {\n if (rank(draw) !== previous) out.push([]);\n previous = rank(draw);\n out[out.length - 1]?.push(draw);\n }\n return out;\n}\n\n/**\n * This function gives the program of one step. The fixed draws keep their spans and their device-days. The open draws have a common floor.\n *\n * - With `\"span\"`, each open draw has a column of its days, not less than the floor. Its runs share the device-days that the fixed draws leave, for the floor.\n * The device-days of each day are the runs over the span. A span not less than the floor uses fewer of them, so this is the safe side.\n * - With `\"day\"`, each open draw has a span of one day and takes no stock. Its runs share the device-days of one day.\n * - With a horizon, the floor is the horizon at most.\n */\nfunction buildStep(\n parts: CaseParts,\n caseCuts: CaseCuts,\n draws: readonly Draw[],\n fixed: ReadonlyMap<string, Fixed>,\n open: readonly Draw[],\n devices: ReadonlyMap<string, number>,\n mode: \"span\" | \"day\",\n horizon?: Rational,\n): Step {\n const program = new Program();\n const floor = program.next();\n if (horizon !== undefined) program.push(new Map([[floor, ONE]]), \"<=\", horizon);\n const opened = new Set(open.map((draw) => draw.need));\n const blocks: DrawBlock[] = [];\n const floors = new Map<string, number>();\n const openRuns: (readonly [Converter, number])[] = [];\n const kept = new Map<string, Rational>();\n for (const draw of draws) {\n const fix = fixed.get(draw.need);\n if (fix === undefined && !opened.has(draw.need)) continue;\n const endless = fix?.endless ?? mode === \"day\";\n const block = drawBlock(program, parts, draw, !endless);\n blocks.push(block);\n const demand = exact(drawDemand(draw, caseCuts));\n const need: Row = new Map(block.gifts);\n if (fix !== undefined) {\n program.push(need, \">=\", mul(demand, fix.span));\n const { limits, stopped } = deviceUse(block.runs);\n for (const index of stopped) program.push(new Map([[index, ONE]]), \"<=\", ZERO);\n for (const [key, limit] of limits) program.push(limit.row, \"<=\", mul(fix.keep.get(key) ?? ZERO, fix.span));\n for (const [key, value] of fix.keep) kept.set(key, add(kept.get(key) ?? ZERO, value));\n continue;\n }\n openRuns.push(...block.runs);\n if (mode === \"day\") {\n program.push(need, \">=\", demand);\n continue;\n }\n const days = program.next();\n addTo(need, days, neg(demand));\n program.push(need, \">=\", ZERO);\n floors.set(draw.need, program.push(new Map([[days, ONE], [floor, neg(ONE)]]), \">=\", ZERO));\n }\n const shared = new Map<string, { row: Row; room: Rational; converters: readonly Converter[] }>();\n const { limits, stopped } = deviceUse(openRuns);\n for (const index of stopped) program.push(new Map([[index, ONE]]), \"<=\", ZERO);\n for (const [key, limit] of limits) {\n const left = sub(exact(devices.get(key) ?? limit.devices), kept.get(key) ?? ZERO);\n const room = sign(left) > 0 ? left : ZERO;\n shared.set(key, { row: limit.row, room, converters: limit.converters });\n if (mode === \"day\") {\n program.push(limit.row, \"<=\", room);\n continue;\n }\n const row: Row = new Map(limit.row);\n addTo(row, floor, neg(room));\n program.push(row, \"<=\", ZERO);\n }\n for (const resource of parts.stocked) {\n const row: Row = new Map();\n for (const block of blocks) {\n const index = block.shares.get(resource);\n if (index !== undefined) addTo(row, index, ONE);\n }\n if (row.size > 0) program.push(row, \"<=\", exact(parts.stock.get(resource) ?? 0));\n }\n return { program, blocks, floor, floors, openRuns, shared };\n}\n\n/**\n * This function fixes the open draws with no end. Each open draw takes no stock, and keeps the fewest device-days of each day.\n * A step with no largest floor has a direction with no take of a stock, so this program has a point.\n */\nfunction fixEndless(parts: CaseParts, caseCuts: CaseCuts, draws: readonly Draw[], fixed: Map<string, Fixed>, open: readonly Draw[], devices: ReadonlyMap<string, number>): void {\n const step = buildStep(parts, caseCuts, draws, fixed, open, devices, \"day\");\n const solved = solveLexicographic(step.program.constraints(), [{ sense: \"min\", coefficients: dense(fewestRow(step.openRuns), step.program.count) }]);\n if (solved.status !== \"optimal\") throw new Error(\"The draws with no end of the best endurance have no point of one day.\");\n for (const draw of open) {\n const block = step.blocks.find((item) => item.draw.need === draw.need) as DrawBlock;\n const keep = new Map<string, Rational>();\n for (const [key, limit] of deviceUse(block.runs).limits) keep.set(key, valueAt(limit.row, solved.x));\n fixed.set(draw.need, { span: ONE, endless: true, keep, capped: [], atHorizon: false });\n }\n}\n","import { DEFAULT_MAX_SETS, stopSets, type Stack } from \"@mark1russell7/system-stack\";\n\n// The minimal stop sets of a supply from the structure of the needs. The index does not give this entry: `stopCurves` uses it.\n\n/**\n * This function gives the minimal sets of cuts that stop a supply, from the paths of the needs of the stack (`stopSets` of the core).\n * A set is a list of indexes of `parts`, from the smallest set. Two sets of one size are in the order of `minimalStops`.\n *\n * - `parts` has the part of each cut that counts. Two cuts of one part are two cuts: each one stops what the part stops.\n * - A cut of the supply stops it alone. The other sets come from `stopSets` with the cut parts as `among`, so no other part can fail.\n * - The parts of `down` are down for the full event. The caller makes sure that they do not stop the supply with no cut.\n * - The result is `undefined` when the search passes its budget, or when the sets of cuts are more than `maxSets`.\n *\n * @param stack - The base stack\n * @param supply - The part of the supply of a draw\n * @param parts - The part of each cut that counts\n * @param down - The parts that are down for the full event\n * @param maxSets - The largest count of sets in one step of the search, and of the sets of cuts (`maxSets` of `stopSets`)\n */\nexport function stackStops(stack: Stack, supply: string, parts: readonly string[], down: readonly string[] = [], maxSets: number = DEFAULT_MAX_SETS): number[][] | undefined {\n const cutsOf = new Map<string, number[]>();\n for (const [index, part] of parts.entries()) cutsOf.set(part, [...(cutsOf.get(part) ?? []), index]);\n const own = (cutsOf.get(supply) ?? []).map((index) => [index]);\n const among = [...cutsOf.keys()].filter((part) => part !== supply);\n const found = stopSets(stack, supply, { down, among, size: among.length, maxSets });\n if (found.kind === \"budget\") return undefined;\n // The empty set: the supply is not in the stack, or it does not work in the base stack.\n // In both, `stopped` of the core does not count it as stopped, so only a cut of the supply stops it.\n if (found.sets.some((set) => set.length === 0)) return own;\n const out = [...own];\n for (const set of found.sets) {\n // Each choice of one cut for each part of the set is a minimal set of cuts.\n let choices: number[][] = [[]];\n for (const part of set) {\n const cuts = cutsOf.get(part) ?? [];\n if (choices.length * cuts.length + out.length > maxSets) return undefined;\n choices = choices.flatMap((choice) => cuts.map((cut) => [...choice, cut]));\n }\n out.push(...choices.map((choice) => choice.sort((x, y) => x - y)));\n }\n return out.sort(byMask);\n}\n\n/** The order of `minimalStops`: the smaller set first, then the set whose largest different index is smaller. */\nfunction byMask(a: readonly number[], b: readonly number[]): number {\n if (a.length !== b.length) return a.length - b.length;\n for (let index = a.length - 1; index >= 0; index -= 1) {\n const difference = (a[index] ?? 0) - (b[index] ?? 0);\n if (difference !== 0) return difference;\n }\n return 0;\n}\n","import { type OrderedRing, pathSetReliability, stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { DEFAULT_MAX_SETS, neededParts, survivalAt, weakestBound, type CutBound, type PathOptions } from \"@mark1russell7/system-stack\";\nimport { bestEndurance } from \"./best.ts\";\nimport { caseDraws, caseStopped, enduranceOf, type CaseOptions } from \"./endurance.ts\";\nimport type { CaseCuts, Draw, Endurance, EnduranceLayer, Prior, Survival } from \"./layer.ts\";\nimport { stackStops } from \"./stops.ts\";\n\n// The shortfall: the user-days in which a draw does not get its need, for one case and for one year.\n\n/** The read of a curve at a time is in the core since system-stack 0.1.13. This package gives it again, so its API does not change. */\nexport { survivalAt };\n\n/**\n * This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.\n * It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.\n * With no horizon, the area goes to the end of the curve.\n */\nexport function tailDays(curve: Survival, from: number, to: number = Infinity): number {\n let area = 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0] = curve[index - 1] ?? [0, 1];\n const [t1] = curve[index] ?? [0, 0];\n const start = Math.max(t0, from);\n const end = Math.min(t1, to);\n if (start < end) area += ((survivalAt(curve, start) + survivalAt(curve, end)) / 2) * (end - start);\n }\n return area;\n}\n\n/**\n * The options of a shortfall: the stack or the parts that are also down, as for `enduranceOf`, and a horizon.\n * With a horizon of `h` days, the shortfall counts only the first `h` days of each cut. A draw that holds `h` days has no shortfall.\n * Thus a plan can aim at a target, for example 14 days and then 90 days.\n */\n/**\n * The options of `stopCurves`. With a stack, `maxSets` is the budget of the search of the needs (`stopSets` of the core).\n * When the search passes it, `minimalStops` gives the sets.\n */\nexport interface StopCurveOptions extends Pick<CaseOptions, \"stack\" | \"down\">, Pick<PathOptions, \"maxSets\"> {\n /** The budget of `independentStop` for the curve of each draw, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`. */\n readonly maxWork?: number | undefined;\n}\n\nexport interface ShortfallOptions extends StopCurveOptions {\n /** The horizon in days, more than 0. The default is no horizon. */\n readonly horizon?: number | undefined;\n}\n\nfunction horizonOf(options: ShortfallOptions): number {\n const horizon = options.horizon ?? Infinity;\n if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);\n return horizon;\n}\n\nfunction budgetsOf(options: StopCurveOptions): { readonly maxSets: number; readonly maxWork: number } {\n const maxSets = options.maxSets ?? DEFAULT_MAX_SETS;\n if (!Number.isInteger(maxSets) || maxSets < 1) throw new RangeError(`The option maxSets is ${String(options.maxSets)}: it is not a whole number from 1.`);\n const maxWork = options.maxWork ?? INDEPENDENT_MAX_WORK;\n if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The option maxWork is ${String(options.maxWork)}: it is not a whole number from 1.`);\n return { maxSets, maxWork };\n}\n\n/**\n * This function gives the days at which the chance of the curve falls to `chance`. With `0.1`, it is the 90th percentile of the duration.\n * When the curve does not fall to `chance`, the result is `Infinity`.\n */\nexport function survivalQuantile(curve: Survival, chance: number): number {\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (p0 <= chance) return t0;\n if (p1 <= chance) return t0 + ((p0 - chance) * (t1 - t0)) / (p0 - p1);\n }\n return Infinity;\n}\n\n/** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */\nexport function yearChance(prior: Prior): number {\n return 1 - Math.exp(-prior.perYear * prior.reach);\n}\n\n/** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */\nexport function yearRate(prior: Prior): number {\n return prior.perYear * prior.reach;\n}\n\n/** This function gives the times at which a curve of the result can bend: each point of each curve, and each crossing of two curves. */\nfunction bendTimes(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const out = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n for (const [i, a] of curves.entries()) {\n for (const b of curves.slice(i + 1)) {\n const d0 = survivalAt(a, t0) - survivalAt(b, t0);\n const d1 = survivalAt(a, t1) - survivalAt(b, t1);\n if (d0 * d1 < 0) out.add(t0 + ((t1 - t0) * d0) / (d0 - d1));\n }\n }\n }\n return [...out].sort((x, y) => x - y);\n}\n\n/**\n * This function makes a survival curve from a chance at each time. It stops at the first chance of 0, and it removes an increase of rounding.\n *\n * @throws RangeError when the chance at the last time is more than 0, as for curves that do not end at a chance of 0\n */\nfunction curveFrom(times: readonly number[], chanceAt: (days: number) => number): Survival {\n const out: [number, number][] = [];\n for (const days of times) {\n const chance = Math.min(out[out.length - 1]?.[1] ?? 1, chanceAt(days));\n out.push([days, chance]);\n if (chance === 0) return out;\n }\n throw new RangeError(\"The curves do not fall to a chance of 0 at their last point.\");\n}\n\n/**\n * This function gives the curve of a stop of some cuts when one event makes each cut longer together.\n * At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.\n *\n * - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).\n * - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.\n * - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.\n * - When no set of cuts stops the supply, the result is `[[0, 0]]`. This curve does not start at `[0, 1]`, so `checkEndurance` refuses it.\n *\n * The result is not a limit. When the cuts are independent, a stop of two cuts in series can be longer. A stop through a need of `any` can be shorter.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param stops - This function tells if the cuts of a list of indexes stop the supply. A larger list stops it when a smaller list does.\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function eventStop(curves: readonly Survival[], stops: (cuts: readonly number[]) => boolean): Survival {\n return curveFrom(bendTimes(curves), (days) => {\n const chances = curves.map((curve) => survivalAt(curve, days));\n for (const level of [...new Set(chances)].sort((x, y) => y - x)) {\n if (stops(chances.flatMap((chance, index) => (chance >= level ? [index] : [])))) return level;\n }\n return 0;\n });\n}\n\n/**\n * This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.\n * It is `eventStop` when any one cut stops the supply.\n *\n * @param curves - The curves, each one good for `checkEndurance`\n * @throws RangeError when there is no curve, or when a curve does not end at a chance of 0\n */\nexport function longestStop(curves: readonly Survival[]): Survival {\n const first = curves[0];\n if (first === undefined) throw new RangeError(\"longestStop needs one or more curves.\");\n return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);\n}\n\n/**\n * The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop` adds the chance of each state.\n * With a stack, `stopCurves` finds the minimal sets from the needs, so a larger count of cuts can have exact sets.\n */\nexport const MINIMAL_STOP_CUTS = 12;\n\n/**\n * This function gives the minimal sets of cuts that stop the supply: each set stops it, and no smaller part of a set stops it.\n * With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.\n */\nexport function minimalStops(count: number, stops: (cuts: readonly number[]) => boolean): number[][] | undefined {\n if (count > MINIMAL_STOP_CUTS) return undefined;\n const found: number[][] = [];\n const masks: number[] = [];\n const all = Array.from({ length: 1 << count }, (_, mask) => mask).sort((x, y) => popCount(x) - popCount(y) || x - y);\n for (const mask of all) {\n if (mask === 0 || masks.some((other) => (other & mask) === other)) continue;\n const cuts = Array.from({ length: count }, (_, index) => index).filter((index) => (mask >> index) & 1);\n if (!stops(cuts)) continue;\n masks.push(mask);\n found.push(cuts);\n }\n return found;\n}\n\nfunction popCount(mask: number): number {\n let total = 0;\n for (let rest = mask; rest > 0; rest &= rest - 1) total += 1;\n return total;\n}\n\n/**\n * This function gives an upper limit of the curve of a stop for each dependence of the cuts.\n * At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.\n * With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.\n *\n * @param curves - The curves of the cuts\n * @param sets - The minimal sets of `minimalStops`, or `undefined`\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function upperStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival {\n const groups = sets ?? curves.map((_, index) => [index]);\n const sum = (days: number): number => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);\n // The sum is linear between two times of bendTimes. A point where it falls through 1 is a bend of min(1, sum).\n const times = bendTimes(curves);\n const bends = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n const s0 = sum(t0) - 1;\n const s1 = sum(t1) - 1;\n if (s0 * s1 < 0) bends.add(t0 + ((t1 - t0) * s0) / (s0 - s1));\n }\n return curveFrom([...bends].sort((x, y) => x - y), (days) => Math.min(1, sum(days)));\n}\n\n/** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */\nexport const INDEPENDENT_TOLERANCE = 1e-6;\n\n/**\n * The default budget of `independentStop` for its groups of more than `MINIMAL_STOP_CUTS` cuts.\n * The budget counts the steps of the expansion times the count of points of the curve.\n * It is near the work of the sum over the states of 12 cuts.\n */\nexport const INDEPENDENT_MAX_WORK: number = 2 ** 26;\n\n/**\n * This function gives the curve of a stop of some cuts when the cuts are independent.\n * At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.\n * Its chance is a sum over each set of cuts that stops the supply.\n * Each term is the product of `s(t)` for the cuts that are on, and of `1 - s(t)` for the other cuts.\n *\n * - When any one cut stops the supply, the result is `1 - prod(1 - s)`. It is not less than the longest cut (`eventStop`).\n * - When the supply needs `any` of two parts, the stop of the two is `s1 * s2`. It is not more than the shorter cut.\n * - The result is not more than `upperStop` of the same sets, because `upperStop` is a limit for each dependence.\n * - Between two points of the curves the chance is a polynomial, not a line. The function splits each such segment into equal pieces.\n * The chance is linear in each `s`, and each mixed second derivative is between -1 and 1.\n * Thus `|f''| <= (sum |s'|)^2 - sum s'^2`, and the line of a piece of length `h` is within `h^2 |f''| / 8` of the chance.\n * The count of pieces keeps each line within `INDEPENDENT_TOLERANCE`. With a margin of 10 %, the count of points is less than `n / sqrt(7.2 * INDEPENDENT_TOLERANCE)` plus the segments, for `n` cuts.\n *\n * - Up to `MINIMAL_STOP_CUTS` cuts in the sets, the function adds the chance of each of the 2 to the power of that count of states.\n * - Two groups of cuts that share no set are independent, so the chance that the supply works is the product over the groups.\n * For example, 20 stages of 2 feeds give 20 groups of 2 cuts.\n * - In a group of more than `MINIMAL_STOP_CUTS` cuts, it uses the Shannon expansion of `pathSetReliability` of collections.\n * The expansion merges two states with the same sets left, and it drops a set that holds another set.\n * - The expansion is exponential in the worst case. The groups share one budget, `maxWork`.\n * When the steps of the expansions times the count of points of the curve pass it, the result is `undefined`.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param sets - The minimal sets of the cuts. With `undefined`, as for no minimal sets, the result is `undefined`. With no sets, it is `[[0, 0]]`\n * @param maxWork - The budget of the expansions of the groups of more than `MINIMAL_STOP_CUTS` cuts, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`\n * @throws RangeError when a curve does not end at a chance of 0, or for a bad `maxWork`\n */\nexport function independentStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined, maxWork: number = INDEPENDENT_MAX_WORK): Survival | undefined {\n if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The budget maxWork is ${String(maxWork)}: it is not a whole number from 1.`);\n if (sets === undefined) return undefined;\n // With no set, no cuts stop the supply, as for `eventStop` and `upperStop`.\n if (sets.length === 0) return [[0, 0]];\n // Only the cuts of a set change the chance. Their place in `used` is their index in the sets of the cuts that count.\n const used = [...new Set(sets.flat())].sort((x, y) => x - y);\n const usedCurves = used.map((index) => curves[index] ?? []);\n const usedSets = sets.map((set) => set.map((index) => used.indexOf(index)));\n const points = independentPoints(usedCurves);\n // Two groups of cuts that share no set are independent: the supply works when it works in each group.\n const groupChances: ((days: number) => number)[] = [];\n // The expansions of all groups share one budget.\n let work = maxWork;\n for (const group of cutGroups(used.length, usedSets)) {\n const curvesOf = group.map((index) => usedCurves[index] ?? []);\n const setsOf = usedSets.filter((set) => group.includes(set[0] ?? -1)).map((set) => set.map((index) => group.indexOf(index)));\n // Up to MINIMAL_STOP_CUTS cuts, the sum over the states is exact with a fixed cost. Past them, the expansion is exact within its budget.\n if (group.length <= MINIMAL_STOP_CUTS) {\n groupChances.push(stateChance(curvesOf, setsOf));\n continue;\n }\n const expanded = expandedChances(curvesOf, setsOf, points, work);\n if (expanded === undefined) return undefined;\n work -= expanded.steps * points.length;\n const chanceOf = new Map(points.map((days, index) => [days, expanded.chances[index] ?? 0]));\n groupChances.push((days) => {\n const chance = chanceOf.get(days);\n if (chance === undefined) throw new Error(`The expansion has no chance at ${String(days)} days.`);\n return chance;\n });\n }\n // With one group, the chance of the group is the result, with no rounding of 1 - (1 - chance).\n const [only] = groupChances;\n if (groupChances.length === 1 && only !== undefined) return curveFrom(points, only);\n return curveFrom(points, (days) => Math.min(1, Math.max(0, 1 - groupChances.reduce((works, chanceAt) => works * (1 - chanceAt(days)), 1))));\n}\n\n/** The groups of the cuts `0` to `count - 1`: two cuts are in one group when a chain of sets joins them. Each set has its cuts in one group. */\nfunction cutGroups(count: number, sets: readonly (readonly number[])[]): number[][] {\n const next = Array.from({ length: count }, () => new Set<number>());\n // A cycle through the cuts of each set joins them both ways, so the strongly connected components are the groups.\n for (const set of sets) for (const [at, index] of set.entries()) next[index]?.add(set[(at + 1) % set.length] ?? index);\n return stronglyConnectedComponents(\n Array.from({ length: count }, (_, index) => index),\n (index) => next[index] ?? [],\n );\n}\n\n/** The times of `independentStop`: the points of the curves, and the pieces that keep each line within `INDEPENDENT_TOLERANCE`. */\nfunction independentPoints(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const points: number[] = [];\n for (const [index, t1] of times.entries()) {\n const t0 = times[index - 1];\n if (t0 !== undefined) {\n const h = t1 - t0;\n const slopes = curves.map((curve) => Math.abs(survivalAt(curve, t1) - survivalAt(curve, t0)) / h);\n const sum = slopes.reduce((total, slope) => total + slope, 0);\n const bound = Math.max(0, sum * sum - slopes.reduce((total, slope) => total + slope * slope, 0));\n // A margin of 10 % keeps the rounding of the chance under the tolerance.\n const pieces = Math.ceil(h * Math.sqrt(bound / (8 * 0.9 * INDEPENDENT_TOLERANCE)));\n for (let piece = 1; piece < pieces; piece += 1) {\n const days = t0 + (h * piece) / pieces;\n // Two times that are next to each other as floats have no time between them.\n if (days > (points[points.length - 1] ?? t0) && days < t1) points.push(days);\n }\n }\n points.push(t1);\n }\n return points;\n}\n\n/** The chance of a stop at a time, as the sum over each state of `MINIMAL_STOP_CUTS` cuts or fewer. Bit k of a state is 1 when cut k is on. */\nfunction stateChance(curves: readonly Survival[], sets: readonly (readonly number[])[]): (days: number) => number {\n const setMasks = sets.map((set) => set.reduce((mask, index) => mask | (1 << index), 0));\n const stopping = Array.from({ length: 1 << curves.length }, (_, mask) => setMasks.some((set) => (set & mask) === set));\n const states = new Float64Array(1 << curves.length);\n return (days) => {\n // The chance of each state of the cuts, one cut at a time.\n states[0] = 1;\n let length = 1;\n for (const curve of curves) {\n const on = survivalAt(curve, days);\n for (let mask = 0; mask < length; mask += 1) {\n const chance = states[mask] ?? 0;\n states[mask + length] = chance * on;\n states[mask] = chance * (1 - on);\n }\n length *= 2;\n }\n let total = 0;\n for (let mask = 0; mask < length; mask += 1) if (stopping[mask]) total += states[mask] ?? 0;\n return Math.min(1, Math.max(0, total));\n };\n}\n\n/** The count of times in one expansion of `expandedChances`: the length of the vectors of its ring. */\nconst EXPANSION_WIDTH = 64;\n\n/**\n * The ring of the vectors of `width` chances, one for each time, for `pathSetReliability` of collections.\n * Each operation is on each time alone. In the order, `a` is less than `b` when it is less or equal at each time, and not equal.\n */\nfunction vectorRing(width: number): OrderedRing<Float64Array> {\n const zip = (a: Float64Array, b: Float64Array, op: (x: number, y: number) => number): Float64Array => {\n const out = new Float64Array(width);\n for (let index = 0; index < width; index += 1) out[index] = op(a[index] ?? 0, b[index] ?? 0);\n return out;\n };\n return {\n zero: new Float64Array(width),\n one: new Float64Array(width).fill(1),\n add: (a, b) => zip(a, b, (x, y) => x + y),\n sub: (a, b) => zip(a, b, (x, y) => x - y),\n mul: (a, b) => zip(a, b, (x, y) => x * y),\n compare: (a, b) => {\n let less = false;\n let more = false;\n for (let index = 0; index < width; index += 1) {\n const [x, y] = [a[index] ?? 0, b[index] ?? 0];\n if (x < y) less = true;\n else if (x > y) more = true;\n else if (x !== y) return Number.NaN;\n }\n return less ? (more ? Number.NaN : -1) : more ? 1 : 0;\n },\n };\n}\n\n/**\n * The chance of a stop at each point, from the Shannon expansion of `pathSetReliability`. A set works when each of its cuts is on.\n * One call gives `EXPANSION_WIDTH` points. When the steps of one expansion times the count of points pass `maxWork`, the result is `undefined`.\n * Else `steps` is the count of steps of one expansion.\n */\nfunction expandedChances(\n curves: readonly Survival[],\n sets: readonly (readonly number[])[],\n points: readonly number[],\n maxWork: number,\n): { readonly chances: number[]; readonly steps: number } | undefined {\n const maxSteps = Math.floor(maxWork / points.length);\n if (maxSteps < 1) return undefined;\n const out: number[] = [];\n let steps = 0;\n for (let start = 0; start < points.length; start += EXPANSION_WIDTH) {\n const times = points.slice(start, start + EXPANSION_WIDTH);\n const chances = curves.map((curve) => Float64Array.from(times, (days) => survivalAt(curve, days)));\n const result = pathSetReliability(sets, chances, vectorRing(times.length), { maxSteps });\n // Each call has the same sets, so the first call tells if the expansion is in the budget.\n if (result.kind === \"budget\") return undefined;\n steps = result.steps;\n for (const chance of result.value) out.push(Math.min(1, Math.max(0, chance)));\n }\n return { chances: out, steps };\n}\n\n/**\n * The curves of the stop of a draw. `event` is for one event that makes each cut longer together, and `independent` is for independent cuts.\n * `upper` is an upper limit for each dependence.\n */\nexport interface StopCurves {\n readonly event: Survival;\n /** The stop when the cuts are independent (`independentStop`). When `independentUpper` is true, it is `upper`. */\n readonly independent: Survival;\n readonly upper: Survival;\n /**\n * This is true when `upper` is the sum of the curves of the cuts that count, because the query has no minimal sets.\n * With a stack, the search of the needs passed its budget. With no stack, more than `MINIMAL_STOP_CUTS` cuts count.\n */\n readonly coarse: boolean;\n /** This is true when `independent` is `upper`: `coarse` is true, or the expansion of `independentStop` passed its budget. */\n readonly independentUpper: boolean;\n /**\n * The weakest bound (`weakestBound` of the core) of the curves of the cuts that the stop uses. Since 0.8.4.\n * With minimal sets, the stop uses the cuts of the sets. With no minimal sets, it uses each cut with a curve.\n * Each of the three curves does not decrease when a cut lasts longer, so it has this bound.\n */\n readonly bound: CutBound;\n}\n\n/** This function gives the parts of the stack that are down for a list of cut indexes. A case uses one memo for each of its draws. */\ntype StoppedOf = (cuts: readonly number[]) => ReadonlySet<string>;\n\nfunction stoppedMemo(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): StoppedOf {\n const memo = new Map<string, ReadonlySet<string>>();\n return (cuts) => {\n const key = cuts.join(\",\");\n let found = memo.get(key);\n if (found === undefined) {\n found = caseStopped({ ...caseCuts, cuts: cuts.flatMap((index) => caseCuts.cuts[index] ?? []) }, options);\n memo.set(key, found);\n }\n return found;\n };\n}\n\n/** This function gives the parts whose cut can stop a supply: the supply, and each part that it needs through the stack. */\nfunction supplyReach(supply: string, options: Pick<CaseOptions, \"stack\">): Set<string> {\n const reach = options.stack === undefined ? new Set<string>() : neededParts(options.stack, supply);\n reach.add(supply);\n return reach;\n}\n\nfunction stopCurvesWith(caseCuts: CaseCuts, draw: Draw, options: StopCurveOptions, stoppedOf: StoppedOf): StopCurves | undefined {\n const reach = supplyReach(draw.supply, options);\n const relevant = caseCuts.cuts.flatMap((cut, index) => (reach.has(cut.part) ? [index] : []));\n const stops = (cuts: readonly number[]): boolean => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);\n if (stops([])) return undefined;\n if (!stops(relevant.map((_, index) => index))) return undefined;\n const given = relevant.map((index) => caseCuts.cuts[index]?.duration);\n // With a stack, the needs give the minimal sets. When their search passes its budget, the sets of each list of cuts are the check.\n const parts = relevant.map((index) => caseCuts.cuts[index]?.part ?? \"\");\n const structural = options.stack === undefined ? undefined : stackStops(options.stack, draw.supply, parts, options.down, budgetsOf(options).maxSets);\n const sets = structural ?? minimalStops(given.length, stops);\n // The stop has no curve when a cut with no curve can be part of it. With no minimal sets, the query cannot tell.\n const unsourced = given.flatMap((curve, index) => (curve === undefined ? [index] : []));\n if (unsourced.length > 0 && (sets === undefined || sets.some((set) => set.some((index) => unsourced.includes(index))))) return undefined;\n // A cut with no curve is in no minimal set here, so it does not change a stop. The curves do not include it.\n const kept = given.flatMap((curve, index) => (curve === undefined ? [] : [index]));\n const curves = kept.map((index) => given[index] ?? []);\n const keptStops = (cuts: readonly number[]): boolean => stops(cuts.map((index) => kept[index] ?? -1));\n const keptSets = sets?.map((set) => set.map((index) => kept.indexOf(index)));\n const upper = upperStop(curves, keptSets);\n const independent = independentStop(curves, keptSets, budgetsOf(options).maxWork);\n // A cut in no minimal set does not change a stop, so its bound does not weaken the bound of the stop.\n const used = sets === undefined ? kept : kept.filter((index) => sets.some((set) => set.includes(index)));\n const bound = weakestBound(used.map((index) => caseCuts.cuts[relevant[index] ?? -1]?.bound ?? \"law\"));\n return { event: eventStop(curves, keptStops), independent: independent ?? upper, upper, coarse: keptSets === undefined, independentUpper: independent === undefined, bound };\n}\n\n/**\n * This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.\n *\n * - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.\n * - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.\n * - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.\n * - With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core), so the count of cuts has no limit of `MINIMAL_STOP_CUTS`.\n * When that search passes its budget (the option `maxSets`), `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.\n * - A cut with no `duration` gives no curve when it is in a minimal set, or when the query has no minimal sets.\n * - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.\n * - With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` is true.\n * - When the expansion of `independentStop` passes its budget, `independent` is `upper`, and `independentUpper` is true.\n * - `bound` is the weakest bound of the curves of the cuts that the stop uses. A cut with no `bound` has a law.\n */\nexport function stopCurves(caseCuts: CaseCuts, draw: Draw, options: StopCurveOptions = {}): StopCurves | undefined {\n budgetsOf(options);\n return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));\n}\n\n/** The shortfall of each level, in user-days, and the draws that the query cannot read. */\nexport interface Shortfall {\n /**\n * The user-days of each level of the layer, when one event makes each cut longer together. The query does not add two levels.\n * This value is not a limit. The true value can be more or less. `upper` is the limit.\n */\n readonly levels: Readonly<Record<string, number>>;\n /** The user-days of each level when the cuts are independent (`StopCurves.independent`). This value is not more than `upper`. */\n readonly independent: Readonly<Record<string, number>>;\n /** The upper limit of the user-days of each level, for each dependence of the cuts. A gate of a high level can use it. */\n readonly upper: Readonly<Record<string, number>>;\n /**\n * The needs of the draws whose stop has no curve (`stopCurves`).\n * The query has no curve of their duration, so their shortfall is not in `levels`. A gate shows them as no read.\n */\n readonly unread: readonly string[];\n /** The needs of the draws whose `upper` is coarse (`StopCurves.coarse`). A gate on `upper` shows them. */\n readonly coarse: readonly string[];\n /** The needs of the draws whose `independent` is `upper` (`StopCurves.independentUpper`). A gate on `independent` shows them. */\n readonly independentUpper: readonly string[];\n /**\n * The bound of the shortfall: the weakest bound (`weakestBound` of the core) of the curves that the query uses. Since 0.8.4.\n * The shortfall does not decrease when a cut lasts longer. So with `upper`, each value is too high or equal, and with `lower` too low or equal.\n * With `none`, a value can be too high or too low.\n *\n * A draw in `unread` and a case that adds 0 do not change the bound. With no curve, the bound is `law`.\n * The bound is for each of `levels`, `independent` and `upper`, each with its own rule of the dependence of the cuts.\n */\n readonly bound: CutBound;\n}\n\nfunction zeroLevels(layer: EnduranceLayer): Record<string, number> {\n return Object.fromEntries(layer.levels.map((level) => [level, 0]));\n}\n\n/**\n * This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.\n * `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param endurance - The endurance of the case, from `enduranceOf`\n * @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon\n * @throws RangeError when the horizon is not a number more than 0, or `maxSets` is not a whole number from 1\n */\nexport function caseShortfall(layer: EnduranceLayer, caseCuts: CaseCuts, endurance: Endurance, options: ShortfallOptions = {}): Shortfall {\n const horizon = horizonOf(options);\n budgetsOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const bounds: CutBound[] = [];\n const stoppedOf = stoppedMemo(caseCuts, options);\n for (const draw of caseDraws(layer, caseCuts, caseStopped(caseCuts, options))) {\n const held = endurance.needs[draw.need];\n const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);\n if (held === undefined || curves === undefined) {\n unread.push(draw.need);\n continue;\n }\n if (curves.coarse) coarse.push(draw.need);\n if (curves.independentUpper) independentUpper.push(draw.need);\n bounds.push(curves.bound);\n const users = draw.users ?? 1;\n levels[draw.level] = (levels[draw.level] ?? 0) + tailDays(curves.event, held.days, horizon) * users;\n independent[draw.level] = (independent[draw.level] ?? 0) + tailDays(curves.independent, held.days, horizon) * users;\n upper[draw.level] = (upper[draw.level] ?? 0) + tailDays(curves.upper, held.days, horizon) * users;\n }\n return { levels, independent, upper, unread, coarse, independentUpper, bound: weakestBound(bounds) };\n}\n\n/**\n * The share of the stores in a case. `take` is the take order of `enduranceOf`. `best` is the leximin share of\n * `bestEndurance`, level by level.\n */\nexport type Share = \"take\" | \"best\";\n\n/** The shares, with the default first. */\nexport const SHARES: readonly Share[] = [\"take\", \"best\"];\n\n/** This function gives the share of the options. The default is `take`. */\nfunction shareOf(options: { readonly share?: Share | undefined }): Share {\n const share = options.share ?? \"take\";\n if (!SHARES.includes(share)) throw new RangeError(`The share ${String(options.share)} is not ${SHARES.join(\" or \")}.`);\n return share;\n}\n\n/** This function gives the endurance of a case with a share: `enduranceOf` for `take`, `bestEndurance` with the horizon for `best`. */\nfunction shareEndurance(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions & ShortfallOptions, share: Share): Endurance {\n return share === \"best\" ? bestEndurance(layer, caseCuts, options) : enduranceOf(layer, caseCuts, options);\n}\n\n/** The options of `yearShortfall`: the date, the stack or the parts that are also down, the horizon and the share. */\nexport interface YearShortfallOptions extends CaseOptions, ShortfallOptions {\n /**\n * The share of the stores in each case. The default `take` gives the endurance from `enduranceOf`. With `best`,\n * the endurance comes from `bestEndurance`, and the horizon of the shortfall is the horizon of the share. Thus a\n * draw at the horizon keeps back only the horizon times its demand, and the lower levels get the rest.\n */\n readonly share?: Share | undefined;\n}\n\n/** The user-days of each level for each curve of the stop: the three sums of a shortfall. Since 0.8.15. */\nexport type ShortfallDays = Pick<Shortfall, \"levels\" | \"independent\" | \"upper\">;\n\n/**\n * The range of the shortfall of one year from the intervals of the rates of its cases (`Prior.interval`). Since 0.8.15.\n * `low` puts the rate of each case at the low end of its interval, and `high` puts it at the high end.\n * Each end holds only for each case alone, so the two values are a range of the sampling error, not a joint interval.\n * The mean of a skewed law can be above the high end, so the expected value can be above `high`.\n */\nexport interface RateRange {\n /** The least level of the intervals of the cases in the sum. */\n readonly level: number;\n readonly low: ShortfallDays;\n readonly high: ShortfallDays;\n /** The cases in the sum with no interval of their rate. Their rate is at the two ends. */\n readonly without: readonly string[];\n}\n\n/** The part of one case in the shortfall of one year. */\nexport interface YearCase {\n readonly case: string;\n /** The expected count of the events of the case at the place in one year (`yearRate`). */\n readonly rate: number;\n /** The interval of `rate` from the interval of the prior, times its reach. A prior with no interval gives none. Since 0.8.15. */\n readonly rateInterval?: readonly [low: number, high: number] | undefined;\n readonly endurance: Endurance;\n readonly shortfall: Shortfall;\n}\n\n/** The shortfall of one year at one place, with the part of each case. */\nexport interface YearShortfall extends Shortfall {\n readonly place: string;\n /** The part of each case. `rate` is the expected count of its events in one year. */\n readonly cases: readonly YearCase[];\n /** The range from the intervals of the rates. A year with no case with an interval has no range. Since 0.8.15. */\n readonly range?: RateRange | undefined;\n}\n\n/**\n * This function gives the shortfall of one year at one place.\n * It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.\n *\n * - The expected count of a case is `perYear * reach`, from the first prior of the case at the place. Thus the result is the expected user-days of one year.\n * - A case with no prior at the place is not in the sum.\n * - `unread` is the union of the needs that a case cannot read, in the order of the cases. `coarse` and `independentUpper` are unions too.\n * - `bound` is the weakest bound of the cases in the sum. A case with no prior, or with an expected count of 0, adds 0, so it does not change the bound.\n *\n * - With `share: \"best\"`, the endurance of each case comes from `bestEndurance` with the horizon of the shortfall.\n * - `range` is the same sum with the rate of each case at each end of its interval (`RateRange`).\n *\n * @param layer - The endurance layer, with its cases and priors\n * @param place - The place of the priors\n * @param options - The date, the stack or the parts that are also down, the horizon and the share\n * @throws RangeError for a bad date, horizon, `maxSets` or share: refer to `caseShortfall` and `enduranceOf`\n */\nexport function yearShortfall(layer: EnduranceLayer, place: string, options: YearShortfallOptions): YearShortfall {\n horizonOf(options);\n budgetsOf(options);\n const share = shareOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const cases: YearCase[] = [];\n const bounds: CutBound[] = [];\n const low = { levels: zeroLevels(layer), independent: zeroLevels(layer), upper: zeroLevels(layer) };\n const high = { levels: zeroLevels(layer), independent: zeroLevels(layer), upper: zeroLevels(layer) };\n const without: string[] = [];\n let level = Infinity;\n for (const caseCuts of layer.cases ?? []) {\n const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);\n if (prior === undefined) continue;\n const rate = yearRate(prior);\n const endurance = shareEndurance(layer, caseCuts, options, share);\n const shortfall = caseShortfall(layer, caseCuts, endurance, options);\n addDays({ levels, independent, upper }, shortfall, rate);\n const rateInterval = prior.interval === undefined ? undefined : ([prior.interval.low * prior.reach, prior.interval.high * prior.reach] as const);\n if (rateInterval === undefined) without.push(caseCuts.case);\n else level = Math.min(level, prior.interval?.level ?? level);\n addDays(low, shortfall, rateInterval?.[0] ?? rate);\n addDays(high, shortfall, rateInterval?.[1] ?? rate);\n for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);\n for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);\n for (const need of shortfall.independentUpper) if (!independentUpper.includes(need)) independentUpper.push(need);\n if (rate > 0) bounds.push(shortfall.bound);\n cases.push({ case: caseCuts.case, rate, ...(rateInterval === undefined ? {} : { rateInterval }), endurance, shortfall });\n }\n const range = Number.isFinite(level) ? { range: { level, low, high, without } } : {};\n return { place, levels, independent, upper, unread, coarse, independentUpper, bound: weakestBound(bounds), cases, ...range };\n}\n\n/** This function adds the user-days of a shortfall times a count of events to each sum of the days. */\nfunction addDays(days: { levels: Record<string, number>; independent: Record<string, number>; upper: Record<string, number> }, shortfall: ShortfallDays, count: number): void {\n for (const [level, value] of Object.entries(shortfall.levels)) days.levels[level] = (days.levels[level] ?? 0) + count * value;\n for (const [level, value] of Object.entries(shortfall.independent)) days.independent[level] = (days.independent[level] ?? 0) + count * value;\n for (const [level, value] of Object.entries(shortfall.upper)) days.upper[level] = (days.upper[level] ?? 0) + count * value;\n}\n\n/** The options of `caseOutlook`: the date, the stack or the parts that are also down, the horizon and the share. */\nexport type OutlookOptions = YearShortfallOptions;\n\n/** A value for each curve of the stop of a draw (`StopCurves`). */\nexport interface CurveValues {\n /** The value when one event makes each cut longer together. */\n readonly event: number;\n /** The value when the cuts are independent. */\n readonly independent: number;\n /** The value of the upper curve: the safe side for each dependence of the cuts. */\n readonly upper: number;\n}\n\n/** The chance and the shortfall of a draw at one end of the sampling bands of its cuts. Since 0.8.14. */\nexport interface BandValues {\n readonly lasts: CurveValues;\n readonly shortfall: CurveValues;\n}\n\n/**\n * The values of a draw at the two ends of the sampling bands of its cuts (`Cut.band`). Since 0.8.14.\n * `shorter` puts each cut at the low end of its band, and `longer` puts each cut at the high end.\n * Each end holds only pointwise, so the two values are a range of the sampling error, not a joint interval.\n */\nexport interface DrawBand {\n readonly shorter: BandValues;\n readonly longer: BandValues;\n}\n\n/** The outlook of one draw in one event of a case. */\nexport interface DrawOutlook {\n readonly need: string;\n readonly level: string;\n readonly supply: string;\n readonly users: number;\n /** The days that the stores give the draw (`DrawEndurance.days`). */\n readonly days: number;\n /** This is true when the draw holds to the horizon of a best share. */\n readonly atHorizon?: true;\n /**\n * The chance that the draw gets its need through the event: `P(min(D, h) <= T)`, for each curve of the stop.\n * `D` is the duration of the stop, `T` is `days` and `h` is the horizon. A draw that holds to the horizon has the chance 1.\n * The chance of `upper` is not more than the true chance, for each dependence of the cuts.\n */\n readonly lasts: CurveValues;\n /** The user-days of the shortfall in one event, `E[max(0, min(D, h) - T)] * users`, for each curve. */\n readonly shortfall: CurveValues;\n /** The bound of the curves of the stop (`StopCurves.bound`). */\n readonly bound: CutBound;\n /** This is true when the upper curve is coarse (`StopCurves.coarse`). */\n readonly coarse: boolean;\n /**\n * The values at the two ends of the sampling bands of the cuts, with the same days. Since 0.8.14.\n * It is missing when a cut that can be part of the stop has a curve and no band. Then the sampling error has no read.\n */\n readonly band?: DrawBand | undefined;\n}\n\n/** The outlook of one event of a case: the days, the chance and the shortfall of each draw. */\nexport interface CaseOutlook {\n readonly case: string;\n readonly title: string;\n readonly at: string;\n readonly share: Share;\n /** The horizon in days, or `undefined` for no horizon. */\n readonly horizon: number | undefined;\n /** Each draw whose supply the case stops and whose stop has a curve, in the order of the layer. */\n readonly draws: readonly DrawOutlook[];\n /** The needs of the draws whose supply the case does not stop. They get their need through the event. */\n readonly holds: readonly string[];\n /** The needs of the draws whose stop has no curve (`stopCurves`). They are no read, not a pass. */\n readonly unread: readonly string[];\n /** The weakest bound of the curves of `draws`. */\n readonly bound: CutBound;\n}\n\n/**\n * This function gives the outlook of one event of a case. For each draw, it gives the days, the chance that the\n * stores last through the stop, and the shortfall. A page of a place can show it for each case of its region.\n *\n * - The days come from the share of the stores: `enduranceOf` for `take`, `bestEndurance` with the horizon for `best`.\n * - The chance and the shortfall use the curves of `stopCurves`. They count the stop only up to the horizon.\n * - `upper` is the safe side: its chance is not more, and its shortfall is not less, than the true value for each dependence.\n * - `band` gives the same values with each cut at each end of its sampling band (`Cut.band`). The days do not change.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, the stack or the parts that are also down, the horizon and the share\n * @throws RangeError for a bad date, horizon, `maxSets` or share: refer to `caseShortfall` and `enduranceOf`\n */\nexport function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, options: OutlookOptions): CaseOutlook {\n const horizon = horizonOf(options);\n budgetsOf(options);\n const share = shareOf(options);\n const endurance = shareEndurance(layer, caseCuts, options, share);\n const stopped = caseDraws(layer, caseCuts, caseStopped(caseCuts, options));\n const stoppedNeeds = new Set(stopped.map((draw) => draw.need));\n const stoppedOf = stoppedMemo(caseCuts, options);\n // Each end of the bands: a cut with a band takes that end as its curve, and a cut with no band has no curve.\n const banded = caseCuts.cuts.some((cut) => cut.band !== undefined);\n const endCuts = (end: \"low\" | \"high\"): CaseCuts => ({ ...caseCuts, cuts: caseCuts.cuts.map(({ duration: _, band, ...cut }) => (band === undefined ? cut : { ...cut, duration: band[end], band })) });\n const ends = banded ? { shorter: endCuts(\"low\"), longer: endCuts(\"high\") } : undefined;\n const draws: DrawOutlook[] = [];\n const unread: string[] = [];\n const bounds: CutBound[] = [];\n for (const draw of stopped) {\n const held = endurance.needs[draw.need];\n const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);\n if (held === undefined || curves === undefined) {\n unread.push(draw.need);\n continue;\n }\n const users = draw.users ?? 1;\n const lasts = (curve: Survival): number => (held.days >= horizon ? 1 : 1 - survivalAt(curve, held.days));\n const short = (curve: Survival): number => tailDays(curve, held.days, horizon) * users;\n const values = (stop: StopCurves): BandValues => ({\n lasts: { event: lasts(stop.event), independent: lasts(stop.independent), upper: lasts(stop.upper) },\n shortfall: { event: short(stop.event), independent: short(stop.independent), upper: short(stop.upper) },\n });\n const shorter = ends === undefined ? undefined : stopCurvesWith(ends.shorter, draw, options, stoppedOf);\n const longer = ends === undefined ? undefined : stopCurvesWith(ends.longer, draw, options, stoppedOf);\n const band = shorter === undefined || longer === undefined ? {} : { band: { shorter: values(shorter), longer: values(longer) } };\n bounds.push(curves.bound);\n draws.push({\n need: draw.need,\n level: draw.level,\n supply: draw.supply,\n users,\n days: held.days,\n ...(held.atHorizon === true ? { atHorizon: true as const } : {}),\n ...values(curves),\n bound: curves.bound,\n coarse: curves.coarse,\n ...band,\n });\n }\n const holds = layer.draws.filter((draw) => !stoppedNeeds.has(draw.need)).map((draw) => draw.need);\n return {\n case: caseCuts.case,\n title: caseCuts.title,\n at: endurance.at,\n share,\n horizon: Number.isFinite(horizon) ? horizon : undefined,\n draws,\n holds,\n unread,\n bound: weakestBound(bounds),\n };\n}\n","import { STACK_SCHEMA, type Stack } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// A sample: a building with 3 users, and a storm that cuts the grid, the road and the water main.\n// Each name and each value is an example, except the grid curve (NREL, technical report 83092). The tests, the README files and the site use it.\n\n/** The base stack of the sample: the supplies of the building and a camp stove. */\nexport const SAMPLE_ENDURANCE_STACK: Stack = {\n schema: STACK_SCHEMA,\n parts: [\n { id: \"grid\", kind: \"power\", name: \"The power grid\" },\n { id: \"water-main\", kind: \"water\", name: \"The water main\" },\n { id: \"road\", kind: \"road\", name: \"The local road to the shops\" },\n { id: \"stove\", kind: \"device\", name: \"The camp stove\" },\n ],\n};\n\n/**\n * The endurance layer of the sample.\n *\n * - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.\n * - The food holds 4800 / 5400 = 0.889 days. The rice needs 2 L of water for each kg, and the drinking water keeps back all the water.\n * - The power holds 1000 Wh / 150 Wh a day = 6.667 days.\n * - The filled bottles are past their due date, so they give nothing.\n */\nexport const SAMPLE_ENDURANCE: EnduranceLayer = {\n schema: ENDURANCE_SCHEMA,\n levels: [\"life\", \"health\", \"comfort\"],\n resources: [\n { code: \"water.stored\", unit: \"L\" },\n { code: \"food.ready\", unit: \"kcal\" },\n { code: \"food.grain-dry\", unit: \"kg\" },\n { code: \"fuel.propane\", unit: \"kg\" },\n { code: \"energy.battery\", unit: \"Wh\" },\n ],\n stores: [\n { id: \"jugs\", resource: \"water.stored\", amount: 75.7, due: \"2028-06-01\" },\n { id: \"bottles\", resource: \"water.stored\", amount: 20, due: \"2026-09-30\" },\n { id: \"cans\", resource: \"food.ready\", amount: 4800, due: \"2028-10-01\" },\n { id: \"rice\", resource: \"food.grain-dry\", amount: 9, due: \"2036-09-28\" },\n { id: \"propane\", resource: \"fuel.propane\", amount: 0.908, due: \"2036-10-01\" },\n { id: \"battery\", resource: \"energy.battery\", amount: 1000, due: \"2031-10-01\" },\n ],\n draws: [\n { need: \"hydration.drink\", level: \"life\", perDay: 11.355, users: 3, supply: \"water-main\" },\n { need: \"food.energy\", level: \"health\", perDay: 5400, users: 3, supply: \"road\" },\n { need: \"power.electric\", level: \"comfort\", perDay: 150, users: 3, supply: \"grid\" },\n ],\n direct: [\n { resource: \"water.stored\", need: \"hydration.drink\", amount: 1 },\n { resource: \"food.ready\", need: \"food.energy\", amount: 1 },\n { resource: \"energy.battery\", need: \"power.electric\", amount: 1 },\n ],\n converters: [\n {\n id: \"cook-rice\",\n device: \"stove\",\n takes: [\n { resource: \"food.grain-dry\", amount: 1 },\n { resource: \"water.stored\", amount: 2 },\n { resource: \"fuel.propane\", amount: 0.05 },\n ],\n gives: { need: \"food.energy\", amount: 3600 },\n },\n ],\n cases: [\n {\n case: \"storm\",\n title: \"Winter storm\",\n cuts: [\n { part: \"grid\", title: \"Power outage\", duration: [[0, 1], [0.5, 0.5], [1, 0.36], [7, 0.013], [30, 0]], source: \"nrel-83092\" },\n { part: \"road\", title: \"Closed local road\", duration: [[0, 1], [1, 0.6], [3, 0.2], [10, 0]], source: \"sample\" },\n { part: \"water-main\", title: \"No water from the main\", duration: [[0, 1], [2, 0.3], [7, 0]], source: \"sample\" },\n ],\n leadSeconds: 86_400,\n },\n { case: \"fire\", title: \"Fire\", cuts: [] },\n ],\n priors: [\n { case: \"storm\", place: \"home\", perYear: 0.8, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n { case: \"fire\", place: \"home\", perYear: 0.003, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n ],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB,UAAU,OAAuB,UAAoB,SAAsB,OAAqC;CAC9H,MAAM,QAAQ,IAAI,IAAI,MAAM,MAAM,KAAK,SAAS,KAAK,IAAI,CAAC;CAC1D,MAAM,UAAU,MAAM,QAAQ,SAAS,CAAC,MAAM,IAAI,IAAI,CAAC;CACvD,IAAI,QAAQ,SAAS,GAAG,MAAM,IAAI,WAAW,aAAa,QAAQ,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,0CAA0C;CAClJ,MAAM,eAAe,YAAY,UAAU,OAAO;CAClD,MAAM,QAAQ,aAAa,OAAO,QAAQ,IAAI,YAAY;CAC1D,MAAM,SAAS,IAAI,IAAI,KAAK;CAC5B,MAAM,OAAO,UAAU,OAAO,UAAU,YAAY,CAAC,CAAC,QAAQ,SAAS,OAAO,IAAI,KAAK,IAAI,CAAC;CAC5F,MAAM,UAAU,IAAI,IAAI,KAAK,KAAK,SAAS,KAAK,IAAI,CAAC;CACrD,MAAM,OAAO;EAAE,MAAM,SAAS;EAAM,IAAI,QAAQ;EAAI,MAAM,KAAK,KAAK,SAAS,KAAK,IAAI;EAAG,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,SAAS,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK;CAAE;CACxJ,MAAM,UAAqB;EAAE,GAAG;EAAM,MAAM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E,MAAM;EAAQ,OAAO;EAAQ,SAAS;EAAO,OAAO;EAAG,QAAQ;EAAU,MAAM;CAAa,CAChG;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
-
import { CUT_BOUNDS, bandFault, curveFault, curveFault as curveFault$1, dayNumber, isCutBound, joinRecords, joinSetting, stopped } from "@mark1russell7/system-stack";
|
|
2
|
+
import { CUT_BOUNDS, bandFault, curveFault, curveFault as curveFault$1, dayNumber, intervalFault, isCutBound, joinRecords, joinSetting, stopped } from "@mark1russell7/system-stack";
|
|
3
3
|
import { ONE, ZERO, add, div, fromFloat, mul, neg, sign, toNumber } from "@mark1russell7/rational";
|
|
4
4
|
import { solveLexicographic } from "@mark1russell7/linear";
|
|
5
5
|
import { stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
@@ -813,6 +813,8 @@ function checkEndurance(layer, stack) {
|
|
|
813
813
|
range(at, "count of events in one year", prior.perYear);
|
|
814
814
|
if (!(prior.reach >= 0 && prior.reach <= 1)) add("error", "endurance-range", at, `The reach of "${at}" is ${String(prior.reach)}. It must be from 0 to 1.`);
|
|
815
815
|
date(at, prior.asOf);
|
|
816
|
+
const fault = prior.interval === void 0 ? void 0 : intervalFault(prior.interval);
|
|
817
|
+
if (fault !== void 0) add("error", "endurance-range", at, `The interval of the count of events in one year of "${at}" is not valid. ${fault}`);
|
|
816
818
|
}
|
|
817
819
|
return faults;
|
|
818
820
|
}
|
|
@@ -897,4 +899,4 @@ function joinEndurance(pieces) {
|
|
|
897
899
|
}
|
|
898
900
|
export { exact as S, fewestRow as _, hasEnduranceError as a, addTo as b, drawDemand as c, giftResource as d, storeAmounts as f, drawBlock as g, deviceUse as h, curveFault as i, enduranceOf as l, caseParts as m, ENDURANCE_CODES as n, caseDraws as o, Program as p, checkEndurance as r, caseStopped as s, joinEndurance as t, giftNeed as u, reachOf as v, dense as x, valueAt as y };
|
|
899
901
|
|
|
900
|
-
//# sourceMappingURL=join-
|
|
902
|
+
//# sourceMappingURL=join-C9nJDe7B.js.map
|