@mark1russell7/stack-endurance 0.8.25 → 0.8.26

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.
@@ -661,7 +661,7 @@ function firstStop(plan, fixed, open, tail = () => []) {
661
661
  coefficients: most.coefficients,
662
662
  relation: "=",
663
663
  rhs: days
664
- }], later);
664
+ }], later, { warm: true });
665
665
  if (full.status !== "optimal") throw new Error("The step of a season has no optimum for its later objectives.");
666
666
  const first = solved.stages[0]?.result;
667
667
  return {
@@ -834,7 +834,7 @@ function seasonBest(plan, fixed, levels, stored, fill = false) {
834
834
  coefficients: dense(fewestRow(cells.flatMap((cell) => [...cell.block.runs])), program.count)
835
835
  });
836
836
  if (fill) objectives.push(mostCharge(plan, charges, program.count));
837
- const solved = solveLexicographic(program.constraints(), objectives);
837
+ const solved = solveLexicographic(program.constraints(), objectives, { warm: true });
838
838
  if (solved.status !== "optimal") throw new Error("The last program of the best endurance with a season has no optimum. The point of the last step is a point of it.");
839
839
  const x = solved.x;
840
840
  const rests = fill ? restsOf(plan, cells, x, charges) : void 0;
@@ -1032,7 +1032,7 @@ function bestShare(input) {
1032
1032
  coefficients: dense(fewestRow(block.runs), program.count)
1033
1033
  }
1034
1034
  ];
1035
- const solved = solveLexicographic(program.constraints(), objectives);
1035
+ const solved = solveLexicographic(program.constraints(), objectives, { warm: true });
1036
1036
  if (solved.status !== "optimal") return void 0;
1037
1037
  const at = (index) => solved.x[index] ?? ZERO;
1038
1038
  const taken = /* @__PURE__ */ new Map();
@@ -2043,4 +2043,4 @@ function joinEndurance(pieces) {
2043
2043
  }
2044
2044
  export { deviceUse as A, fixStops as C, storeCapacities as D, seasonPlan as E, addTo as F, dense as I, exact as L, fewestRow as M, reachOf as N, Program as O, valueAt as P, deviceKey as R, firstStop as S, seasonJoint as T, seasonSupply as _, hasEnduranceError as a, storeAmounts as b, caseStopped as c, giftNeed as d, giftResource as f, monthlyShares as g, monthOf as h, curveFault as i, drawBlock as j, caseParts as k, drawDemand as l, monthEdges as m, ENDURANCE_CODES as n, SEASON_HORIZON_DAYS as o, hasSeason as p, checkEndurance as r, caseDraws as s, joinEndurance as t, enduranceOf as u, shareOf as v, seasonBest as w, fewestOpen as x, sowDays as y, isSource as z };
2045
2045
 
2046
- //# sourceMappingURL=join-CxA4Td_Z.js.map
2046
+ //# sourceMappingURL=join-BwTee3Ue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-BwTee3Ue.js","names":["inputClosure","closureOf","curveFault"],"sources":["../src/converter.ts","../src/fit.ts","../src/rows.ts","../src/program.ts","../src/seasonal.ts","../src/share.ts","../src/endurance.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import type { Converter } from \"./layer.ts\";\n\n// The internal rules of a converter that the endurance query and the joint days share. The root entry does not give them.\n\n/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */\nexport function inputsOf(converter: Converter): Map<string, number> {\n const out = new Map<string, number>();\n for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);\n return out;\n}\n\n/**\n * This function tells if a converter is a source (M2-solar): it takes nothing, and it has a limit `perDay` more than 0.\n * Its runs of a day are lost when no draw uses them. Thus a take uses a source before a store.\n */\nexport function isSource(converter: Converter): boolean {\n if (!(converter.perDay !== undefined && converter.perDay > 0)) return false;\n // The same test as `inputsOf(converter).size === 0`, with no map: the take loops call it.\n for (const input of converter.takes) if (input.amount > 0) return false;\n return true;\n}\n\n/**\n * This function tells if a converter can run in a case. Its device works, it takes a resource or it is a source, and it\n * gives an amount more than 0.\n */\nexport function canRun(converter: Converter, stoppedParts: ReadonlySet<string>): boolean {\n return converter.gives.amount > 0 && (inputsOf(converter).size > 0 || isSource(converter)) && (converter.device === undefined || !stoppedParts.has(converter.device));\n}\n\n/**\n * This function gives the key of the device-days that a converter uses. The converters of one device share one key.\n * A converter with no device has a key of its own.\n */\nexport function deviceKey(converter: Converter): string {\n return converter.device === undefined ? `converter:${converter.id}` : `device:${converter.device}`;\n}\n","/** The relative tolerance of a take and of a fit. */\nexport const TOLERANCE = 1e-13;\n\n/** One try of a fit: the amount that the stores could not give, out of the amount wanted, and the value of the try. */\nexport interface Try<T> {\n readonly short: number;\n readonly need: number;\n readonly value: T;\n}\n\n/** The result of a fit: the largest amount with no shortfall, and the value of its try. The value is `undefined` when only 0 fits. */\nexport interface Fit<T> {\n readonly x: number;\n readonly value: T | undefined;\n}\n\n/**\n * The count of the tries of `largestFit`, for the tests of the cost. It is not in the public API, and it does not change a result.\n * It is the one side effect of `largestFit` and of the queries that use it.\n */\nexport const fitTries = { count: 0 };\n\n/**\n * This function gives the largest `x` in `[0, most]` at which `attempt` has no shortfall, to the relative tolerance `TOLERANCE`.\n *\n * - A try fits when its shortfall is not more than `TOLERANCE` times its need.\n * - The shortfall must not decrease when `x` increases. A take of a chain of converters gives a shortfall that is linear in parts.\n * - The first try is `most`. After it, each step tries the zero of the line through the last two tries that do not fit.\n * With one try that does not fit, the step tries `x` times the part of the need that the stores gave.\n * - When a step does not halve the interval, the next step is a bisection. Thus a fit takes at most approximately twice the steps of a bisection.\n * - A step on the lower end tries a point just above it, so a correct estimate ends the fit in one more try.\n * - An estimate that fits with a shortfall above 0 is in the band of the tolerance above the zero, so the fit ends there.\n * A bisection step or a probe at the lower end can fit with a shortfall of rounding below the zero. The fit does not end there.\n *\n * @param most - The upper limit of `x`\n * @param attempt - The try at an amount. It must not change its input\n * @returns The largest amount that fits, and the value of its try\n */\nexport function largestFit<T>(most: number, attempt: (x: number) => Try<T>): Fit<T> {\n const fits = (tried: Try<T>): boolean => tried.short <= TOLERANCE * tried.need;\n fitTries.count += 1;\n const first = attempt(most);\n if (fits(first)) return { x: most, value: first.value };\n let low = 0;\n let best: T | undefined;\n let high = most;\n let highShort = first.short;\n let highNeed = first.need;\n let before: { readonly x: number; readonly short: number } | undefined;\n let bisect = false;\n for (let step = 0; step < 400 && high - low > 4 * TOLERANCE * high; step += 1) {\n const width = high - low;\n let x: number;\n if (bisect) x = (low + high) / 2;\n else if (before !== undefined && before.short > highShort) x = high - (highShort * (before.x - high)) / (before.short - highShort);\n else x = high * (1 - highShort / highNeed);\n // Only a secant or ratio estimate through tries that do not fit lands at or above the zero of a convex shortfall.\n const estimate = !bisect && x < high;\n if (!(x < high)) x = (low + high) / 2;\n const floor = low + 2 * TOLERANCE * high;\n const clamped = !(x > floor);\n if (clamped) x = floor;\n fitTries.count += 1;\n const tried = attempt(x);\n if (fits(tried)) {\n low = x;\n best = tried.value;\n // An estimate that fits with a shortfall is in the band of the tolerance above the zero, so the fit ends.\n if (tried.short > 0 && estimate && !clamped) break;\n } else {\n before = { x: high, short: highShort };\n high = x;\n highShort = tried.short;\n highNeed = tried.need;\n }\n bisect = !bisect && high - low > width / 2;\n }\n return { x: low, value: best };\n}\n","import { add, fromFloat, type Rational, ZERO } from \"@mark1russell7/rational\";\n\n// The internal rows of the linear programs of the queries. The root entry does not give them.\n\n/** A sparse row: the coefficient of each variable, by its index. */\nexport type Row = Map<number, Rational>;\n\n/** This function adds `value` to the coefficient of the variable `index` in `row`. It changes `row`. */\nexport function addTo(row: Row, index: number, value: Rational): void {\n row.set(index, add(row.get(index) ?? ZERO, value));\n}\n\n/** This function gives the dense form of a row: one coefficient for each of `count` variables. */\nexport function dense(row: Row, count: number): Rational[] {\n const out = new Array<Rational>(count).fill(ZERO);\n for (const [index, value] of row) out[index] = value;\n return out;\n}\n\n/** This function gives the exact rational of a finite double, with no rounding. A double is a dyadic rational. */\nexport function exact(value: number): Rational {\n return fromFloat(value);\n}\n","import type { Constraint } from \"@mark1russell7/linear\";\nimport { add, div, mul, neg, ONE, type Rational, ZERO } from \"@mark1russell7/rational\";\nimport { canRun, deviceKey, inputsOf } from \"./converter.ts\";\nimport { giftNeed, giftResource } from \"./endurance.ts\";\nimport type { Converter, DirectUse, Draw, EnduranceLayer } from \"./layer.ts\";\nimport { addTo, dense, exact, type Row } from \"./rows.ts\";\n\n// The internal parts of the linear programs over the totals of a span: the parts of a case, the columns and rows of each draw,\n// and the device-days of the converters. The joint days and the best endurance use them. The root entry does not give them.\n\n/** One constraint row of a program, in its sparse form. */\nexport interface RowSpec {\n readonly row: Row;\n readonly relation: Constraint[\"relation\"];\n readonly rhs: Rational;\n}\n\n/** A program in construction: the count of its variables and its rows. */\nexport class Program {\n count = 0;\n readonly rows: RowSpec[] = [];\n\n /** This method adds a variable and gives its index. */\n next(): number {\n return this.count++;\n }\n\n /** This method adds a row and gives its index. */\n push(row: Row, relation: Constraint[\"relation\"], rhs: Rational): number {\n this.rows.push({ row, relation, rhs });\n return this.rows.length - 1;\n }\n\n /** This method gives the dense rows for `solveLexicographic`. */\n constraints(): Constraint[] {\n return this.rows.map(({ row, relation, rhs }) => ({ coefficients: dense(row, this.count), relation, rhs }));\n }\n}\n\n/** The parts of a case that the programs use. */\nexport interface CaseParts {\n /** The stock of each resource at the date of the query (`storeAmounts`). */\n readonly stock: ReadonlyMap<string, number>;\n /** The direct uses of the needs of the program, with an amount more than 0. */\n readonly direct: readonly DirectUse[];\n /** The converters that can run and give a need of the program. */\n readonly cooks: readonly Converter[];\n /** The converters that can run and give a resource. */\n readonly makers: readonly Converter[];\n /** Each resource that a direct use or a converter takes, and each resource that a maker gives. */\n readonly resources: ReadonlySet<string>;\n /** The resources of `resources` with a stock more than 0, in the order of their codes. */\n readonly stocked: readonly string[];\n}\n\n/** This function gives the parts of a case for the draws of `needs`. */\nexport function caseParts(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>, stock: ReadonlyMap<string, number>, needs: ReadonlySet<string>): CaseParts {\n const direct = (layer.direct ?? []).filter((use) => needs.has(use.need) && use.amount > 0);\n // A converter with a season gives its resource only at its harvests (`seasonSupply`), thus it is not a cook or a maker of a program.\n const live = (layer.converters ?? []).filter((converter) => converter.season === undefined && canRun(converter, stoppedParts));\n const cooks = live.filter((converter) => needs.has(giftNeed(converter) ?? \"\"));\n const makers = live.filter((converter) => giftResource(converter) !== undefined);\n return partsOf(stock, direct, cooks, makers);\n}\n\n/** This function gives the parts of a case from its stock, its direct uses, its cooks and its makers. */\nexport function partsOf(stock: ReadonlyMap<string, number>, direct: readonly DirectUse[], cooks: readonly Converter[], makers: readonly Converter[]): CaseParts {\n const resources = new Set<string>([...direct.map((use) => use.resource), ...[...cooks, ...makers].flatMap((converter) => [...inputsOf(converter).keys()])]);\n for (const maker of makers) resources.add(giftResource(maker) ?? \"\");\n const stocked = [...resources].filter((resource) => (stock.get(resource) ?? 0) > 0).sort();\n return { stock, direct, cooks, makers, resources, stocked };\n}\n\n/** The columns of one draw in a program. */\nexport interface DrawBlock {\n readonly draw: Draw;\n /** The gifts of the need of the draw from the columns of its direct uses and of its cooks. The caller adds the term of the days. */\n readonly gifts: Row;\n /** The column of the share of each stock, by the code of the resource. It is empty for a draw with no stock. */\n readonly shares: ReadonlyMap<string, number>;\n /** The column of the runs of each converter for the draw: each cook of its need, and each maker. */\n readonly runs: ReadonlyMap<Converter, number>;\n}\n\n/**\n * This function adds the columns of one draw to a program, and the balance row of each of its resources.\n * In a balance row, the takes of the draw are not more than its share of the stock plus the gifts of its makers.\n * The caller adds the row of the need, with the term of the days.\n *\n * A draw has columns and rows only for the resources and the makers that it can use (`reachOf`).\n * A share of another resource or the runs of another maker cannot give the need of the draw. Thus the optimum of each program is the same.\n * This keeps each program small: the programs are dense, so each column of each draw costs a column in each row.\n *\n * @param stocked - False for a draw that takes no stock. Its shares are not columns.\n */\nexport function drawBlock(program: Program, parts: CaseParts, draw: Draw, stocked = true): DrawBlock {\n const gifts: Row = new Map();\n const { closure, reach } = reachOf(parts, new Set([draw.need]));\n const balance = new Map<string, Row>([...closure].map((resource) => [resource, new Map()]));\n const consume = (resource: string, index: number, amount: Rational): void => addTo(balance.get(resource) as Row, index, amount);\n for (const use of parts.direct) {\n if (use.need !== draw.need) continue;\n const index = program.next();\n addTo(gifts, index, exact(use.amount));\n consume(use.resource, index, ONE);\n }\n const runs = new Map<Converter, number>();\n for (const cook of parts.cooks) {\n if (giftNeed(cook) !== draw.need) continue;\n const index = program.next();\n runs.set(cook, index);\n addTo(gifts, index, exact(cook.gives.amount));\n for (const [resource, each] of inputsOf(cook)) consume(resource, index, exact(each));\n }\n for (const maker of parts.makers) {\n if (!reach.has(maker)) continue;\n const index = program.next();\n runs.set(maker, index);\n for (const [resource, each] of inputsOf(maker)) consume(resource, index, exact(each));\n consume(giftResource(maker) as string, index, neg(exact(maker.gives.amount)));\n }\n const shares = new Map(stocked ? parts.stocked.filter((resource) => closure.has(resource)).map((resource) => [resource, program.next()] as const) : []);\n for (const [resource, index] of shares) consume(resource, index, neg(ONE));\n for (const row of balance.values()) if (row.size > 0) program.push(row, \"<=\", ZERO);\n return { draw, gifts, shares, runs };\n}\n\n/** The device-days of a limit: the runs of its converters over `perDay`, the count of its devices, and its converters. */\nexport interface DeviceLimit {\n readonly row: Row;\n readonly devices: number;\n readonly converters: Converter[];\n}\n\n/**\n * This function gives the device-days of each device of a set of run columns, by the key of the device (`deviceKey`).\n * One run uses `1 / perDay` of a day of one device. The converters of one device share one limit. A converter with no device has a limit of its own.\n * A converter with no limit `perDay` is not in the record. The list `stopped` has the columns of the converters with a limit of 0.\n */\nexport function deviceUse(runs: Iterable<readonly [Converter, number]>): { readonly limits: Map<string, DeviceLimit>; readonly stopped: number[] } {\n const limits = new Map<string, DeviceLimit>();\n const stopped: number[] = [];\n for (const [converter, index] of runs) {\n if (converter.perDay === undefined) continue;\n if (!(converter.perDay > 0)) {\n stopped.push(index);\n continue;\n }\n const key = deviceKey(converter);\n const limit: DeviceLimit = limits.get(key) ?? { row: new Map(), devices: converter.devices ?? 1, converters: [] };\n limits.set(key, limit);\n if (!limit.converters.includes(converter)) limit.converters.push(converter);\n addTo(limit.row, index, div(ONE, exact(converter.perDay)));\n }\n return { limits, stopped };\n}\n\n/**\n * This function gives the row of the fewest device-days of a set of run columns: the runs over `perDay`, or the runs with no limit.\n * As an objective, it gives no more runs than the plan uses.\n */\nexport function fewestRow(runs: Iterable<readonly [Converter, number]>): Row {\n const out: Row = new Map();\n for (const [converter, index] of runs) addTo(out, index, converter.perDay !== undefined && converter.perDay > 0 ? div(ONE, exact(converter.perDay)) : ONE);\n return out;\n}\n\n/** This function gives the value of a sparse row at the point `x`. */\nexport function valueAt(row: Row, x: readonly Rational[]): Rational {\n let out = ZERO;\n for (const [index, value] of row) out = add(out, mul(value, x[index] ?? ZERO));\n return out;\n}\n\n/**\n * This function gives each resource that a draw can use: the resources of its direct uses and the inputs of its cooks.\n * It also gives the inputs of their makers, through each chain.\n */\nexport function inputClosure(direct: readonly string[], cooks: readonly Converter[], makers: readonly Converter[]): Set<string> {\n const out = new Set<string>();\n const queue = [...direct, ...cooks.flatMap((cook) => [...inputsOf(cook).keys()])];\n for (let resource = queue.shift(); resource !== undefined; resource = queue.shift()) {\n if (out.has(resource)) continue;\n out.add(resource);\n for (const maker of makers) if (giftResource(maker) === resource) queue.push(...inputsOf(maker).keys());\n }\n return out;\n}\n\n/** This function gives the resources that the draws of `needs` can use, and the converters that they can use. */\nexport function reachOf(parts: CaseParts, needs: ReadonlySet<string>): { readonly closure: Set<string>; readonly reach: Set<Converter> } {\n const cooks = parts.cooks.filter((cook) => needs.has(giftNeed(cook) ?? \"\"));\n const closure = inputClosure(parts.direct.filter((use) => needs.has(use.need)).map((use) => use.resource), cooks, parts.makers);\n return { closure, reach: new Set([...cooks, ...parts.makers.filter((maker) => closure.has(giftResource(maker) ?? \"\"))]) };\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 { deviceKey, isSource } from \"./converter.ts\";\nimport { drawDemand, giftResource, type HarvestLot, monthEdges, monthlyShares, monthOf, type SeasonSupply, shareOf } from \"./endurance.ts\";\nimport type { CaseCuts, Converter, Draw, DrawEndurance, EnduranceLayer, IsoDate } from \"./layer.ts\";\nimport { type CaseParts, caseParts, deviceUse, drawBlock, type DrawBlock, fewestRow, partsOf, Program, reachOf, valueAt } from \"./program.ts\";\nimport { addTo, dense, exact, type Row } from \"./rows.ts\";\n\n// The linear programs of a case with a season (M2-grow-share): the best endurance and the joint days with harvests.\n// The days go in segments. A segment ends at each harvest day, at each spoil day and at the horizon. In a segment,\n// no lot comes and no lot spoils, so the programs over the totals of a segment are exact. The root entry does not give them.\n// With shares `monthly` (M2-solar), a segment also ends at the start of each month, so the device-days of a segment are exact too.\n\n/** A lot of the programs: a store (day 0, no spoil day) or the rest of a harvest after the sowings. */\nexport interface PlanLot {\n readonly resource: string;\n readonly day: number;\n readonly spoils: number;\n readonly amount: Rational;\n /** The index of a harvest lot in the lots of the supply (`SeasonSupply.lots`). A store lot has none. */\n readonly origin?: number;\n}\n\n/** The parts of the programs of a case with a season. */\nexport interface SeasonPlan {\n /** The parts of the case. The stock of each resource is the stores after the sowings plus the harvests. */\n readonly parts: CaseParts;\n readonly caseCuts: CaseCuts;\n /** The draws whose supply stops, in the order of `caseDraws`. */\n readonly draws: readonly Draw[];\n /** The count of devices of each key. */\n readonly devices: ReadonlyMap<string, number>;\n readonly lots: readonly PlanLot[];\n /** The ends of the segments: 0, each harvest day and each spoil day in the horizon, and the horizon. With shares, also the start of each month. */\n readonly edges: readonly number[];\n /** The shares `monthly` of each device key (M2-solar). A key with no shares has the share 1 in each month. */\n readonly shares: ReadonlyMap<string, readonly number[]>;\n /** The month of each segment, 0 for January. */\n readonly months: readonly number[];\n /** The stores with a capacity that a source charges (M2-solar-charge), in the order of their resources. */\n readonly charges: readonly PlanCharge[];\n}\n\n/** A resource whose stores have a capacity, with the sources that charge it (M2-solar-charge). */\nexport interface PlanCharge {\n readonly resource: string;\n /** The sum of the capacities of the stores of the resource. */\n readonly capacity: Rational;\n /** The lot of the stores of the resource. Its amount is the level on day 0, and it can be 0. */\n readonly lot: PlanLot;\n /** The sources that give the resource: converters with a limit `perDay` and no inputs. */\n readonly sources: readonly Converter[];\n /** The right side of the takes of each segment (M2-solar-charge-sweep). The takes can be this much more than the level that the plan adds before the segment. */\n readonly take: readonly Rational[];\n /** The right side of the charge of each segment: the most that it can be, plus the level that the plan adds before it. */\n readonly fill: readonly Rational[];\n /** True if the higher draws of the sweep give the rest. Then two more rows keep the takes and the charges of the higher draws possible after the last cell. */\n readonly higher: boolean;\n}\n\n/**\n * The rest of a store with a capacity that the higher draws of the sweep of `enduranceOf` leave in a span of days (M2-solar-charge-sweep).\n * The takes of a lower draw in the span can be `take` more than the level that the lower draw adds before the span.\n * The charge of a lower draw in the span can be `fill` less that level.\n */\nexport interface ChargeRest {\n readonly from: number;\n readonly to: number;\n /** The level at the start of the span, less the takes of the higher draws in the span. */\n readonly take: Rational;\n /** The capacity, less the level at the start of the span and the charges of the higher draws in the span. */\n readonly fill: Rational;\n}\n\n/** This function gives the least of a list of rationals, or `none` for an empty list. */\nfunction leastOf(values: readonly Rational[], none: Rational): Rational {\n let low: Rational | undefined;\n for (const value of values) if (low === undefined || sign(sub(value, low)) < 0) low = value;\n return low ?? none;\n}\n\n/**\n * This function gives the capacity of each resource whose stores have a capacity (M2-solar-charge). A store whose part is\n * in `stoppedParts` has no capacity. A store with a due date has no charge: the gate refuses a capacity with a due date.\n */\nexport function storeCapacities(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): Map<string, number> {\n const out = new Map<string, number>();\n for (const store of layer.stores) {\n if (store.capacity === undefined || store.due !== undefined) continue;\n if (store.part !== undefined && stoppedParts.has(store.part)) continue;\n out.set(store.resource, (out.get(store.resource) ?? 0) + store.capacity);\n }\n return out;\n}\n\n/**\n * This function gives the parts of the programs of a case with a season. `parts` are the parts of the case with the\n * stock after the sowings (`seasonSupply`).\n *\n * @param rests - The rest of each store with a capacity that the higher draws of the sweep leave (M2-solar-charge-sweep).\n * A segment gets the least rest of the spans that it touches. This is the safe side.\n */\nexport function seasonPlan(\n supply: SeasonSupply,\n parts: CaseParts,\n caseCuts: CaseCuts,\n draws: readonly Draw[],\n devices: ReadonlyMap<string, number>,\n capacities: ReadonlyMap<string, number> = new Map(),\n rests: ReadonlyMap<string, readonly ChargeRest[]> = new Map(),\n): SeasonPlan {\n const total = new Map(supply.stock);\n const harvests = supply.lots.map((lot, origin) => ({ ...lot, origin })).filter((lot) => parts.resources.has(lot.resource));\n for (const lot of harvests) total.set(lot.resource, (total.get(lot.resource) ?? 0) + lot.amount);\n const found = partsOf(total, parts.direct, parts.cooks, parts.makers);\n // A store with a capacity that a source charges has a lot, also when it is empty (M2-solar-charge).\n const sourcesOf = (resource: string): Converter[] => found.makers.filter((maker) => isSource(maker) && giftResource(maker) === resource);\n const charged = [...capacities.keys()].filter((resource) => found.resources.has(resource) && sourcesOf(resource).length > 0).sort();\n const all: CaseParts = { ...found, stocked: [...new Set([...found.stocked, ...charged])].sort() };\n const storeLot = (resource: string): PlanLot => ({ resource, day: 0, spoils: Infinity, amount: exact(supply.stock.get(resource) ?? 0) });\n const lots: PlanLot[] = [\n ...all.stocked.filter((resource) => (supply.stock.get(resource) ?? 0) > 0 || charged.includes(resource)).map(storeLot),\n ...harvests.map((lot) => ({ resource: lot.resource, day: Math.max(0, lot.day), spoils: lot.spoils, amount: exact(lot.amount), origin: lot.origin })),\n ];\n const inside = (day: number): boolean => day > 0 && day < supply.horizon;\n const shares = monthlyShares([...all.cooks, ...all.makers]);\n const months = shares.size === 0 ? [] : monthEdges(supply.start, supply.horizon);\n const edges = [...new Set([0, supply.horizon, ...months, ...lots.flatMap((lot) => [lot.day, lot.spoils]).filter(inside)])].sort((a, b) => a - b);\n const charges = charged.map((resource): PlanCharge => {\n const lot = lots.find((item) => item.resource === resource && item.origin === undefined) as PlanLot;\n // The gate keeps the amount within the capacity. The largest of the two keeps the program feasible when it does not.\n const capacity = exact(Math.max(capacities.get(resource) ?? 0, toNumber(lot.amount)));\n const rest = rests.get(resource) ?? [];\n const spans = edges.slice(0, -1).map((from, index) => rest.filter((item) => item.from < (edges[index + 1] ?? Infinity) && item.to > from));\n const take = spans.map((list) => leastOf(list.map((item) => item.take), lot.amount));\n const fill = spans.map((list) => leastOf(list.map((item) => item.fill), sub(capacity, lot.amount)));\n return { resource, capacity, lot, sources: sourcesOf(resource), take, fill, higher: rest.length > 0 };\n });\n const monthOfSegment = edges.slice(0, -1).map((edge) => (shares.size === 0 ? 0 : monthOf(supply.start, edge)));\n return { parts: all, caseCuts, draws, devices, lots, edges, shares, months: monthOfSegment, charges };\n}\n\n/** The first stop of a draw whose days are fixed. */\nexport interface FixedStop {\n /** The days to the first stop. */\n readonly stop: Rational;\n /** The index of the segment of the stop. */\n readonly segment: number;\n /** The device-days of each day that the draw keeps in each segment to its stop. The keys are the index of the segment, then the key of the device. */\n readonly keep: ReadonlyMap<number, ReadonlyMap<string, Rational>>;\n readonly atHorizon: boolean;\n readonly capped: readonly string[];\n}\n\n/** The columns of one draw in one segment. */\ninterface Cell {\n readonly draw: Draw;\n readonly segment: number;\n readonly block: DrawBlock;\n /** The fed days of the cell in its segment: a constant, or the index of a column. */\n readonly fed: Rational | number;\n /** The column of the take of each lot that the cell can take. */\n readonly takes: ReadonlyMap<PlanLot, number>;\n}\n\n/** The device-days of the open cells of one segment for one device. */\ninterface Shared {\n readonly row: Row;\n readonly room: Rational;\n readonly converters: readonly Converter[];\n}\n\n/** A program of one step, with the indexes of its parts. */\ninterface Step {\n readonly program: Program;\n /** The column of the common days of the open draws to their first stop. */\n readonly t: number;\n readonly cells: readonly Cell[];\n /** The row `fed - (t - edge) >= 0` of each open draw in the segment of the stop, by the code of its need. */\n readonly floors: ReadonlyMap<string, number>;\n /** The device-days of the open cells of each segment to the stop, by the index of the segment, then the key of the device. */\n readonly shared: ReadonlyMap<number, ReadonlyMap<string, Shared>>;\n /** The index of the segment of the stop. */\n readonly segment: number;\n /** The charge columns of the step (M2-solar-charge). */\n readonly charges: Charges;\n}\n\nconst edgeOf = (plan: SeasonPlan, index: number): Rational => exact(plan.edges[index] ?? 0);\nconst lengthOf = (plan: SeasonPlan, index: number): Rational => sub(edgeOf(plan, index + 1), edgeOf(plan, index));\nconst segmentsOf = (plan: SeasonPlan): number => plan.edges.length - 1;\n\n/** This function gives the fed days of a fixed draw in a segment. It is all of a segment before the stop, the part to the stop, then 0. */\nfunction fixedFed(plan: SeasonPlan, fix: FixedStop, segment: number): Rational {\n if (segment < fix.segment) return lengthOf(plan, segment);\n if (segment === fix.segment) return sub(fix.stop, edgeOf(plan, segment));\n return ZERO;\n}\n\n/**\n * This function adds the columns of one draw in one segment. The gifts of the need are not less than the demand times the fed days.\n * The share of each stock is the sum of the takes of the lots that are ready and not spoiled in the whole segment.\n */\nfunction addCell(program: Program, plan: SeasonPlan, draw: Draw, segment: number, fed: Rational | number): Cell {\n const block = drawBlock(program, plan.parts, draw);\n const demand = exact(drawDemand(draw, plan.caseCuts));\n const need: Row = new Map(block.gifts);\n if (typeof fed === \"number\") {\n addTo(need, fed, neg(demand));\n program.push(need, \">=\", ZERO);\n } else program.push(need, \">=\", mul(demand, fed));\n const from = plan.edges[segment] ?? 0;\n const to = plan.edges[segment + 1] ?? Infinity;\n const takes = new Map<PlanLot, number>();\n for (const [resource, share] of block.shares) {\n const row: Row = new Map([[share, ONE]]);\n for (const lot of plan.lots) {\n if (lot.resource !== resource || lot.day > from || lot.spoils < to) continue;\n const column = program.next();\n takes.set(lot, column);\n addTo(row, column, neg(ONE));\n }\n program.push(row, \"=\", ZERO);\n }\n return { draw, segment, block, fed, takes };\n}\n\n/** This function adds the row of each lot: the takes of all the cells are not more than its amount. The rows of `addCharges` cover the lot of a charge. */\nfunction lotRows(program: Program, plan: SeasonPlan, cells: readonly Cell[]): void {\n const charged = new Set(plan.charges.map((charge) => charge.lot));\n for (const lot of plan.lots) {\n if (charged.has(lot)) continue;\n const row: Row = new Map();\n for (const cell of cells) {\n const column = cell.takes.get(lot);\n if (column !== undefined) addTo(row, column, ONE);\n }\n if (row.size > 0) program.push(row, \"<=\", lot.amount);\n }\n}\n\n/** The charge columns of a program (M2-solar-charge). */\ninterface Charges {\n /** The pairs of a source and its charge column in each segment, for the rows of the device-days. */\n readonly pairs: ReadonlyMap<number, readonly (readonly [Converter, number])[]>;\n /** The gift of all the charges of each resource, as a row. */\n readonly gifts: ReadonlyMap<string, Row>;\n /** The gift of the charge of each resource in each segment before `through`, as a row (M2-solar-charge-sweep). */\n readonly segments: ReadonlyMap<string, readonly Row[]>;\n}\n\n/**\n * This function adds the charge of each store with a capacity in the segments before `through` (M2-solar-charge).\n * Each source has one charge column in each segment before the last one: no take of the program uses the charge of the last one.\n * The level at the start of a segment is the amount of the lot plus the charges of the segments before it, less their takes.\n * - The takes of a segment are not more than the level at its start.\n * - The level at the start of a segment plus its charge is not more than the capacity.\n * Thus each order of the takes and the charges in a segment is a plan. The caller adds the charge columns to the rows of the device-days.\n *\n * With no higher draws, the right side of the takes is the amount of the lot. The right side of the charge is the capacity less that amount.\n * With higher draws (M2-solar-charge-sweep), the right sides are the rest that they leave (`PlanCharge.take` and `fill`).\n * Then each segment has the row of its charge, and two more rows keep the level after `through` in the rest of the later segments.\n */\nfunction addCharges(program: Program, plan: SeasonPlan, cells: readonly Cell[], through: number): Charges {\n const pairs = new Map<number, [Converter, number][]>();\n const gifts = new Map<string, Row>();\n const segments = new Map<string, Row[]>();\n for (const charge of plan.charges) {\n // The level at the start of the segment that the draws of the plan add.\n const level: Row = new Map();\n const given: Row = new Map();\n const each: Row[] = [];\n gifts.set(charge.resource, given);\n segments.set(charge.resource, each);\n for (let segment = 0; segment < through; segment += 1) {\n const takes: Row = new Map();\n for (const cell of cells) {\n const column = cell.segment === segment ? cell.takes.get(charge.lot) : undefined;\n if (column !== undefined) addTo(takes, column, ONE);\n }\n const most: Row = new Map(takes);\n for (const [column, value] of level) addTo(most, column, neg(value));\n program.push(most, \"<=\", charge.take[segment] ?? charge.lot.amount);\n const full: Row = new Map(level);\n const own: Row = new Map();\n each.push(own);\n if (segment + 1 < through) {\n for (const source of charge.sources) {\n const column = program.next();\n pairs.set(segment, [...(pairs.get(segment) ?? []), [source, column]]);\n const amount = exact(source.gives.amount);\n addTo(full, column, amount);\n addTo(level, column, amount);\n addTo(given, column, amount);\n addTo(own, column, amount);\n }\n program.push(full, \"<=\", charge.fill[segment] ?? sub(charge.capacity, charge.lot.amount));\n } else if (charge.higher) program.push(full, \"<=\", charge.fill[segment] ?? ZERO);\n for (const [column, value] of takes) addTo(level, column, neg(value));\n }\n if (charge.higher && through < segmentsOf(plan)) {\n // After `through`, the plan has no takes and no charge. Its level must keep the takes and the charges of the higher draws possible.\n const less: Row = new Map();\n for (const [column, value] of level) addTo(less, column, neg(value));\n program.push(less, \"<=\", leastOf(charge.take.slice(through), ZERO));\n program.push(new Map(level), \"<=\", leastOf(charge.fill.slice(through), ZERO));\n }\n }\n return { pairs, gifts, segments };\n}\n\n/**\n * This function gives the most charge, the earliest first, as an objective (M2-solar-charge-sweep). The weight of the charge of\n * a segment is the days from its start to the horizon. Thus the store keeps the highest level that it can for the lower draws.\n */\nfunction mostCharge(plan: SeasonPlan, charges: Charges, count: number): Objective {\n const most: Row = new Map();\n const horizon = edgeOf(plan, segmentsOf(plan));\n for (const rows of charges.segments.values()) {\n rows.forEach((row, segment) => {\n for (const [column, value] of row) addTo(most, column, mul(value, sub(horizon, edgeOf(plan, segment))));\n });\n }\n return { sense: \"max\", coefficients: dense(most, count) };\n}\n\n/**\n * This function gives the rest of each store with a capacity in each segment (M2-solar-charge-sweep). It is the rest that the\n * draws of a plan and the higher draws leave. The takes and the charges of the plan come out of the rest that the plan got.\n */\nfunction restsOf(plan: SeasonPlan, cells: readonly Cell[], x: readonly Rational[], charges: Charges): Map<string, ChargeRest[]> {\n const out = new Map<string, ChargeRest[]>();\n for (const charge of plan.charges) {\n const rows = charges.segments.get(charge.resource) ?? [];\n // The level that the draws of the plan add before the segment.\n let added = ZERO;\n const list: ChargeRest[] = [];\n for (let segment = 0; segment < segmentsOf(plan); segment += 1) {\n let taken = ZERO;\n for (const cell of cells) if (cell.segment === segment) taken = add(taken, x[cell.takes.get(charge.lot) ?? -1] ?? ZERO);\n const row = rows[segment];\n const given = row === undefined ? ZERO : valueAt(row, x);\n const take = add(sub(charge.take[segment] ?? charge.lot.amount, taken), added);\n const fill = sub(sub(charge.fill[segment] ?? ZERO, given), added);\n list.push({ from: plan.edges[segment] ?? 0, to: plan.edges[segment + 1] ?? 0, take, fill });\n added = add(added, sub(given, taken));\n }\n out.set(charge.resource, list);\n }\n return out;\n}\n\n/**\n * This function gives the most device-days of one day that the charges of a plan use, by the key of the device (M2-solar-charge-sweep).\n * The value comes before the shares `monthly`. The charge of a segment can come in equal parts on each of its days.\n */\nfunction chargeDaysOf(plan: SeasonPlan, charges: Charges, x: readonly Rational[]): Map<string, number> {\n const out = new Map<string, number>();\n for (const [segment, list] of charges.pairs) {\n const length = toNumber(lengthOf(plan, segment));\n if (!(length > 0)) continue;\n for (const [key, limit] of deviceUse(list).limits) {\n const share = shareIn(plan, segment, key);\n if (share > 0) out.set(key, Math.max(out.get(key) ?? 0, toNumber(valueAt(limit.row, x)) / length / share));\n }\n }\n return out;\n}\n\n/**\n * This function adds the cells of the fixed draws. Each one is fed to its first stop, and its runs use the device-days of each day\n * that it keeps. It gives the device-days of each day that the fixed draws keep, by the index of the segment, then the key.\n */\nfunction addFixed(program: Program, plan: SeasonPlan, fixed: ReadonlyMap<string, FixedStop>, cells: Cell[]): Map<number, Map<string, Rational>> {\n const kept = new Map<number, Map<string, Rational>>();\n for (const draw of plan.draws) {\n const fix = fixed.get(draw.need);\n if (fix === undefined) continue;\n for (let segment = 0; segment <= fix.segment; segment += 1) {\n const fed = fixedFed(plan, fix, segment);\n const keep = fix.keep.get(segment) ?? new Map<string, Rational>();\n // The draw keeps its device-days of each day for the whole segment. This is the safe side, as in `bestEndurance`.\n const into = kept.get(segment) ?? new Map<string, Rational>();\n kept.set(segment, into);\n for (const [key, value] of keep) into.set(key, add(into.get(key) ?? ZERO, value));\n if (sign(fed) <= 0) continue;\n const cell = addCell(program, plan, draw, segment, fed);\n cells.push(cell);\n const { limits, stopped } = deviceUse(cell.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(keep.get(key) ?? ZERO, fed));\n }\n }\n return kept;\n}\n\n/** The share of the device-days of a key in a segment (M2-solar): its share `monthly` in the month of the segment, or 1. */\nfunction shareIn(plan: SeasonPlan, segment: number, key: string): number {\n return shareOf(plan.shares, key, plan.months[segment] ?? 0);\n}\n\n/** This function gives the device-days of each day that the fixed draws leave in a segment: the devices times the share, less the kept device-days. */\nfunction roomOf(plan: SeasonPlan, kept: ReadonlyMap<number, ReadonlyMap<string, Rational>>, segment: number, key: string, devices: number): Rational {\n const left = sub(mul(exact(plan.devices.get(key) ?? devices), exact(shareIn(plan, segment, key))), kept.get(segment)?.get(key) ?? ZERO);\n return sign(left) > 0 ? left : ZERO;\n}\n\n/**\n * This function gives the program of one step with the stop of the open draws in segment `segment`. The open draws are fed in\n * each segment before it. In it, each one is fed for `t - edge` days or more, and their runs share the device-days that\n * the fixed draws leave, for `t - edge` days. This is the safe side, as in `bestEndurance`.\n */\nfunction buildStep(plan: SeasonPlan, fixed: ReadonlyMap<string, FixedStop>, open: readonly Draw[], segment: number): Step {\n const program = new Program();\n const t = program.next();\n program.push(new Map([[t, ONE]]), \"<=\", edgeOf(plan, segment + 1));\n const cells: Cell[] = [];\n const kept = addFixed(program, plan, fixed, cells);\n const opened = new Set(open.map((draw) => draw.need));\n const floors = new Map<string, number>();\n for (const draw of plan.draws) {\n if (!opened.has(draw.need)) continue;\n for (let index = 0; index < segment; index += 1) cells.push(addCell(program, plan, draw, index, lengthOf(plan, index)));\n const fed = program.next();\n program.push(new Map([[fed, ONE]]), \"<=\", lengthOf(plan, segment));\n floors.set(draw.need, program.push(new Map([[fed, ONE], [t, neg(ONE)]]), \">=\", neg(edgeOf(plan, segment))));\n cells.push(addCell(program, plan, draw, segment, fed));\n }\n const charges = addCharges(program, plan, cells, segment + 1);\n const shared = new Map<number, Map<string, Shared>>();\n for (let index = 0; index <= segment; index += 1) {\n const runs = cells.filter((cell) => cell.segment === index && opened.has(cell.draw.need)).flatMap((cell) => [...cell.block.runs]);\n const { limits, stopped } = deviceUse([...runs, ...(charges.pairs.get(index) ?? [])]);\n for (const column of stopped) program.push(new Map([[column, ONE]]), \"<=\", ZERO);\n const bySegment = new Map<string, Shared>();\n shared.set(index, bySegment);\n for (const [key, limit] of limits) {\n const room = roomOf(plan, kept, index, key, limit.devices);\n bySegment.set(key, { row: limit.row, room, converters: limit.converters });\n const row: Row = new Map(limit.row);\n if (index < segment) program.push(row, \"<=\", mul(room, lengthOf(plan, index)));\n else {\n addTo(row, t, neg(room));\n program.push(row, \"<=\", neg(mul(room, edgeOf(plan, segment))));\n }\n }\n }\n lotRows(program, plan, cells);\n return { program, t, cells, floors, shared, segment, charges };\n}\n\n/** The first stop of a set of open draws: the step, its solution and the days. */\nexport interface Stop {\n readonly step: Step;\n readonly x: readonly Rational[];\n /** The dual value of each row of the first objective. */\n readonly dual: readonly Rational[];\n readonly days: Rational;\n readonly atHorizon: boolean;\n}\n\n/**\n * This function gives the largest common first stop of the open draws, with the fixed draws at their stops. The days to\n * a first stop are not a linear function of the takes, so the function tries the segments in order. When the days reach\n * the end of a segment, it tries the next segment. The days of the last step are exact.\n * After the largest days, the step takes the objectives of `tail`.\n */\nexport function firstStop(plan: SeasonPlan, fixed: ReadonlyMap<string, FixedStop>, open: readonly Draw[], tail: (step: Step) => Objective[] = () => []): Stop {\n const segments = segmentsOf(plan);\n for (let segment = 0; segment < segments; segment += 1) {\n const step = buildStep(plan, fixed, open, segment);\n const most: Objective = { sense: \"max\", coefficients: dense(new Map([[step.t, ONE]]), step.program.count) };\n const solved = solveLexicographic(step.program.constraints(), [most]);\n if (solved.status !== \"optimal\") throw new Error(\"The step of a season has no optimum. The point of the stop of the last segment is a point of it.\");\n const days = solved.values[0] ?? ZERO;\n const end = edgeOf(plan, segment + 1);\n if (segment + 1 < segments && equals(days, end)) continue;\n // The later objectives keep the days of the first objective as a row. This is the row that solveLexicographic adds, thus\n // the program does not solve the first objective again (M2-sweep-speed).\n // With two later objectives, the second one starts from the optimal basis of the first one (M2-linear-warm-start).\n const later = tail(step);\n const full = later.length === 0 ? solved : solveLexicographic([...step.program.constraints(), { coefficients: most.coefficients, relation: \"=\", rhs: days }], later, { warm: true });\n if (full.status !== \"optimal\") throw new Error(\"The step of a season has no optimum for its later objectives.\");\n const first = solved.stages[0]?.result;\n return { step, x: full.x, dual: first?.status === \"optimal\" ? first.dual : [], days, atHorizon: segment + 1 === segments && equals(days, end) };\n }\n throw new Error(\"A season plan has no segment.\");\n}\n\n/** This function gives the fewest device-days of the runs of the open cells of a step, as an objective. */\nexport function fewestOpen(step: Step, open: ReadonlySet<string>): Objective {\n return { sense: \"min\", coefficients: dense(fewestRow(step.cells.filter((cell) => open.has(cell.draw.need)).flatMap((cell) => [...cell.block.runs])), step.program.count) };\n}\n\n/** This function gives the smallest sum of the shares of the stocks, each over the total of its lots, as an objective. */\nexport function leastShares(plan: SeasonPlan, cells: readonly Cell[], count: number): Objective {\n const least: Row = new Map();\n // The stock of an empty store with a charge is 0 (M2-solar-charge). Its weight is 1.\n const weight = (resource: string): Rational => div(ONE, exact((plan.parts.stock.get(resource) ?? 0) > 0 ? (plan.parts.stock.get(resource) as number) : 1));\n for (const cell of cells) for (const [resource, index] of cell.block.shares) addTo(least, index, weight(resource));\n return { sense: \"min\", coefficients: dense(least, count) };\n}\n\n/** This function fixes the open draws of `done` at the stop: the device-days of each day that they keep, and their capped converters. */\nexport function fixStops(plan: SeasonPlan, stop: Stop, done: readonly Draw[], fixed: Map<string, FixedStop>): void {\n const { step, x, days } = stop;\n const fedIn = (segment: number): Rational => (segment < step.segment ? lengthOf(plan, segment) : sub(days, edgeOf(plan, step.segment)));\n const full = new Set<string>();\n for (const [segment, bySegment] of step.shared) {\n for (const [key, limit] of bySegment) if (equals(valueAt(limit.row, x), mul(limit.room, fedIn(segment)))) full.add(`${String(segment)}\\u0000${key}`);\n }\n for (const draw of done) {\n const keep = new Map<number, Map<string, Rational>>();\n const used = new Set<Converter>();\n for (const cell of step.cells) {\n if (cell.draw.need !== draw.need) continue;\n const fed = fedIn(cell.segment);\n const bySegment = new Map<string, Rational>();\n keep.set(cell.segment, bySegment);\n for (const [key, limit] of deviceUse(cell.block.runs).limits) {\n bySegment.set(key, sign(fed) > 0 ? div(valueAt(limit.row, x), fed) : ZERO);\n if (full.has(`${String(cell.segment)}\\u0000${key}`)) for (const converter of limit.converters) used.add(converter);\n }\n }\n const { reach } = reachOf(plan.parts, new Set([draw.need]));\n const capped = sign(days) > 0 && !stop.atHorizon\n ? [...reach].filter((converter) => converter.perDay !== undefined && (!(converter.perDay > 0) || used.has(converter))).map((converter) => converter.id).sort()\n : [];\n fixed.set(draw.need, { stop: days, segment: step.segment, keep, atHorizon: stop.atHorizon, capped });\n }\n}\n\n/** This function gives the sum of the take of each resource of the cells of one need, more than 0 only. */\nfunction takesOf(cells: readonly Cell[], need: string, x: readonly Rational[]): Record<string, number> {\n const sums = new Map<string, Rational>();\n for (const cell of cells) {\n if (cell.draw.need !== need) continue;\n for (const [resource, index] of cell.block.shares) sums.set(resource, add(sums.get(resource) ?? ZERO, x[index] ?? ZERO));\n }\n const out: Record<string, number> = {};\n for (const [resource, value] of [...sums].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) if (sign(value) > 0) out[resource] = toNumber(value);\n return out;\n}\n\n/** This function gives the resources of `closure` with a store in the layer whose lots are used up at `x`. They are in the order of their codes. */\nexport function usedUp(plan: SeasonPlan, cells: readonly Cell[], x: readonly Rational[], closure: ReadonlySet<string>, stored: ReadonlySet<string>, charges?: Charges): string[] {\n return [...closure]\n .filter((resource) => stored.has(resource))\n .filter((resource) => {\n let taken = ZERO;\n // The charges of a store with a capacity add to its lots (M2-solar-charge).\n const given = charges?.gifts.get(resource);\n let amount = given === undefined ? ZERO : valueAt(given, x);\n for (const lot of plan.lots) {\n if (lot.resource !== resource) continue;\n amount = add(amount, lot.amount);\n for (const cell of cells) taken = add(taken, x[cell.takes.get(lot) ?? -1] ?? ZERO);\n }\n return equals(taken, amount);\n })\n .sort();\n}\n\n/** This function tells if the cells of two draws or more of `cells` can use the limited device `key`. */\nfunction sharedKey(cells: readonly Cell[], key: string): boolean {\n return new Set(cells.filter((cell) => deviceUse(cell.block.runs).limits.has(key)).map((cell) => cell.draw.need)).size > 1;\n}\n\n/** The result of the last program of the best endurance with a season. */\nexport interface SeasonBest {\n readonly needs: Record<string, DrawEndurance>;\n /** The take of each lot by all the draws. */\n readonly taken: ReadonlyMap<PlanLot, number>;\n /** The most device-days of one day that each draw uses while it is fed, by the code of its need, then the key of the device. */\n readonly perDay: ReadonlyMap<string, ReadonlyMap<string, number>>;\n /** With `fill`, the rest of each store with a capacity that the plan leaves in each segment (M2-solar-charge-sweep). */\n readonly rests?: ReadonlyMap<string, readonly ChargeRest[]> | undefined;\n /** With `fill`, the most device-days of one day that the charges use, by the key of the device, before the shares `monthly`. */\n readonly chargeDays?: ReadonlyMap<string, number> | undefined;\n}\n\n/**\n * This function gives the last program of the best endurance with a season. Each draw keeps its first stop. After it, a later\n * harvest can feed the draw again (`again`). The objectives come in this order:\n * - the most fed days after the stops for each level, in the order of the levels.\n * - the earliest fed days.\n * - the smallest sum of the shares of the stocks.\n * - the fewest device-days.\n *\n * In a segment after the stops, the cells of two draws or more that can use one limited device take turns. Their fed days\n * together are not more than the segment, and each one has the device-days of each day that the stops leave. This is the\n * safe side: the cells do not use one device at the same time. Each other cell starts at the start of the segment.\n *\n * @param fill - True for the sweep of `enduranceOf` (M2-solar-charge-sweep). Then the last objective is the most charge, the\n * earliest first, and the result gives the rest of each store with a capacity. A store with a capacity is binding if the\n * takes of the segment of the stop use all the level at its start.\n */\nexport function seasonBest(plan: SeasonPlan, fixed: ReadonlyMap<string, FixedStop>, levels: readonly (readonly Draw[])[], stored: ReadonlySet<string>, fill = false): SeasonBest {\n const program = new Program();\n const cells: Cell[] = [];\n const kept = addFixed(program, plan, fixed, cells);\n const segments = segmentsOf(plan);\n const again = new Map<Cell, number>();\n // The cells that take turns in their segment.\n const taking = new Set<Cell>();\n for (const draw of plan.draws) {\n const fix = fixed.get(draw.need) as FixedStop;\n for (let segment = fix.segment + 1; segment < segments; segment += 1) {\n const fed = program.next();\n program.push(new Map([[fed, ONE]]), \"<=\", lengthOf(plan, segment));\n const cell = addCell(program, plan, draw, segment, fed);\n cells.push(cell);\n again.set(cell, fed);\n }\n }\n for (let segment = 0; segment < segments; segment += 1) {\n const later = [...again.keys()].filter((cell) => cell.segment === segment);\n const { limits, stopped } = deviceUse(later.flatMap((cell) => [...cell.block.runs]));\n for (const column of stopped) program.push(new Map([[column, ONE]]), \"<=\", ZERO);\n const turns = new Set(later.filter((cell) => [...deviceUse(cell.block.runs).limits.keys()].some((key) => sharedKey(later, key))));\n if (turns.size > 0) {\n const row: Row = new Map();\n for (const cell of turns) addTo(row, again.get(cell) as number, ONE);\n program.push(row, \"<=\", lengthOf(plan, segment));\n for (const cell of turns) taking.add(cell);\n }\n for (const [key, limit] of limits) {\n const room = roomOf(plan, kept, segment, key, limit.devices);\n for (const cell of later) {\n const own = deviceUse(cell.block.runs).limits.get(key);\n if (own === undefined) continue;\n const row: Row = new Map(own.row);\n addTo(row, again.get(cell) as number, neg(room));\n program.push(row, \"<=\", ZERO);\n }\n }\n }\n // The charge of each segment uses the device-days that the cells after the stops leave (M2-solar-charge).\n const charges = addCharges(program, plan, cells, segments);\n for (const [segment, list] of charges.pairs) {\n const later = [...again.keys()].filter((cell) => cell.segment === segment);\n const { limits } = deviceUse([...later.flatMap((cell) => [...cell.block.runs]), ...list]);\n const keys = new Set(list.map(([source]) => deviceKey(source)));\n for (const [key, limit] of limits) if (keys.has(key)) program.push(limit.row, \"<=\", mul(roomOf(plan, kept, segment, key, limit.devices), lengthOf(plan, segment)));\n }\n lotRows(program, plan, cells);\n const objectives: Objective[] = levels.map((level) => {\n const needs = new Set(level.map((draw) => draw.need));\n const row: Row = new Map();\n for (const [cell, fed] of again) if (needs.has(cell.draw.need)) addTo(row, fed, ONE);\n return { sense: \"max\", coefficients: dense(row, program.count) };\n });\n // After the fed days of each level, the fed days come as early as they can: the weight of a segment is the days from its start to the horizon.\n const early: Row = new Map();\n const horizon = edgeOf(plan, segments);\n for (const [cell, fed] of again) addTo(early, fed, sub(horizon, edgeOf(plan, cell.segment)));\n objectives.push({ sense: \"max\", coefficients: dense(early, program.count) });\n objectives.push(leastShares(plan, cells, program.count));\n objectives.push({ sense: \"min\", coefficients: dense(fewestRow(cells.flatMap((cell) => [...cell.block.runs])), program.count) });\n if (fill) objectives.push(mostCharge(plan, charges, program.count));\n // Each later stage starts from the optimal basis of the stage before it (M2-linear-warm-start). This program has the most stages.\n const solved = solveLexicographic(program.constraints(), objectives, { warm: true });\n if (solved.status !== \"optimal\") throw new Error(\"The last program of the best endurance with a season has no optimum. The point of the last step is a point of it.\");\n const x = solved.x;\n const rests = fill ? restsOf(plan, cells, x, charges) : undefined;\n // In the sweep, a store with a capacity is binding if the takes of the segment of the stop use all the level at its start.\n const charged = new Set(plan.charges.map((charge) => charge.resource));\n const bound = (closure: ReadonlySet<string>, segment: number): string[] => {\n const used = usedUp(plan, cells, x, closure, stored, charges);\n if (rests === undefined) return used;\n const empty = [...charged].filter((resource) => closure.has(resource) && stored.has(resource) && sign(rests.get(resource)?.[segment]?.take ?? ONE) <= 0);\n return [...used.filter((resource) => !charged.has(resource)), ...empty].sort();\n };\n // The start of the turn of each cell that takes turns: after the turns of the cells of the draws before it.\n const turn = new Map<Cell, Rational>();\n const offset = new Map<number, Rational>();\n for (const cell of [...taking].sort((a, b) => plan.draws.indexOf(a.draw) - plan.draws.indexOf(b.draw))) {\n const start = offset.get(cell.segment) ?? ZERO;\n turn.set(cell, start);\n offset.set(cell.segment, add(start, x[again.get(cell) as number] ?? ZERO));\n }\n const needs: Record<string, DrawEndurance> = {};\n for (const draw of plan.draws) {\n const fix = fixed.get(draw.need) as FixedStop;\n const spans: { from: number; to: number }[] = [];\n for (const [cell, fed] of again) {\n if (cell.draw.need !== draw.need) continue;\n const value = x[fed] ?? ZERO;\n if (sign(value) <= 0) continue;\n const start = add(edgeOf(plan, cell.segment), taking.has(cell) ? (turn.get(cell) ?? ZERO) : ZERO);\n const from = toNumber(start);\n const to = toNumber(add(start, value));\n const last = spans[spans.length - 1];\n if (last !== undefined && last.to === from) last.to = to;\n else spans.push({ from, to });\n }\n const { closure } = reachOf(plan.parts, new Set([draw.need]));\n needs[draw.need] = {\n days: toNumber(fix.stop),\n binding: fix.atHorizon ? [] : bound(closure, fix.segment),\n takes: takesOf(cells, draw.need, x),\n ...(fix.capped.length === 0 ? {} : { capped: fix.capped }),\n ...(fix.atHorizon ? { atHorizon: true as const } : {}),\n ...(spans.length === 0 ? {} : { again: spans }),\n };\n }\n const taken = new Map<PlanLot, number>();\n for (const lot of plan.lots) {\n let sum = ZERO;\n for (const cell of cells) sum = add(sum, x[cell.takes.get(lot) ?? -1] ?? ZERO);\n taken.set(lot, toNumber(sum));\n }\n const perDay = new Map<string, Map<string, number>>();\n for (const cell of cells) {\n const fed = typeof cell.fed === \"number\" ? (x[cell.fed] ?? ZERO) : cell.fed;\n if (sign(fed) <= 0) continue;\n const into = perDay.get(cell.draw.need) ?? new Map<string, number>();\n perDay.set(cell.draw.need, into);\n // The use of a segment counts as its part of the share of the segment, as in `enduranceOf` (M2-solar).\n for (const [key, limit] of deviceUse(cell.block.runs).limits) {\n const share = shareIn(plan, cell.segment, key);\n if (share > 0) into.set(key, Math.max(into.get(key) ?? 0, toNumber(div(valueAt(limit.row, x), fed)) / share));\n }\n }\n return { needs, taken, perDay, rests, chargeDays: fill ? chargeDaysOf(plan, charges, x) : undefined };\n}\n\n/** The joint days of a set of draws with a season, before the change to the record of `jointDays`. */\nexport interface SeasonJoint {\n readonly days: number;\n readonly atHorizon: boolean;\n readonly takes: Record<string, Record<string, number>>;\n readonly binding: string[];\n readonly runs: Record<string, number>;\n readonly capped: string[];\n}\n\n/**\n * This function gives the joint days of the draws of a plan with a season. The objectives come in this order:\n * - the largest common first stop.\n * - the smallest sum of the shares of the stocks.\n * - the fewest device-days.\n */\nexport function seasonJoint(plan: SeasonPlan, stored: ReadonlySet<string>): SeasonJoint {\n const open = new Set(plan.draws.map((draw) => draw.need));\n const stop = firstStop(plan, new Map(), plan.draws, (step) => [leastShares(plan, step.cells, step.program.count), fewestOpen(step, open)]);\n const { step, x } = stop;\n const takes: Record<string, Record<string, number>> = {};\n for (const draw of plan.draws) takes[draw.need] = takesOf(step.cells, draw.need, x);\n const total = new Map<Converter, Rational>();\n for (const cell of step.cells) for (const [converter, index] of cell.block.runs) total.set(converter, add(total.get(converter) ?? ZERO, x[index] ?? ZERO));\n const runs: Record<string, number> = {};\n for (const [converter, value] of [...total].sort(([a], [b]) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))) if (sign(value) > 0) runs[converter.id] = toNumber(value);\n const fixed = new Map<string, FixedStop>();\n fixStops(plan, stop, plan.draws, fixed);\n const capped = [...new Set([...fixed.values()].flatMap((fix) => fix.capped))].sort();\n return { days: toNumber(stop.days), atHorizon: stop.atHorizon, takes, binding: usedUp(plan, step.cells, x, reachOf(plan.parts, open).closure, stored, step.charges), runs, capped };\n}\n\n/** The endurance of one draw with a season and a shared device, and the supply that it leaves to the lower draws. */\nexport interface SeasonDraw {\n readonly need: DrawEndurance;\n /** The stocks that the draw leaves, by the code of the resource. */\n readonly stock: Map<string, number>;\n /** The rest of each harvest lot of the input, in the same order. */\n readonly lots: number[];\n /** The most device-days of one day that the draw uses while it is fed, by the key of the device. With a charge, it includes the device-days of the charge. */\n readonly perDay: ReadonlyMap<string, number>;\n /** The rest of each store with a capacity that the draw and the higher draws leave (M2-solar-charge-sweep). */\n readonly rests: ReadonlyMap<string, readonly ChargeRest[]>;\n}\n\n/**\n * This function gives the endurance of one draw of `enduranceOf` that reaches two limited converters of one device in a layer\n * with a season (M2-grow-share-sweep). The take order cannot give the share of the device-days.\n * Thus the programs of `bestEndurance` give it for this one draw: the first stop, then the most fed days after it (`again`).\n *\n * The function also gives the endurance of a draw that can take a store with a capacity that a source charges (M2-solar-charge-sweep).\n * - The takes of the store come from the rest that the higher draws leave (`rests`). Thus the takes and the charges of the higher draws stay possible.\n * - The first stop takes the fewest stocks, thus the draw keeps the most runs of a source and the most level for the lower draws.\n * - The last program charges the store as much as it can, the earliest first. The draw gives the rest that it leaves to the lower draws.\n * - The device-days of the charge are a part of the device-days of the draw (`perDay`). Thus a lower draw cannot use them.\n *\n * @param stock - The stocks that the higher draws leave. The stock of a store with a charge is its amount on day 0, because the rest gives the takes of the higher draws.\n * @param lots - The rest of each harvest lot that the higher draws leave.\n * @param room - The device-days of each day that the higher draws leave, by the key of the device, before the shares `monthly`.\n * @param start - The first day of the event, for the months of the shares.\n * @param capacities - The capacity of each resource whose stores have a capacity (`storeCapacities`).\n * @param rests - The rest of each store with a capacity that the higher draws leave. With no rest, the store has its amount and its capacity.\n */\nexport function seasonDraw(\n layer: EnduranceLayer,\n stoppedParts: ReadonlySet<string>,\n caseCuts: CaseCuts,\n draw: Draw,\n stock: ReadonlyMap<string, number>,\n lots: readonly HarvestLot[],\n horizon: number,\n room: ReadonlyMap<string, number>,\n start: IsoDate,\n capacities: ReadonlyMap<string, number> = new Map(),\n rests: ReadonlyMap<string, readonly ChargeRest[]> = new Map(),\n): SeasonDraw {\n const supply: SeasonSupply = { stock: new Map(stock), harvests: [], lots, horizon, start };\n const plan = seasonPlan(supply, caseParts(layer, stoppedParts, supply.stock, new Set([draw.need])), caseCuts, [draw], room, capacities, rests);\n const fixed = new Map<string, FixedStop>();\n const open = new Set([draw.need]);\n const filled = plan.charges.length > 0;\n const tail = (step: Step): Objective[] => (filled ? [leastShares(plan, step.cells, step.program.count), fewestOpen(step, open)] : [fewestOpen(step, open)]);\n fixStops(plan, firstStop(plan, fixed, [draw], tail), [draw], fixed);\n const best = seasonBest(plan, fixed, [[draw]], new Set(layer.stores.map((store) => store.resource)), filled);\n const left = new Map(stock);\n const rest = lots.map((lot) => lot.amount);\n // The rest gives the level of a store with a charge to the lower draws, thus its stock does not change.\n const chargedLots = new Set(plan.charges.map((charge) => charge.lot));\n for (const [lot, amount] of best.taken) {\n if (chargedLots.has(lot)) continue;\n if (lot.origin === undefined) left.set(lot.resource, Math.max(0, (left.get(lot.resource) ?? 0) - amount));\n else rest[lot.origin] = Math.max(0, (rest[lot.origin] ?? 0) - amount);\n }\n const perDay = new Map<string, number>(best.perDay.get(draw.need) ?? []);\n for (const [key, each] of best.chargeDays ?? new Map<string, number>()) perDay.set(key, (perDay.get(key) ?? 0) + each);\n return { need: best.needs[draw.need] as DrawEndurance, stock: left, lots: rest, perDay, rests: best.rests ?? new Map<string, readonly ChargeRest[]>() };\n}\n","import { type Objective, solveLexicographic } from \"@mark1russell7/linear\";\nimport { div, neg, ONE, type Rational, sign, toNumber, ZERO } from \"@mark1russell7/rational\";\nimport type { Converter, DirectUse, Draw } from \"./layer.ts\";\nimport { deviceUse, drawBlock, fewestRow, partsOf, Program, valueAt } from \"./program.ts\";\nimport { addTo, dense, exact, type Row } from \"./rows.ts\";\n\n// The best share of one draw: a linear program over the totals of its days, with exact rationals (@mark1russell7/linear).\n// The endurance query uses it for a draw whose converters share the days of a device. The root entry does not give it.\n// The columns and rows come from program.ts, as for the joint days and the best endurance.\n\n/** The input of the best share of one draw. */\nexport interface ShareInput {\n /** The draw. */\n readonly draw: Draw;\n /** The stock of each resource that the draw can take, by the code of the resource. */\n readonly stock: ReadonlyMap<string, number>;\n /** The device-days of each day that the draw can use, by the key of the device (`deviceKey`). */\n readonly room: ReadonlyMap<string, number>;\n /** The direct uses that give the need of the draw. */\n readonly direct: readonly DirectUse[];\n /** The converters that give the need of the draw. */\n readonly converters: readonly Converter[];\n /** The makers that the draw can use: the makers of its inputs, through each chain. */\n readonly makers: readonly Converter[];\n /** The amount of the need for each day. It is more than 0. */\n readonly demand: number;\n}\n\n/** The best share of one draw: its days, the take of each stock and the device-days of each device. */\nexport interface Share {\n /** The largest count of days at which the draw gets its demand. */\n readonly days: number;\n /** The amount of each resource that the draw takes from the stock. A resource with no take is not in the map. */\n readonly taken: ReadonlyMap<string, number>;\n /** The device-days that the runs use in `days`, by the key of the device. A device with no use is not in the map. */\n readonly used: ReadonlyMap<string, number>;\n}\n\n/**\n * This function gives the best share of the stocks and of the device-days for one draw.\n * It gives `undefined` when the program has no optimum.\n *\n * - The variables are the days `T`, the take of each direct use, the runs of each converter and maker, and the take of each stock.\n * - The gifts of the direct uses and of the converters are not less than `T` times the demand.\n * - The takes of each resource are not more than the take of its stock plus the gifts of its makers. The take of a stock is not more than the stock.\n * - The runs of the converters of one device use `room` times `T` device-days or less. One run uses `1 / perDay` of a device-day. A limit of 0 stops the converter.\n * - The first objective takes the largest `T`. The second takes the smallest sum of the takes of the stocks, each over its stock. The third takes the fewest device-days.\n *\n * The gifts at `T` days are a concave function of `T`, and they are 0 at 0. Thus each count of days up to the largest `T` also fits.\n *\n * @param input - The draw, the stocks, the device-days of each day, the ways of the draw and its demand\n * @returns The days, the takes of the stocks and the device-days of each device\n */\nexport function bestShare(input: ShareInput): Share | undefined {\n const parts = partsOf(input.stock, input.direct, input.converters, input.makers);\n const program = new Program();\n const days = program.next();\n const block = drawBlock(program, parts, input.draw);\n // The need: the gifts are not less than the demand times the days.\n const need: Row = new Map(block.gifts);\n addTo(need, days, neg(exact(input.demand)));\n program.push(need, \">=\", ZERO);\n // The take of each stock is not more than the stock.\n for (const [resource, index] of block.shares) program.push(new Map([[index, ONE]]), \"<=\", exact(input.stock.get(resource) ?? 0));\n // The limit of each device: the runs use `room` times `T` device-days or less. The converters of one device share one limit.\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) {\n const row: Row = new Map(limit.row);\n addTo(row, days, neg(exact(input.room.get(key) ?? 0)));\n program.push(row, \"<=\", ZERO);\n }\n\n const least: Row = new Map();\n for (const [resource, index] of block.shares) addTo(least, index, div(ONE, exact(input.stock.get(resource) ?? 1)));\n const objectives: Objective[] = [\n { sense: \"max\", coefficients: dense(new Map([[days, ONE]]), program.count) },\n { sense: \"min\", coefficients: dense(least, program.count) },\n { sense: \"min\", coefficients: dense(fewestRow(block.runs), program.count) },\n ];\n // Each later stage starts from the optimal basis of the stage before it (M2-linear-warm-start). The program has one draw.\n const solved = solveLexicographic(program.constraints(), objectives, { warm: true });\n // The point 0 is feasible, and the later objectives are not less than 0. Thus only an unbounded first stage has no optimum.\n if (solved.status !== \"optimal\") return undefined;\n\n const at = (index: number): Rational => solved.x[index] ?? ZERO;\n const taken = new Map<string, number>();\n for (const [resource, index] of block.shares) if (sign(at(index)) > 0) taken.set(resource, toNumber(at(index)));\n const used = new Map<string, number>();\n for (const [key, limit] of limits) {\n const sum = valueAt(limit.row, solved.x);\n if (sign(sum) > 0) used.set(key, toNumber(sum));\n }\n return { days: toNumber(at(days)), taken, used };\n}\n","import { dayNumber, stopped, type Stack } from \"@mark1russell7/system-stack\";\nimport { canRun, deviceKey, inputsOf, isSource } from \"./converter.ts\";\nimport { largestFit, type Try } from \"./fit.ts\";\nimport type { CaseCuts, Converter, DirectUse, Draw, DrawEndurance, Endurance, EnduranceLayer, Harvest, IsoDate, Season } from \"./layer.ts\";\nimport { inputClosure as closureOf } from \"./program.ts\";\nimport { type ChargeRest, seasonDraw, storeCapacities } from \"./seasonal.ts\";\nimport { bestShare } from \"./share.ts\";\n\n// The endurance query: the days that each draw holds when a case stops its supply.\n\n/** The options of the queries of a case. */\nexport interface CaseOptions {\n /** The date of the query. A store whose due date is on this date or before it gives nothing. */\n readonly at: IsoDate;\n /** The base stack. With it, a cut also stops each part that cannot work without a cut part (`stopped` of the core). */\n readonly stack?: Stack | undefined;\n /** The `id` of more parts that are down, with the cuts of the case. */\n readonly down?: readonly string[] | undefined;\n /**\n * The first day of the event, for the sow days of each converter with a season (M2-grow) and the months of the shares\n * `monthly` (M2-solar). The default is `at`. The\n * stores are the stores at `at`. Thus a query can move the event in the year and keep the stores.\n */\n readonly start?: IsoDate | undefined;\n /**\n * The horizon in days, more than 0. A layer with no converter with a season, shares `monthly` or a source does not use\n * it in `enduranceOf`. With such a converter, the query reads the sowings up to the horizon, and a draw holds the horizon at most. The default\n * is `SEASON_HORIZON_DAYS`.\n */\n readonly horizon?: number | undefined;\n}\n\n/** The default horizon of a layer with a converter with a season: 730 days, thus two seasons of each year. */\nexport const SEASON_HORIZON_DAYS = 730;\n\n/**\n * This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.\n * With a stack, it also gives each part that stops.\n */\nexport function caseStopped(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): Set<string> {\n const down = [...caseCuts.cuts.map((cut) => cut.part), ...(options.down ?? [])];\n const out = new Set(down);\n if (options.stack !== undefined) for (const id of stopped(options.stack, down)) out.add(id);\n return out;\n}\n\n/** This function gives the day number of a date, or throws a `RangeError` for a date that is not `YYYY-MM-DD`. */\nfunction dayOf(date: IsoDate): number {\n const day = dayNumber(date);\n if (day === undefined) throw new RangeError(`The date \"${date}\" is not a date YYYY-MM-DD.`);\n return day;\n}\n\nconst DAY_MS = 86_400_000;\n\n/** This function gives the month of the day `day` after the start, 0 for January (M2-solar). It throws a `RangeError` for a bad date. */\nexport function monthOf(start: IsoDate, day: number): number {\n dayOf(start);\n return new Date(Date.parse(`${start}T00:00:00Z`) + Math.floor(day) * DAY_MS).getUTCMonth();\n}\n\n/**\n * This function gives the days from the start to the first day of each month, in increasing order (M2-solar). Each\n * day is more than 0 and less than the horizon. It throws a `RangeError` for a date that is not `YYYY-MM-DD`.\n */\nexport function monthEdges(start: IsoDate, horizon: number): number[] {\n dayOf(start);\n const first = Date.parse(`${start}T00:00:00Z`);\n const date = new Date(first);\n const out: number[] = [];\n for (let month = date.getUTCMonth() + 1; ; month += 1) {\n const day = Math.round((Date.UTC(date.getUTCFullYear(), month, 1) - first) / DAY_MS);\n if (!(day < horizon)) break;\n out.push(day);\n }\n return out;\n}\n\n/** This function gives the shares `monthly` of each device key of the converters with a limit and shares (M2-solar). */\nexport function monthlyShares(converters: Iterable<Converter>): Map<string, readonly number[]> {\n const out = new Map<string, readonly number[]>();\n for (const converter of converters) if (converter.monthly !== undefined && converter.perDay !== undefined) out.set(deviceKey(converter), converter.monthly);\n return out;\n}\n\n/** This function gives the share of the device-days of a key in a month: its share `monthly`, or 1. */\nexport function shareOf(shares: ReadonlyMap<string, readonly number[]>, key: string, month: number): number {\n return shares.get(key)?.[month] ?? 1;\n}\n\n// The rule of a source is in converter.ts, with canRun. The root entry gives it (M2-solar).\nexport { isSource };\n\n/**\n * This function gives the amount of each resource in the stores at a date, by the code of the resource.\n *\n * - A store gives nothing on its due date and after it.\n * - A store gives nothing when its part is in `stoppedParts`.\n */\nexport function storeAmounts(layer: EnduranceLayer, at: IsoDate, stoppedParts: ReadonlySet<string> = new Set()): Map<string, number> {\n const today = dayOf(at);\n const out = new Map<string, number>();\n for (const store of layer.stores) {\n if (store.due !== undefined && today >= dayOf(store.due)) continue;\n if (store.part !== undefined && stoppedParts.has(store.part)) continue;\n out.set(store.resource, (out.get(store.resource) ?? 0) + store.amount);\n }\n return out;\n}\n\n/** This function gives the amount of a need for each day in a case: the rate of the draw times the factor of the case. */\nexport function drawDemand(draw: Draw, caseCuts: CaseCuts): number {\n return draw.perDay * (caseCuts.factors?.[draw.need] ?? 1);\n}\n\n/**\n * This function gives the draws that take from the stores in a case: each draw whose supply stops, with a demand more than 0.\n * The sequence is by the level (the order of `levels`), then by the code of the need.\n */\nexport function caseDraws(layer: EnduranceLayer, caseCuts: CaseCuts, stoppedParts: ReadonlySet<string>): Draw[] {\n const rank = (level: string): number => {\n const index = layer.levels.indexOf(level);\n return index < 0 ? layer.levels.length : index;\n };\n return layer.draws\n .filter((draw) => stoppedParts.has(draw.supply) && drawDemand(draw, caseCuts) > 0)\n .sort((a, b) => rank(a.level) - rank(b.level) || (a.need < b.need ? -1 : a.need > b.need ? 1 : 0));\n}\n\n/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */\nexport function giftNeed(converter: Converter): string | undefined {\n return \"need\" in converter.gives ? converter.gives.need : undefined;\n}\n\n/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */\nexport function giftResource(converter: Converter): string | undefined {\n return \"resource\" in converter.gives ? converter.gives.resource : undefined;\n}\n\n/** The converters of a case that make each resource, in the order of the layer, by the code of the resource. */\ntype Makers = ReadonlyMap<string, readonly Converter[]>;\n\nfunction makersOf(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): Makers {\n const out = new Map<string, Converter[]>();\n for (const converter of layer.converters ?? []) {\n const resource = giftResource(converter);\n // A converter with a season gives its resource only at its harvests, thus it is not a maker of a take.\n if (resource === undefined || converter.season !== undefined || !canRun(converter, stoppedParts)) continue;\n out.set(resource, [...(out.get(resource) ?? []), converter]);\n }\n return out;\n}\n\n/** The ways to get one need in a case: its direct uses, then the converters that give it, in the order of the layer. `makers` make the resources. */\ninterface Ways {\n readonly direct: readonly DirectUse[];\n readonly converters: readonly Converter[];\n readonly makers: Makers;\n /** The converters that are sources (M2-solar), and the other converters, in the order of the layer. A layer with no source has no cost in the take. */\n readonly sources: readonly Converter[];\n readonly others: readonly Converter[];\n /** The sources of `converters` and of the makers. With one of them, the stock gives no limit to a span. */\n readonly open: readonly Converter[];\n}\n\nfunction waysOf(layer: EnduranceLayer, need: string, stoppedParts: ReadonlySet<string>, makers: Makers): Ways {\n const converters = (layer.converters ?? []).filter((converter) => giftNeed(converter) === need && canRun(converter, stoppedParts));\n const sources = converters.filter(isSource);\n return {\n direct: (layer.direct ?? []).filter((use) => use.need === need && use.amount > 0),\n converters,\n makers,\n sources,\n others: sources.length === 0 ? converters : converters.filter((converter) => !isSource(converter)),\n open: [...new Set([...sources, ...[...makers.values()].flat().filter(isSource)])],\n };\n}\n\n// A chain: the resources on the path of a take. A maker does not take a resource of its own path, so a cycle of the layer stops there.\nconst NO_PATH: ReadonlySet<string> = new Set();\n\n// The device-days that are left to the converters with a limit `perDay` are in the map of the resources, under a key that\n// no code of a resource has. Thus each copy of the map in a try copies them too. The converters of one device share one\n// key (`deviceKey`), and a converter with no device has a key of its own. One run of a converter uses `1 / perDay` of a device-day.\nconst RUNS = \"\\u0000runs:\";\n\nfunction runsKey(converter: Converter): string {\n return RUNS + deviceKey(converter);\n}\n\n/** This function gives the device-days that a converter has left in `left`, or undefined with no limit. */\nfunction daysLeft(left: ReadonlyMap<string, number>, converter: Converter): number | undefined {\n return converter.perDay === undefined ? undefined : left.get(runsKey(converter));\n}\n\n/** This function gives the map with no runs left of the converters: a map of the resources only. */\nfunction resourcesOnly(left: ReadonlyMap<string, number>): Map<string, number> {\n return new Map([...left].filter(([key]) => !key.startsWith(RUNS)));\n}\n\n/**\n * This function gives the most of a resource that `left` gives: its stock, and the runs of each maker.\n * It is an upper limit. When two inputs come from one resource, the true amount can be less.\n */\nfunction mostResource(left: ReadonlyMap<string, number>, makers: Makers, resource: string, path: ReadonlySet<string>): number {\n let total = left.get(resource) ?? 0;\n if (path.has(resource)) return total;\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) total += mostRuns(left, makers, maker, next) * maker.gives.amount;\n return total;\n}\n\n/** This function gives the most runs of a converter that `left` gives. It is an upper limit, as for `mostResource`. */\nfunction mostRuns(left: ReadonlyMap<string, number>, makers: Makers, converter: Converter, path: ReadonlySet<string>): number {\n const limit = daysLeft(left, converter);\n let runs = limit === undefined ? Infinity : limit * (converter.perDay ?? 0);\n for (const [resource, each] of inputsOf(converter)) runs = Math.min(runs, mostResource(left, makers, resource, path) / each);\n return Number.isFinite(runs) ? runs : 0;\n}\n\n/**\n * This function takes an amount of a resource from `left`: the stock first, then the makers in the order of the layer.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction takeResource(left: Map<string, number>, makers: Makers, resource: string, amount: number, path: ReadonlySet<string>): number {\n let rest = amount;\n const ways = path.has(resource) ? undefined : makers.get(resource);\n let next: ReadonlySet<string> | undefined;\n // A source gives first: its runs of a day are lost when no draw uses them (M2-solar).\n if (ways !== undefined && ways.some(isSource)) {\n next = new Set(path).add(resource);\n for (const maker of ways) {\n if (rest <= 0) break;\n if (isSource(maker)) rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;\n }\n }\n const has = left.get(resource) ?? 0;\n const got = Math.min(Math.max(0, rest), has);\n left.set(resource, has - got);\n rest -= got;\n if (rest <= 0 || ways === undefined) return Math.max(0, rest);\n next ??= new Set(path).add(resource);\n for (const maker of ways) {\n if (rest <= 0) break;\n if (!isSource(maker)) rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/**\n * This function runs a converter up to `wanted` times with the resources of `left`, and it gives the count of runs.\n * It changes `left`. When two inputs come from one resource, `largestFit` finds the runs that the resources give.\n */\nfunction run(left: Map<string, number>, makers: Makers, converter: Converter, wanted: number, path: ReadonlySet<string>): number {\n const inputs = inputsOf(converter);\n const most = Math.min(wanted, mostRuns(left, makers, converter, path));\n if (!(most > 0)) return 0;\n const attempt = (runs: number): Try<Map<string, number>> => {\n const copy = new Map(left);\n let need = 0;\n let short = 0;\n // The converter takes its device-days before its inputs. Thus a maker on the same device gets only the rest.\n const limit = daysLeft(copy, converter);\n if (limit !== undefined && converter.perDay !== undefined && converter.perDay > 0) {\n const wanted = runs / converter.perDay;\n const got = Math.min(wanted, limit);\n copy.set(runsKey(converter), limit - got);\n need += runs;\n short += (wanted - got) * converter.perDay;\n }\n for (const [resource, each] of inputs) {\n need += runs * each;\n short += takeResource(copy, makers, resource, runs * each, path);\n }\n return { short, need, value: copy };\n };\n const { x: runs, value: best } = largestFit(most, attempt);\n if (best === undefined) return 0;\n for (const [resource, amount] of best) left.set(resource, amount);\n return runs;\n}\n\n/**\n * This function takes an amount of a need from the resources in `left`: the direct uses first, then the converters.\n * A direct use or a converter takes each resource from its stock first, then from its makers.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction take(left: Map<string, number>, ways: Ways, amount: number): number {\n let rest = amount;\n // A source gives first: its runs of a day are lost when no draw uses them (M2-solar).\n for (const converter of ways.sources) {\n if (rest <= 0) break;\n rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;\n }\n for (const use of ways.direct) {\n if (rest <= 0) break;\n const wanted = rest / use.amount;\n rest -= (wanted - takeResource(left, ways.makers, use.resource, wanted, NO_PATH)) * use.amount;\n }\n for (const converter of ways.others) {\n if (rest <= 0) break;\n rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/** This function gives each resource that a need can use: the inputs of its ways, and the inputs of their makers, through each chain. */\nfunction inputClosure(ways: Ways): Set<string> {\n return closureOf(\n ways.direct.map((use) => use.resource),\n ways.converters,\n [...ways.makers.values()].flat(),\n );\n}\n\n/** The relative tolerance of a used-up resource. */\nconst USED_UP = 1e-9;\n\n/** This function gives the day number of a day `MM-DD` of a year. A day that the year does not have gives undefined. */\nfunction yearDay(year: number, monthDay: string): number | undefined {\n return dayNumber(`${String(year).padStart(4, \"0\")}-${monthDay}`);\n}\n\n/**\n * This function gives the sow days of a season, in days from the start of the event, before the horizon, in increasing\n * order (M2-grow). The sow day of a year is the first day of its window on the start or after it. A window with `from`\n * after `to` goes across the end of the year. A year that does not have a day of the window (`02-29`) has no sowing.\n *\n * @throws RangeError when the start is not `YYYY-MM-DD`, or the horizon is not more than 0.\n */\nexport function sowDays(season: Pick<Season, \"from\" | \"to\">, start: IsoDate, horizon: number): number[] {\n if (!(horizon > 0)) throw new RangeError(`The horizon ${String(horizon)} is not a number of days more than 0.`);\n const first = dayOf(start);\n const out: number[] = [];\n // The window of the year before the start can go across the end of the year into the start.\n for (let year = Number(start.slice(0, 4)) - 1; ; year += 1) {\n const from = yearDay(year, season.from);\n const sameYear = yearDay(year, season.to);\n const to = from !== undefined && sameYear !== undefined && sameYear < from ? yearDay(year + 1, season.to) : sameYear;\n const opens = from ?? yearDay(year, \"01-01\")!;\n if (opens - first >= horizon) break;\n if (from === undefined || to === undefined || to < first) continue;\n const day = Math.max(from, first) - first;\n if (day < horizon) out.push(day);\n }\n return out;\n}\n\n/**\n * A lot of a resource in the ledger of a season (M2-grow-seed): a store before the event, or a harvest. A harvest is\n * ready from `day`, and its rest spoils on `spoils`. A store has the day -Infinity and no spoil day (Infinity).\n */\ninterface Lot {\n readonly resource: string;\n readonly day: number;\n readonly spoils: number;\n /** The amount that is not taken and not spoiled. */\n left: number;\n /** The amount that spoiled. */\n lost: number;\n}\n\n/** This function gives a lot of a store: it is ready before the event, and it does not spoil. */\nfunction storeLot(resource: string, amount: number): Lot {\n return { resource, day: -Infinity, spoils: Infinity, left: amount, lost: 0 };\n}\n\n/** This function compares two numbers for a sort, also two that are Infinity. */\nfunction compare(a: number, b: number): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\n/**\n * This function takes the use of each resource from `from` to `to` from the lots, first expiring first out. It takes\n * the lot that spoils first, then the lot of the earliest day. A store comes after each lot with a spoil day, and before each\n * harvest with no spoil day. With no spoil day, the order is thus the stores, then each harvest in the order of its day.\n */\nfunction useLots(lots: readonly Lot[], from: ReadonlyMap<string, number>, to: ReadonlyMap<string, number>): void {\n for (const [resource, had] of from) {\n let rest = had - (to.get(resource) ?? 0);\n if (!(rest > 0)) continue;\n const order = lots.filter((lot) => lot.resource === resource && lot.left > 0).sort((a, b) => compare(a.spoils, b.spoils) || compare(a.day, b.day));\n for (const lot of order) {\n if (!(rest > 0)) break;\n const taken = Math.min(lot.left, rest);\n lot.left -= taken;\n rest -= taken;\n }\n }\n}\n\n/**\n * This function gives the sowings of the converters with a season that can operate in a case, up to the horizon. It\n * also gives the lot of each harvest. The order is the order of their sow days, then of the layer. Each sowing takes its inputs\n * from `stock`, and from each harvest that is ready and not spoiled on its sow day (M2-grow-seed). It changes `stock`,\n * and the `left` of each lot is the rest of its harvest after the later sowings.\n */\nfunction sowings(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>, stock: Map<string, number>, makers: Makers, start: IsoDate, horizon: number): { readonly harvests: Harvest[]; readonly lots: Lot[] } {\n const plan: { readonly converter: Converter; readonly season: Season; readonly sow: number; readonly order: number }[] = [];\n (layer.converters ?? []).forEach((converter, order) => {\n const season = converter.season;\n if (season === undefined || !(season.runs > 0) || !canRun(converter, stoppedParts)) return;\n for (const sow of sowDays(season, start, horizon)) plan.push({ converter, season, sow, order });\n });\n plan.sort((a, b) => a.sow - b.sow || a.order - b.order);\n const stores = [...stock].map(([resource, amount]) => storeLot(resource, amount));\n const lots: Lot[] = [];\n const out: Harvest[] = [];\n for (const { converter, season, sow } of plan) {\n const ready = [...stores, ...lots.filter((lot) => lot.day <= sow && lot.spoils > sow)];\n const pool = new Map<string, number>();\n for (const lot of ready) pool.set(lot.resource, (pool.get(lot.resource) ?? 0) + lot.left);\n const had = new Map(pool);\n const runs = run(pool, makers, converter, season.runs, NO_PATH);\n useLots(ready, had, pool);\n const resource = giftResource(converter);\n if (resource === undefined) continue;\n const day = sow + season.delayDays;\n const amount = runs * converter.gives.amount;\n const spoils = season.shelfDays === undefined ? Infinity : day + season.shelfDays;\n out.push({ converter: converter.id, sow, day, runs, resource, amount, ...(season.shelfDays === undefined ? {} : { spoils }) });\n lots.push({ resource, day, spoils, left: amount, lost: 0 });\n }\n for (const store of stores) stock.set(store.resource, store.left);\n return { harvests: out, lots };\n}\n\n/** A lot of a harvest that the draws can take: its resource, its day, its spoil day (Infinity for none) and its amount. */\nexport interface HarvestLot {\n readonly resource: string;\n readonly day: number;\n readonly spoils: number;\n readonly amount: number;\n}\n\n/** The supply of a case with a season: the stocks after the sowings, the sowings, and the lots of the harvests before the horizon. */\nexport interface SeasonSupply {\n /** The stock of each resource of the stores at `at`, less the inputs of the sowings. */\n readonly stock: Map<string, number>;\n readonly harvests: Harvest[];\n /** The rest of each harvest after the later sowings, in the order of its day. Each lot has a day before the horizon and an amount more than 0. */\n readonly lots: readonly HarvestLot[];\n /** The horizon in days (`horizon` of the options, default `SEASON_HORIZON_DAYS`). */\n readonly horizon: number;\n /** The first day of the event (`start` of the options, or `at`). The shares `monthly` read the month of each day from it (M2-solar). */\n readonly start: IsoDate;\n}\n\n/**\n * This function gives the supply of a case with a season (M2-grow-share). `enduranceOf`, `bestEndurance` and `jointDays`\n * use it, so they read the same sowings. It throws a `RangeError` for a horizon that is not more than 0, or a date that is not `YYYY-MM-DD`.\n */\nexport function seasonSupply(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>, options: CaseOptions): SeasonSupply {\n const stock = storeAmounts(layer, options.at, stoppedParts);\n const horizon = seasonHorizon(options.horizon);\n const start = options.start ?? options.at;\n const sown = sowings(layer, stoppedParts, stock, makersOf(layer, stoppedParts), start, horizon);\n // Two crops with different delays give their harvests in a different order from their sowings.\n const lots = sown.lots\n .filter((lot) => lot.day < horizon && lot.left > 0)\n .sort((a, b) => a.day - b.day)\n .map((lot) => ({ resource: lot.resource, day: lot.day, spoils: lot.spoils, amount: lot.left }));\n return { stock, harvests: sown.harvests, lots, horizon, start };\n}\n\n/**\n * This function tells if a layer has a converter with a season, with shares `monthly` or a source (M2-solar) that can run\n * in a case. Such a layer needs the queries in segments of days to a horizon. A harvest, a spoil day and the start of a\n * month end a segment. A source can feed a draw with no end, thus the horizon is the upper limit of its days.\n */\nexport function hasSeason(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): boolean {\n return (layer.converters ?? []).some((converter) => (converter.season !== undefined || converter.monthly !== undefined || isSource(converter)) && canRun(converter, stoppedParts));\n}\n\n/**\n * This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.\n *\n * - A draw takes from the stores only when the case stops its supply part. Each other draw holds without end, and the result leaves it out.\n * - The demand of a draw for each day is its rate times the factor of the case.\n * - The draws take the resources in the order of their level, then of their codes. A draw takes from its direct uses first, then from its converters.\n * - The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.\n * - Each higher draw keeps back its own days times its demand. Thus the takes of all the draws are not more than the stores at any time.\n * - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.\n * A draw with a shared device is different. Refer to the last item.\n * - A converter whose device stops gives nothing. A store whose part stops gives nothing.\n * - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.\n * - A converter with a limit `perDay` runs `perDay` times `devices` times `T` times or less in `T` days. The converters of one device share it.\n * - The higher draws use the runs of a limit first.\n * - A higher draw keeps back its runs of each day for all the days of a lower draw, also when its own days are fewer. This is the safe side.\n * - Two limited converters of one device can make the shortfall of the take order decrease when the days increase.\n * Thus a draw whose ways reach two converters of one device, each with a limit `perDay` more than 0, does not use the take order.\n * A linear program with exact rationals gives its days: the largest `T` with the best share of its stocks and of the device-days.\n * At this `T`, the draw takes the smallest sum of its takes of the stocks, each over its stock, then the fewest device-days.\n\n * - A converter with a season (M2-grow) is not a maker of a take. Its sowings take their inputs from the stores before\n * the first draw, and each harvest adds to the stocks on its day. Refer to `Season`. The query reads the sowings\n * and the harvests up to the horizon (`horizon`, default `SEASON_HORIZON_DAYS`), and a draw holds the horizon at most.\n * - With a season, each draw takes its stocks over spans from harvest to harvest. `days` is the first stop of the\n * draw. A later harvest can feed the draw again: `again` gives these spans, and `takes` is the sum to the horizon.\n * A lower draw gets the stocks that the higher draws leave, the earliest stocks first taken. This is the safe side.\n * - A draw with a shared device and a season gets the programs of `bestEndurance` for itself alone (M2-grow-share-sweep). Its stocks,\n * its harvest lots and its device-days are those that the higher draws leave. It has no field `spoiled`.\n * - A source (M2-solar) takes nothing and has a limit `perDay`. A take uses it first: its runs of a day are lost when no\n * draw uses them. With shares `monthly`, the device-days of a day are the devices times the share of its month. Each\n * span also ends at the start of a month, and a draw can hold again from the start of a month.\n * - A store with a capacity that a source charges (M2-solar-charge-sweep) takes a charge. Each draw that can take it gets the\n * programs of `bestEndurance` for itself alone, in the order of the levels. Thus one draw gets the days of `bestEndurance`.\n * A lower draw takes only the level that the higher draws leave. It charges the store only with the device-days that they leave.\n *\n * The function is pure, but for an internal count of the tries of its fits for the tests. It throws a `RangeError` for a date that is not `YYYY-MM-DD`. The gate `checkEndurance` examines the layer before.\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 * @returns The endurance of each draw whose supply stops\n */\nexport function enduranceOf(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions): Endurance {\n const stoppedParts = caseStopped(caseCuts, options);\n const seasonal = hasSeason(layer, stoppedParts);\n const supply = seasonal ? seasonSupply(layer, stoppedParts, options) : undefined;\n const start = supply?.stock ?? storeAmounts(layer, options.at, stoppedParts);\n const makers = makersOf(layer, stoppedParts);\n const stocked = new Set(layer.stores.map((store) => store.resource));\n const limited = (layer.converters ?? []).filter((converter) => converter.perDay !== undefined && canRun(converter, stoppedParts));\n // The count of devices of each key (`deviceKey`). The gate refuses two counts for one device.\n const devices = new Map(limited.map((converter) => [deviceKey(converter), converter.devices ?? 1]));\n // The share of the device-days of each key in the month of a day (M2-solar). With no shares, each share is 1.\n const monthShares = monthlyShares(limited);\n const begin = options.start ?? options.at;\n const shareAt = (key: string, at: number): number => (monthShares.size === 0 ? 1 : shareOf(monthShares, key, monthOf(begin, at)));\n const months = monthShares.size === 0 || supply === undefined ? [] : monthEdges(begin, supply.horizon);\n const nextMonth = (at: number): number => months.find((day) => day > at) ?? Infinity;\n // The device-days of each day that the higher draws use, by the key of the device. A higher draw keeps back its\n // device-days of each day for all the days of a lower draw, also after its own days end. This is the safe side.\n const used = new Map<string, number>();\n // The stocks that the higher draws leave after their own days.\n let before = new Map(start);\n // The sowings take their inputs from the stocks before each draw (M2-grow). Each harvest is a part of the stocks\n // from its day. `later` holds the amount of each harvest that the higher draws leave.\n const horizon = supply?.horizon ?? Infinity;\n const harvests = supply?.harvests ?? [];\n // The rest of each harvest after the sowings, in the order of its day (`seasonSupply`).\n const later = (supply?.lots ?? []).map((lot) => ({ ...lot }));\n // The stores with a capacity that a source charges (M2-solar-charge-sweep), and the rest of each that the higher draws leave.\n const capacities = storeCapacities(layer, stoppedParts);\n const chargedResources = new Set([...capacities.keys()].filter((resource) => (makers.get(resource) ?? []).some(isSource)));\n const rests = new Map<string, readonly ChargeRest[]>();\n const needs: Record<string, DrawEndurance> = {};\n for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {\n const ways = waysOf(layer, draw.need, stoppedParts, makers);\n const demand = drawDemand(draw, caseCuts);\n // The device-days of each day that the higher draws leave to this draw, by the key of the device.\n const room = new Map([...devices].map(([key, count]) => [key, Math.max(0, count - (used.get(key) ?? 0))] as const));\n const closure = inputClosure(ways);\n // The converters that the draw can use: the converters that give its need, and the makers of its inputs through each chain.\n const reach = new Set([...ways.converters, ...[...closure].flatMap((resource) => makers.get(resource) ?? [])]);\n // The take of `days` days of the need from `stock`, with the device-days of those days from the day `at`.\n const after = (stock: ReadonlyMap<string, number>, days: number, at = 0): { left: Map<string, number>; short: number } => {\n const tried = new Map(stock);\n for (const [key, free] of room) tried.set(RUNS + key, free * shareAt(key, at) * days);\n return { left: tried, short: take(tried, ways, days * demand) };\n };\n // The days of one span from `stock`, `limit` days or less. `bound` is an upper limit of the need that the stock gives.\n const span = (stock: ReadonlyMap<string, number>, limit: number, bound: number, at = 0): { days: number; left: Map<string, number> } => {\n const fit = largestFit(Math.min(limit, bound / demand), (days) => {\n const tried = after(stock, days, at);\n return { short: tried.short, need: days * demand, value: tried.left };\n });\n return { days: fit.x, left: fit.value ?? after(stock, fit.x, at).left };\n };\n // With two limited converters of one device, the shortfall of the take order can decrease when the days increase.\n // For such a draw, a linear program gives the best share of the device-days and of the stocks.\n const shares = sharesDevice(reach);\n // A draw that can take a store with a charge gets the same programs, with the rest that the higher draws leave (M2-solar-charge-sweep).\n const charging = [...closure].some((resource) => chargedResources.has(resource));\n if ((shares || charging) && seasonal) {\n const lots = later.map((lot) => ({ resource: lot.resource, day: lot.day, spoils: lot.spoils, amount: lot.amount }));\n const held = seasonDraw(layer, stoppedParts, caseCuts, draw, resourcesOnly(before), lots, horizon, room, begin, capacities, rests);\n needs[draw.need] = held.need;\n for (const [key, each] of held.perDay) used.set(key, (used.get(key) ?? 0) + each);\n for (const [resource, rest] of held.rests) rests.set(resource, rest);\n before = held.stock;\n for (const [index, amount] of held.lots.entries()) (later[index] as { amount: number }).amount = amount;\n continue;\n }\n const share = shares ? bestShare({ draw, stock: before, room, direct: ways.direct, converters: ways.converters, makers: [...reach].filter((converter) => !ways.converters.includes(converter)), demand }) : undefined;\n let low: number;\n let left: Map<string, number>;\n // The stocks at the end of the sweep, and the stocks that came in it: the stocks before the draw and the harvests.\n let final: Map<string, number>;\n const came = new Map(before);\n // The amount of each resource that spoils in the sweep of the draw (M2-grow-seed).\n const lost = new Map<string, number>();\n // The ledger of the sweep of a season (M2-grow-seed): a lot for each stock before the draw, then each harvest that arrives.\n const pool = [...before].map(([resource, amount]) => storeLot(resource, amount));\n const arrived: { readonly lot: Lot; readonly harvest: (typeof later)[number] }[] = [];\n const again: { from: number; to: number }[] = [];\n let atHorizon = false;\n // The device-days of each day that the draw uses, the most of each span, by the key of the device. With shares\n // `monthly`, a span gives `free` times its share, and the use counts as its part of that share (M2-solar). Thus a\n // draw that uses all the device-days of a dark month keeps all the device-days of each month. This is the safe side.\n const perDay = new Map<string, number>();\n const count = (spanLeft: ReadonlyMap<string, number>, days: number, at = 0): void => {\n if (days > 0) for (const [key, free] of room) {\n const share = shareAt(key, at);\n if (!(share > 0)) continue;\n const each = (free * share * days - (spanLeft.get(RUNS + key) ?? 0)) / days / share;\n perDay.set(key, perDay.has(key) ? Math.max(perDay.get(key)!, each) : each);\n }\n };\n // The length and the first day of the span of the first stop, for the limits of the runs.\n let spanDays: number;\n let spanAt = 0;\n if (share !== undefined) {\n low = share.days;\n spanDays = low;\n left = new Map(before);\n for (const [resource, amount] of share.taken) left.set(resource, Math.max(0, (left.get(resource) ?? 0) - amount));\n for (const [key, free] of room) left.set(RUNS + key, Math.max(0, free * low - (share.used.get(key) ?? 0)));\n final = left;\n count(left, low);\n } else if (later.length === 0 && !seasonal) {\n // The upper limit: the days that the draw holds when it takes all the stores itself. `largestFit` finds the days below it.\n ({ days: low, left } = span(before, Infinity, capacity(start, ways)));\n spanDays = low;\n final = left;\n count(left, low);\n } else {\n // The sweep from harvest to harvest (M2-grow). In each span, the draw takes from the stocks of the span, first\n // expiring first out. A span ends at the next harvest, at the next spoil day of a lot (M2-grow-seed) or at the\n // horizon. After a stop, the draw holds again from the next harvest that feeds it.\n let stock: Map<string, number> = new Map(before);\n let next = 0;\n let at = 0;\n let first: { days: number; left: Map<string, number>; spanDays: number; spanAt: number } | undefined;\n let resumed = 0;\n // The harvests arrive on their days, and then the rest of each lot spoils on its spoil day. During a stop, the\n // draw takes nothing, thus a lot that arrives and spoils in the stop is lost in full.\n const advance = (): void => {\n while (next < later.length && later[next]!.day <= at) {\n const harvest = later[next]!;\n const lot: Lot = { resource: harvest.resource, day: harvest.day, spoils: harvest.spoils, left: harvest.amount, lost: 0 };\n pool.push(lot);\n arrived.push({ lot, harvest });\n stock.set(lot.resource, (stock.get(lot.resource) ?? 0) + lot.left);\n came.set(lot.resource, (came.get(lot.resource) ?? 0) + lot.left);\n next += 1;\n }\n for (const lot of pool) {\n if (!(lot.left > 0) || lot.spoils > at) continue;\n stock.set(lot.resource, Math.max(0, (stock.get(lot.resource) ?? 0) - lot.left));\n lost.set(lot.resource, (lost.get(lot.resource) ?? 0) + lot.left);\n lot.lost += lot.left;\n lot.left = 0;\n }\n };\n advance();\n for (;;) {\n const spoil = Math.min(...pool.filter((lot) => lot.left > 0).map((lot) => lot.spoils));\n const end = Math.min(next < later.length ? later[next]!.day : Infinity, spoil, horizon, nextMonth(at));\n const part = span(stock, end - at, capacity(stock, ways, shareAt, at), at);\n count(part.left, part.days, at);\n const rest = resourcesOnly(part.left);\n useLots(pool, stock, rest);\n stock = rest;\n const stop = at + part.days;\n if (part.days < end - at) {\n if (first === undefined) first = { days: stop, left: part.left, spanDays: part.days, spanAt: at };\n else if (stop > resumed) again.push({ from: resumed, to: stop });\n // After a stop, the draw holds again from the next harvest, or from the start of the next month (M2-solar).\n const resume = Math.min(next < later.length ? later[next]!.day : Infinity, nextMonth(at));\n if (!(resume < horizon)) break;\n at = resume;\n resumed = at;\n } else {\n at = end;\n if (at >= horizon) {\n if (first === undefined) atHorizon = true;\n else again.push({ from: resumed, to: horizon });\n break;\n }\n }\n advance();\n }\n low = first?.days ?? horizon;\n left = first?.left ?? stock;\n spanDays = first?.spanDays ?? horizon;\n spanAt = first?.spanAt ?? 0;\n final = stock;\n }\n // The binding resources are of the stores only: a used-up limit of runs is in `capped`, not here.\n const stores = resourcesOnly(left);\n const binding = atHorizon\n ? []\n : [...closure]\n .filter((resource) => !makers.has(resource) || stocked.has(resource))\n .filter((resource) => mostResource(stores, makers, resource, NO_PATH) <= USED_UP * Math.max(1, start.get(resource) ?? 0))\n .sort();\n const takes: Record<string, number> = {};\n for (const [resource, amount] of came) {\n const taken = amount - (final.get(resource) ?? 0) - (lost.get(resource) ?? 0);\n if (taken > 0) takes[resource] = taken;\n }\n const spoiled = Object.fromEntries([...lost].filter(([, amount]) => amount > 0));\n // A limit stops the draw when its limit gives the converter no runs left, and its inputs give more runs.\n // The runs left are the device-days left times `perDay`. Thus a limit of 0 stops the draw, also with its device-days left.\n const runsLeft = (converter: Converter): number => (daysLeft(left, converter) ?? 0) * (converter.perDay ?? 0);\n const runsGiven = (converter: Converter): number => (devices.get(deviceKey(converter)) ?? 1) * shareAt(deviceKey(converter), spanAt) * (converter.perDay ?? 0) * spanDays;\n const capped = atHorizon\n ? []\n : limited\n .filter((converter) => reach.has(converter))\n .filter((converter) => runsLeft(converter) <= USED_UP * Math.max(1, runsGiven(converter)))\n .filter((converter) => mostRuns(stores, makers, converter, NO_PATH) > USED_UP)\n .map((converter) => converter.id)\n .sort();\n needs[draw.need] = {\n days: low,\n binding,\n takes,\n ...(capped.length === 0 ? {} : { capped }),\n ...(atHorizon ? { atHorizon: true as const } : {}),\n ...(again.length === 0 ? {} : { again }),\n ...(Object.keys(spoiled).length === 0 ? {} : { spoiled }),\n };\n // The device-days of each day of this draw count against each lower draw, for all of its days.\n for (const [key, each] of perDay) used.set(key, (used.get(key) ?? 0) + each);\n if (later.length === 0 && !seasonal) {\n before = resourcesOnly(final);\n continue;\n }\n // The lower draws get the rest of each lot after the takes of this draw. A lower draw reads the spoil of each lot\n // again, thus the spoiled rest of a lot is a part of its rest. With no spoil day, the takes come from the earliest\n // stocks: the stocks before the draw, then each harvest in the order of its day.\n for (const lot of pool) if (lot.day === -Infinity) before.set(lot.resource, lot.left);\n for (const { lot, harvest } of arrived) harvest.amount = lot.left + lot.lost;\n }\n return { case: caseCuts.case, at: options.at, needs, ...(harvests.length === 0 ? {} : { harvests }) };\n}\n\n/** This function gives the horizon of a layer with a season, or throws a `RangeError` for a horizon that is not more than 0. */\nfunction seasonHorizon(horizon: number | undefined): number {\n const value = horizon ?? SEASON_HORIZON_DAYS;\n if (!(value > 0) || !Number.isFinite(value)) throw new RangeError(`The horizon ${String(horizon)} is not a number of days more than 0.`);\n return value;\n}\n\n/** This function tells if two converters of `reach` with a limit `perDay` more than 0 share one device. */\nfunction sharesDevice(reach: ReadonlySet<Converter>): boolean {\n const seen = new Set<string>();\n for (const converter of reach) {\n if (converter.perDay === undefined || !(converter.perDay > 0)) continue;\n const key = deviceKey(converter);\n if (seen.has(key)) return true;\n seen.add(key);\n }\n return false;\n}\n\n/**\n * This function gives an upper limit of a need that the stores give with no other draw, through each chain. A source\n * (M2-solar) with a share more than 0 gives no upper limit, thus the limit is Infinity. The span of the sweep is finite.\n */\nfunction capacity(start: ReadonlyMap<string, number>, ways: Ways, shareAt?: (key: string, at: number) => number, at = 0): number {\n for (const converter of ways.open) if ((shareAt === undefined ? 1 : shareAt(deviceKey(converter), at)) > 0) return Infinity;\n let total = 0;\n for (const use of ways.direct) total += mostResource(start, ways.makers, use.resource, NO_PATH) * use.amount;\n for (const converter of ways.converters) total += mostRuns(start, ways.makers, converter, NO_PATH) * converter.gives.amount;\n return total;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { bandFault, CUT_BOUNDS, curveFault, dayNumber, intervalFault, isCutBound, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./endurance.ts\";\nimport type { Converter, EnduranceLayer } from \"./layer.ts\";\n\n// The gate of an endurance layer: the meaning of a layer with a correct form, for its base stack.\n\n/**\n * These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.\n *\n * - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.\n * The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.\n * - `endurance-level-unknown`: the level of a draw is not a level of the layer.\n * - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.\n * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.\n * - `endurance-range`: an amount, a rate, a count or a factor is not a finite number of 0 or more. Or a reach is not from 0 to 1.\n * - `endurance-date`: a date is not a date `YYYY-MM-DD`.\n * - `endurance-converter-empty`: a converter takes nothing and has no limit `perDay` more than 0, or it gives an amount of 0.\n * A converter with a limit can take nothing: it is a source, for example a solar panel. Since 0.8.20 (M2-solar).\n * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.\n * Or its days do not increase, or its chance increases.\n * - `endurance-bound`: the bound of a cut is not a value of `CUT_BOUNDS` of the core. Since 0.8.4.\n * - `endurance-prior-case`: a prior names a case that the layer does not have.\n * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.\n * - `endurance-devices`: two converters of one device give two different counts of devices.\n * - `endurance-device-mix` (warning): a device has a converter with a limit `perDay` and a converter with no limit. The\n * converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.\n * - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.\n * - `endurance-cut-no-curve` (warning): a cut has no curve of its duration. The draws whose stop it can be part of are no read in the shortfall.\n * - `endurance-season`: the season of a converter has a day that is not `MM-DD`. Or its delay or its shelf life is not more than 0.\n * Or its count of sowings is not a finite number of 0 or more. Or the converter with a season gives a need, or it has\n * `perDay` or `devices`. Since 0.8.16 (M2-grow).\n * - `endurance-monthly`: the shares `monthly` of a converter are not 12 numbers from 0 to 1. Or the converter has\n * `monthly` and no `perDay`, or a season. Or two converters of one device have different shares. Since 0.8.20 (M2-solar).\n * - `endurance-capacity`: the capacity of a store is not a finite number more than 0, or it is less than the amount.\n * Or a store with a capacity has a due date. Or a resource has a store with a capacity and a store with no capacity.\n * Since 0.8.21 (M2-solar-charge).\n */\nexport const ENDURANCE_CODES: readonly [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-bound\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n \"endurance-season\",\n \"endurance-monthly\",\n \"endurance-capacity\",\n] = [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-bound\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n \"endurance-season\",\n \"endurance-monthly\",\n \"endurance-capacity\",\n];\n\n/** A code of `ENDURANCE_CODES`. */\nexport type EnduranceCode = (typeof ENDURANCE_CODES)[number];\n\n/** A fault of the gate of an endurance layer. */\nexport interface EnduranceFault extends Fault {\n readonly code: EnduranceCode;\n}\n\nexport { curveFault } from \"@mark1russell7/system-stack\";\n\n/**\n * This function gives each fault of an endurance layer. With a base stack, it also examines the `id` of each part. A list with no error tells that the gate passes.\n *\n * The faults are in the order of the layer. The function is pure.\n *\n * @param layer - The endurance layer\n * @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.\n * @returns The faults\n */\nexport function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[] {\n const faults: EnduranceFault[] = [];\n const add = (level: EnduranceFault[\"level\"], code: EnduranceCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const once = (what: string, keys: readonly string[]): void => {\n const seen = new Set<string>();\n for (const key of keys) {\n if (seen.has(key)) add(\"error\", \"endurance-twice\", key, `Two or more ${what} have the key \"${key}\".`);\n seen.add(key);\n }\n };\n const range = (at: string, what: string, value: number): void => {\n if (!(Number.isFinite(value) && value >= 0)) add(\"error\", \"endurance-range\", at, `The ${what} of \"${at}\" is ${String(value)}. It must be a finite number of 0 or more.`);\n };\n const date = (at: string, value: string): void => {\n if (dayNumber(value) === undefined) add(\"error\", \"endurance-date\", at, `The date \"${value}\" of \"${at}\" is not a date YYYY-MM-DD.`);\n };\n const parts = stack === undefined ? undefined : new Set(stack.parts.map((part) => part.id));\n const part = (at: string, what: string, id: string | undefined): void => {\n if (parts !== undefined && id !== undefined && !parts.has(id)) add(\"error\", \"endurance-part-unknown\", at, `The ${what} \"${id}\" of \"${at}\" is not a part of the stack.`);\n };\n const resources = new Set(layer.resources.map((resource) => resource.code));\n const resource = (at: string, code: string): void => {\n if (!resources.has(code)) add(\"error\", \"endurance-resource-unknown\", at, `The resource \"${code}\" of \"${at}\" is not a resource of the layer.`);\n };\n const direct = layer.direct ?? [];\n const converters = layer.converters ?? [];\n const cases = layer.cases ?? [];\n const priors = layer.priors ?? [];\n\n once(\"levels\", layer.levels);\n once(\"resources\", layer.resources.map((item) => item.code));\n once(\"stores\", layer.stores.map((store) => store.id));\n once(\"draws\", layer.draws.map((draw) => draw.need));\n once(\"converters\", converters.map((converter) => converter.id));\n once(\"cases\", cases.map((item) => item.case));\n once(\"priors\", priors.map((prior) => `${prior.case}@${prior.place}`));\n\n for (const store of layer.stores) {\n resource(store.id, store.resource);\n range(store.id, \"amount\", store.amount);\n if (store.due !== undefined) date(store.id, store.due);\n part(store.id, \"part\", store.part);\n if (store.capacity !== undefined) {\n if (!(Number.isFinite(store.capacity) && store.capacity > 0 && store.capacity >= store.amount)) {\n add(\"error\", \"endurance-capacity\", store.id, `The capacity of \"${store.id}\" is ${String(store.capacity)}. It must be a finite number more than 0, and not less than the amount.`);\n }\n if (store.due !== undefined) add(\"error\", \"endurance-capacity\", store.id, `The store \"${store.id}\" has a capacity and a due date. A store with a charge has no due date.`);\n }\n }\n for (const code of new Set(layer.stores.map((store) => store.resource))) {\n const all = layer.stores.filter((store) => store.resource === code);\n const charged = all.filter((store) => store.capacity !== undefined);\n if (charged.length > 0 && charged.length < all.length) {\n add(\"error\", \"endurance-capacity\", code, `The resource \"${code}\" has a store with a capacity and a store with no capacity. Its stores all have a capacity, or none has one.`);\n }\n }\n const levels = new Set(layer.levels);\n for (const draw of layer.draws) {\n if (!levels.has(draw.level)) add(\"error\", \"endurance-level-unknown\", draw.need, `The level \"${draw.level}\" of the draw \"${draw.need}\" is not a level of the layer.`);\n range(draw.need, \"rate\", draw.perDay);\n if (draw.users !== undefined) range(draw.need, \"count of users\", draw.users);\n part(draw.need, \"supply\", draw.supply);\n const ways = direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need);\n if (!ways) add(\"warning\", \"endurance-no-way\", draw.need, `The draw \"${draw.need}\" has no direct use and no converter. It holds 0 days when its supply stops.`);\n }\n for (const use of direct) {\n const at = `${use.resource}>${use.need}`;\n resource(at, use.resource);\n range(at, \"amount\", use.amount);\n }\n for (const converter of converters) {\n once(`resources of the converter \"${converter.id}\"`, converter.takes.map((input) => input.resource));\n for (const input of converter.takes) {\n resource(converter.id, input.resource);\n range(converter.id, \"amount\", input.amount);\n }\n range(converter.id, \"amount\", converter.gives.amount);\n const made = giftResource(converter);\n if (made !== undefined) resource(converter.id, made);\n const source = converter.perDay !== undefined && converter.perDay > 0;\n if ((!source && !converter.takes.some((input) => input.amount > 0)) || converter.gives.amount === 0) add(\"error\", \"endurance-converter-empty\", converter.id, `The converter \"${converter.id}\" takes nothing, or it gives nothing.`);\n part(converter.id, \"device\", converter.device);\n if (converter.perDay !== undefined) range(converter.id, \"rate perDay\", converter.perDay);\n if (converter.devices !== undefined && !(Number.isSafeInteger(converter.devices) && converter.devices >= 1))\n add(\"error\", \"endurance-range\", converter.id, `The count of devices of \"${converter.id}\" is ${String(converter.devices)}. It must be a whole number of 1 or more.`);\n if (converter.season !== undefined) for (const message of seasonFaults(converter)) add(\"error\", \"endurance-season\", converter.id, message);\n for (const message of monthlyFaults(converter)) add(\"error\", \"endurance-monthly\", converter.id, message);\n }\n const shares = new Map<string, Converter>();\n for (const converter of converters) {\n if (converter.device === undefined || converter.perDay === undefined) continue;\n const seen = shares.get(converter.device);\n if (seen === undefined) shares.set(converter.device, converter);\n else if (!sameShares(seen.monthly, converter.monthly))\n add(\"error\", \"endurance-monthly\", converter.id, `The converter \"${converter.id}\" and the converter \"${seen.id}\" of the device \"${converter.device}\" have different shares monthly. The converters of one device have the same shares.`);\n }\n const counts = new Map<string, number>();\n for (const converter of converters) {\n if (converter.device === undefined) continue;\n const count = converter.devices ?? 1;\n const seen = counts.get(converter.device);\n if (seen !== undefined && seen !== count)\n add(\"error\", \"endurance-devices\", converter.id, `The converter \"${converter.id}\" gives the count ${String(count)} for the device \"${converter.device}\". An other converter gives the count ${String(seen)}.`);\n if (seen === undefined) counts.set(converter.device, count);\n }\n // One fault names each device with a limited converter and a converter with no limit, at the first converter with no limit.\n const mixed = new Set<string>();\n for (const converter of converters) {\n const device = converter.device;\n if (device === undefined || converter.perDay !== undefined || mixed.has(device)) continue;\n const limited = converters.find((other) => other.device === device && other.perDay !== undefined);\n if (limited === undefined) continue;\n mixed.add(device);\n add(\"warning\", \"endurance-device-mix\", converter.id, `The device \"${device}\" has the limited converter \"${limited.id}\" and the converter \"${converter.id}\" with no limit. \"${converter.id}\" uses no device-days.`);\n }\n const caseCodes = new Set(cases.map((item) => item.case));\n for (const item of cases) {\n once(`cuts of the case \"${item.case}\"`, item.cuts.map((cut) => cut.part));\n for (const cut of item.cuts) {\n const at = `${item.case}/${cut.part}`;\n part(at, \"cut\", cut.part);\n if (cut.bound !== undefined && !isCutBound(cut.bound))\n add(\"error\", \"endurance-bound\", at, `The bound of the cut \"${at}\" is ${JSON.stringify(cut.bound)}. It must be one of ${CUT_BOUNDS.join(\", \")}.`);\n if (cut.duration === undefined) {\n add(\"warning\", \"endurance-cut-no-curve\", at, `The cut \"${at}\" has no curve of its duration, so the draws that it can stop are no read.`);\n if (cut.band !== undefined) add(\"error\", \"endurance-curve\", at, `The cut \"${at}\" has a band and no curve of its duration.`);\n continue;\n }\n const fault = curveFault(cut.duration);\n if (fault !== undefined) add(\"error\", \"endurance-curve\", at, `The duration of the cut \"${at}\": ${fault}`);\n const band = cut.band === undefined || fault !== undefined ? undefined : bandFault(cut.duration, cut.band);\n if (band !== undefined) add(\"error\", \"endurance-curve\", at, `The band of the cut \"${at}\": ${band}`);\n }\n for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, \"factor\", factor);\n if (item.leadSeconds !== undefined) range(item.case, \"lead time\", item.leadSeconds);\n }\n for (const cycle of resourceCycles(converters)) {\n const [first = \"\"] = cycle;\n const names = cycle.map((code) => `\"${code}\"`).join(\", \");\n const message = cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`;\n add(\"error\", \"endurance-cycle\", first, `${message} A chain of converters cannot end.`);\n }\n for (const prior of priors) {\n const at = `${prior.case}@${prior.place}`;\n if (!caseCodes.has(prior.case)) add(\"error\", \"endurance-prior-case\", at, `The prior \"${at}\" names the case \"${prior.case}\", which the layer does not have.`);\n range(at, \"count of events in one year\", prior.perYear);\n 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.`);\n date(at, prior.asOf);\n const fault = prior.interval === undefined ? undefined : intervalFault(prior.interval);\n if (fault !== undefined) add(\"error\", \"endurance-range\", at, `The interval of the count of events in one year of \"${at}\" is not valid. ${fault}`);\n }\n return faults;\n}\n\n/** This function tells if a text is a day `MM-DD` of a leap year. */\nfunction isMonthDay(value: string): boolean {\n return /^\\d{2}-\\d{2}$/.test(value) && dayNumber(`2000-${value}`) !== undefined;\n}\n\n/** This function gives the messages of the faults of the season of a converter. */\nfunction seasonFaults(converter: Converter): string[] {\n const season = converter.season;\n if (season === undefined) return [];\n const out: string[] = [];\n for (const day of [season.from, season.to]) if (!isMonthDay(day)) out.push(`The season of \"${converter.id}\" has the day \"${day}\". It is not a day MM-DD.`);\n if (!(Number.isFinite(season.delayDays) && season.delayDays > 0)) out.push(`The delay of the season of \"${converter.id}\" is ${String(season.delayDays)}. It must be a finite number of days more than 0.`);\n if (season.shelfDays !== undefined && !(Number.isFinite(season.shelfDays) && season.shelfDays > 0)) out.push(`The shelf life of the season of \"${converter.id}\" is ${String(season.shelfDays)}. It must be a finite number of days more than 0.`);\n if (!(Number.isFinite(season.runs) && season.runs >= 0)) out.push(`The runs of the season of \"${converter.id}\" are ${String(season.runs)}. They must be a finite number of 0 or more.`);\n if (giftResource(converter) === undefined) out.push(`The converter \"${converter.id}\" has a season and gives a need. A converter with a season gives a resource.`);\n if (converter.perDay !== undefined || converter.devices !== undefined) out.push(`The converter \"${converter.id}\" has a season and a limit perDay or devices. A converter with a season has no such limit.`);\n return out;\n}\n\n/** This function gives the messages of the faults of the shares `monthly` of a converter (M2-solar). */\nfunction monthlyFaults(converter: Converter): string[] {\n const monthly = converter.monthly;\n if (monthly === undefined) return [];\n const out: string[] = [];\n if (monthly.length !== 12 || !monthly.every((share) => Number.isFinite(share) && share >= 0 && share <= 1))\n out.push(`The shares monthly of \"${converter.id}\" are not 12 numbers from 0 to 1.`);\n if (converter.perDay === undefined) out.push(`The converter \"${converter.id}\" has shares monthly and no limit perDay. The shares are parts of the limit.`);\n if (converter.season !== undefined) out.push(`The converter \"${converter.id}\" has shares monthly and a season. A converter has one or the other.`);\n return out;\n}\n\n/** This function tells if two lists of shares `monthly` are equal. No list is equal to a list of 12 ones. */\nfunction sameShares(a: readonly number[] | undefined, b: readonly number[] | undefined): boolean {\n const full = (shares: readonly number[] | undefined): readonly number[] => shares ?? Array.from({ length: 12 }, () => 1);\n const left = full(a);\n const right = full(b);\n return left.length === right.length && left.every((share, index) => share === right[index]);\n}\n\n/**\n * This function gives each cycle of resources: a resource is made from a resource that a converter makes from it. Each cycle is a list of codes.\n * A converter with a season is not part of a cycle: its harvest comes after its sowing, thus a chain of it ends.\n */\nfunction resourceCycles(converters: readonly Converter[]): string[][] {\n const from = new Map<string, Set<string>>();\n for (const converter of converters) {\n const made = giftResource(converter);\n if (made === undefined || converter.season !== undefined) continue;\n const inputs = from.get(made) ?? new Set<string>();\n for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);\n from.set(made, inputs);\n }\n const successors = (code: string): Iterable<string> => from.get(code) ?? [];\n return stronglyConnectedComponents(from.keys(), successors).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (from.get(only)?.has(only) ?? false);\n });\n}\n\n/** This function tells if a list of faults has an error. */\nexport function hasEnduranceError(faults: readonly EnduranceFault[]): boolean {\n return faults.some((fault) => fault.level === \"error\");\n}\n","import { canonicalJson } from \"@mark1russell7/rigor-generators\";\nimport { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The join of the endurance layers of the fragments of a stack, for example one file of stores for each owner.\n\n/**\n * This function joins the endurance layers of the fragments of a stack into one layer.\n *\n * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.\n * - The records of each list are in the order of the fragments.\n * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.\n * Its message gives the canonical JSON of the record of each fragment.\n * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.\n * - One key of each other list in two or more fragments is a fault, also when the records are equal.\n * - The key of a direct use is its resource and its need.\n *\n * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer> {\n const levels = joinSetting(pieces, (layer) => (layer.levels.length > 0 ? layer.levels.join(\"\\n\") : undefined), \"levels\");\n // Two fragments can declare one resource, for example `water.stored` in `L`. Canonical JSON (RFC 8785) compares the records,\n // so the order of the keys has no effect. The message of a fault gives the canonical JSON of the record of each fragment.\n const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\", {\n equal: (first, other) => canonicalJson(first) === canonicalJson(other),\n text: canonicalJson,\n });\n const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, \"store\");\n const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, \"draw\");\n const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, \"direct use\");\n const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, \"converter\");\n const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, \"case\");\n const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, \"prior\");\n const errors = [levels, resources, stores, draws, direct, converters, cases, priors].flatMap((join) => join.errors);\n if (errors.length > 0) return { ok: false, errors };\n const has = (key: \"direct\" | \"converters\" | \"cases\" | \"priors\"): boolean => pieces.some((piece) => piece.layer[key] !== undefined);\n return {\n ok: true,\n layer: {\n schema: ENDURANCE_SCHEMA,\n levels: levels.value === undefined ? [] : levels.value.split(\"\\n\"),\n resources: resources.items,\n stores: stores.items,\n draws: draws.items,\n ...(has(\"direct\") ? { direct: direct.items } : {}),\n ...(has(\"converters\") ? { converters: converters.items } : {}),\n ...(has(\"cases\") ? { cases: cases.items } : {}),\n ...(has(\"priors\") ? { priors: priors.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,SAAS,WAA2C;CAClE,MAAM,sBAAM,IAAI,IAAoB;CACpC,KAAK,MAAM,SAAS,UAAU,OAAO,IAAI,MAAM,SAAS,GAAG,IAAI,IAAI,MAAM,WAAW,IAAI,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM;CAChI,OAAO;AACT;;;;;AAMA,SAAgB,SAAS,WAA+B;CACtD,IAAI,EAAE,UAAU,WAAW,KAAA,KAAa,UAAU,SAAS,IAAI,OAAO;CAEtE,KAAK,MAAM,SAAS,UAAU,OAAO,IAAI,MAAM,SAAS,GAAG,OAAO;CAClE,OAAO;AACT;;;;;AAMA,SAAgB,OAAO,WAAsB,cAA4C;CACvF,OAAO,UAAU,MAAM,SAAS,MAAM,SAAS,SAAS,CAAC,CAAC,OAAO,KAAK,SAAS,SAAS,OAAO,UAAU,WAAW,KAAA,KAAa,CAAC,aAAa,IAAI,UAAU,MAAM;AACrK;;;;;AAMA,SAAgB,UAAU,WAA8B;CACtD,OAAO,UAAU,WAAW,KAAA,IAAY,aAAa,UAAU,OAAO,UAAU,UAAU;AAC5F;;;ACnCA,MAAa,YAAY;;;;;AAmBzB,MAAa,WAAW,EAAE,OAAO,EAAE;;;;;;;;;;;;;;;;;AAkBnC,SAAgB,WAAc,MAAc,SAAwC;CAClF,MAAM,QAAQ,UAA2B,MAAM,SAAS,YAAY,MAAM;CAC1E,SAAS,SAAS;CAClB,MAAM,QAAQ,QAAQ,IAAI;CAC1B,IAAI,KAAK,KAAK,GAAG,OAAO;EAAE,GAAG;EAAM,OAAO,MAAM;CAAM;CACtD,IAAI,MAAM;CACV,IAAI;CACJ,IAAI,OAAO;CACX,IAAI,Y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3
3
  "name": "@mark1russell7/stack-endurance",
4
- "version": "0.8.25",
4
+ "version": "0.8.26",
5
5
  "description": "Stores, draws and converters of a system stack: the days that each draw holds when a case cuts its supply, and the shortfall of each level in one year. An add-on of system-stack.",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@mark1russell7/collections": "^0.11.2",
53
- "@mark1russell7/linear": "^0.1.0",
53
+ "@mark1russell7/linear": "^0.1.3",
54
54
  "@mark1russell7/rational": "^0.1.3",
55
55
  "@mark1russell7/rigor-generators": "^0.2.0",
56
56
  "@mark1russell7/system-stack": "0.1.16",