@mark1russell7/stack-endurance 0.8.18 → 0.8.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,7 +53,18 @@ A converter can have a `season`. It has a window of sow days in each year (`from
53
53
  - Since 0.8.18, `bestEndurance` and `jointDays` read the harvests. The days go in segments that end at each harvest day, at each spoil day and at the horizon. A segment takes only the lots that are ready and not spoiled in all of it.
54
54
  - In `bestEndurance`, `days` is the first stop of each draw, with the same share by level and leximin. A last program gives the most fed days after the stops to each level (`again`). Two draws that use one limited device after their stops take turns on it. This is the safe side.
55
55
  - `jointDays` gives the largest common first stop. With `atHorizon`, the plan holds the horizon.
56
- - `enduranceOf` still refuses a draw with a shared device and a season (M2-grow-share-sweep).
56
+ - Since 0.8.19, a draw of `enduranceOf` with a shared device and a season gets the programs of `bestEndurance` for itself alone (M2-grow-share-sweep). Its stocks, harvest lots and device-days are those that the higher draws leave. It has no field `spoiled`.
57
+
58
+ ## Power from the sun: a source with shares in each month
59
+
60
+ A converter with a limit `perDay` more than 0 can take nothing. It is a source, for example a solar panel. A converter can also have `monthly`: 12 shares from 0 to 1, January first. In a day of month `m`, the converter has `devices` times `monthly[m]` device-days. Thus a panel with `perDay` 1500 and a share of 0.2 in January gives 300 runs in a day of January. Since 0.8.20 (M2-solar).
61
+
62
+ - The energy of a day that no draw takes is lost. A store does not take it. Thus a battery is a store with no charge from the panel. This is the safe side.
63
+ - A take uses a source first, before the stores and the other converters. The runs of a source in a day are lost when no draw uses them.
64
+ - A layer with a source or with shares goes in segments to the horizon, as a layer with a season. A segment also ends at the start of each month. A source can feed a draw with no end, thus the horizon is the upper limit of its days.
65
+ - After a stop, a draw can hold again from the start of a month with more device-days. `again` gives these spans.
66
+ - A higher draw keeps the largest part of the device-days that it uses in a month, for each month of a lower draw. This is the safe side.
67
+ - The converters of one device have the same shares. A converter with shares has a limit `perDay` and no season. The gate refuses the other cases (`endurance-monthly`).
57
68
 
58
69
  ## The rule of shortfall
59
70
 
@@ -232,4 +243,4 @@ In the sample, the rice needs 2 L of water for each kg. The drinking water holds
232
243
 
233
244
  ## The gate
234
245
 
235
- `checkEndurance(layer, stack)` gives the faults of a layer. `ENDURANCE_CODES` lists the codes. The gate finds two records with one key, and an unknown level, resource or part. It also finds a value out of range, a bad date, an empty converter and a bad survival curve. Converters that make a resource from itself are a cycle, and the gate refuses them. Two counts of devices for one device are a fault (`endurance-devices`). A device with a limited converter and a converter with no limit is a warning (`endurance-device-mix`), because the converter with no limit uses no device-days. A draw with no way to get its need is a warning, and a cut with no curve is a warning. A bad season is a fault (`endurance-season`). A converter with a season is not part of a cycle, because its harvest comes after its sowing.
246
+ `checkEndurance(layer, stack)` gives the faults of a layer. `ENDURANCE_CODES` lists the codes. The gate finds two records with one key, and an unknown level, resource or part. It also finds a value out of range, a bad date, an empty converter and a bad survival curve. Converters that make a resource from itself are a cycle, and the gate refuses them. Two counts of devices for one device are a fault (`endurance-devices`). A device with a limited converter and a converter with no limit is a warning (`endurance-device-mix`), because the converter with no limit uses no device-days. A draw with no way to get its need is a warning, and a cut with no curve is a warning. A bad season is a fault (`endurance-season`). Bad shares `monthly` are a fault (`endurance-monthly`). A converter that takes nothing is a fault, but for a source with a limit `perDay` more than 0. A converter with a season is not part of a cycle, because its harvest comes after its sowing.
package/build/add-on.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { u as EnduranceLayer } from "./layer-BCQy77mt.js";
1
+ import { u as EnduranceLayer } from "./layer-CsVKqL3L.js";
2
2
  import { StackJoiner } from "@mark1russell7/system-stack";
3
3
  /**
4
4
  * This function gives the endurance add-on.
package/build/add-on.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as checkEndurance, t as joinEndurance } from "./join-D4KzcbbY.js";
1
+ import { r as checkEndurance, t as joinEndurance } from "./join-BB1qLU4e.js";
2
2
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
3
3
  import { parseEndurance } from "./schema.js";
4
4
  // src/add-on.ts
package/build/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
- import { _ as Season, a as DirectUse, c as ENDURANCE_SCHEMA, d as Gift, f as Harvest, g as Resource, h as Prior, i as CutBound, l as Endurance, m as MonthDay, n as Converter, o as Draw, p as IsoDate, r as Cut, s as DrawEndurance, t as CaseCuts, u as EnduranceLayer, v as Store, y as Survival } from "./layer-BCQy77mt.js";
1
+ import { _ as Season, a as DirectUse, c as ENDURANCE_SCHEMA, d as Gift, f as Harvest, g as Resource, h as Prior, i as CutBound, l as Endurance, m as MonthDay, n as Converter, o as Draw, p as IsoDate, r as Cut, s as DrawEndurance, t as CaseCuts, u as EnduranceLayer, v as Store, y as Survival } from "./layer-CsVKqL3L.js";
2
2
  import { CutBound as CutBound$1, Fault, LayerParse, LayerPiece, PathOptions, Stack, curveFault, survivalAt } from "@mark1russell7/system-stack";
3
+ /**
4
+ * This function tells if a converter is a source (M2-solar): it takes nothing, and it has a limit `perDay` more than 0.
5
+ * Its runs of a day are lost when no draw uses them. Thus a take uses a source before a store.
6
+ */
7
+ export declare function isSource(converter: Converter): boolean;
3
8
  /** The options of the queries of a case. */
4
9
  export interface CaseOptions {
5
10
  /** The date of the query. A store whose due date is on this date or before it gives nothing. */
@@ -9,13 +14,14 @@ export interface CaseOptions {
9
14
  /** The `id` of more parts that are down, with the cuts of the case. */
10
15
  readonly down?: readonly string[] | undefined;
11
16
  /**
12
- * The first day of the event, for the sow days of each converter with a season (M2-grow). The default is `at`. The
17
+ * The first day of the event, for the sow days of each converter with a season (M2-grow) and the months of the shares
18
+ * `monthly` (M2-solar). The default is `at`. The
13
19
  * stores are the stores at `at`. Thus a query can move the event in the year and keep the stores.
14
20
  */
15
21
  readonly start?: IsoDate | undefined;
16
22
  /**
17
- * The horizon in days, more than 0. A layer with no converter with a season does not use it in `enduranceOf`. With
18
- * such a converter, the query reads the sowings up to the horizon, and a draw holds the horizon at most. The default
23
+ * The horizon in days, more than 0. A layer with no converter with a season, shares `monthly` or a source does not use
24
+ * 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
19
25
  * is `SEASON_HORIZON_DAYS`.
20
26
  */
21
27
  readonly horizon?: number | undefined;
@@ -27,6 +33,17 @@ export declare const SEASON_HORIZON_DAYS = 730;
27
33
  * With a stack, it also gives each part that stops.
28
34
  */
29
35
  export declare function caseStopped(caseCuts: CaseCuts, options: Pick<CaseOptions, "stack" | "down">): Set<string>;
36
+ /** 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. */
37
+ export declare function monthOf(start: IsoDate, day: number): number;
38
+ /**
39
+ * This function gives the days from the start to the first day of each month, in increasing order (M2-solar). Each
40
+ * day is more than 0 and less than the horizon. It throws a `RangeError` for a date that is not `YYYY-MM-DD`.
41
+ */
42
+ export declare function monthEdges(start: IsoDate, horizon: number): number[];
43
+ /** This function gives the shares `monthly` of each device key of the converters with a limit and shares (M2-solar). */
44
+ export declare function monthlyShares(converters: Iterable<Converter>): Map<string, readonly number[]>;
45
+ /** This function gives the share of the device-days of a key in a month: its share `monthly`, or 1. */
46
+ export declare function shareOf(shares: ReadonlyMap<string, readonly number[]>, key: string, month: number): number;
30
47
  /**
31
48
  * This function gives the amount of each resource in the stores at a date, by the code of the resource.
32
49
  *
@@ -69,13 +86,19 @@ export interface SeasonSupply {
69
86
  readonly lots: readonly HarvestLot[];
70
87
  /** The horizon in days (`horizon` of the options, default `SEASON_HORIZON_DAYS`). */
71
88
  readonly horizon: number;
89
+ /** 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). */
90
+ readonly start: IsoDate;
72
91
  }
73
92
  /**
74
93
  * This function gives the supply of a case with a season (M2-grow-share). `enduranceOf`, `bestEndurance` and `jointDays`
75
94
  * 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`.
76
95
  */
77
96
  export declare function seasonSupply(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>, options: CaseOptions): SeasonSupply;
78
- /** This function tells if a layer has a converter with a season that can run in a case. */
97
+ /**
98
+ * This function tells if a layer has a converter with a season, with shares `monthly` or a source (M2-solar) that can run
99
+ * 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
100
+ * month end a segment. A source can feed a draw with no end, thus the horizon is the upper limit of its days.
101
+ */
79
102
  export declare function hasSeason(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): boolean;
80
103
  /**
81
104
  * This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.
@@ -103,7 +126,11 @@ export declare function hasSeason(layer: EnduranceLayer, stoppedParts: ReadonlyS
103
126
  * - With a season, each draw takes its stocks over spans from harvest to harvest. `days` is the first stop of the
104
127
  * draw. A later harvest can feed the draw again: `again` gives these spans, and `takes` is the sum to the horizon.
105
128
  * A lower draw gets the stocks that the higher draws leave, the earliest stocks first taken. This is the safe side.
106
- * - A draw with a shared device and a season gets a `RangeError` (M2-grow-share).
129
+ * - A draw with a shared device and a season gets the programs of `bestEndurance` for itself alone (M2-grow-share-sweep). Its stocks,
130
+ * its harvest lots and its device-days are those that the higher draws leave. It has no field `spoiled`.
131
+ * - 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
132
+ * draw uses them. With shares `monthly`, the device-days of a day are the devices times the share of its month. Each
133
+ * span also ends at the start of a month, and a draw can hold again from the start of a month.
107
134
  *
108
135
  * 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.
109
136
  *
@@ -613,7 +640,8 @@ export declare function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, o
613
640
  * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.
614
641
  * - `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.
615
642
  * - `endurance-date`: a date is not a date `YYYY-MM-DD`.
616
- * - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.
643
+ * - `endurance-converter-empty`: a converter takes nothing and has no limit `perDay` more than 0, or it gives an amount of 0.
644
+ * A converter with a limit can take nothing: it is a source, for example a solar panel. Since 0.8.20 (M2-solar).
617
645
  * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.
618
646
  * Or its days do not increase, or its chance increases.
619
647
  * - `endurance-bound`: the bound of a cut is not a value of `CUT_BOUNDS` of the core. Since 0.8.4.
@@ -627,8 +655,10 @@ export declare function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, o
627
655
  * - `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.
628
656
  * 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
629
657
  * `perDay` or `devices`. Since 0.8.16 (M2-grow).
658
+ * - `endurance-monthly`: the shares `monthly` of a converter are not 12 numbers from 0 to 1. Or the converter has
659
+ * `monthly` and no `perDay`, or a season. Or two converters of one device have different shares. Since 0.8.20 (M2-solar).
630
660
  */
631
- export declare const ENDURANCE_CODES: readonly ["endurance-twice", "endurance-level-unknown", "endurance-resource-unknown", "endurance-part-unknown", "endurance-range", "endurance-date", "endurance-converter-empty", "endurance-curve", "endurance-bound", "endurance-prior-case", "endurance-cycle", "endurance-devices", "endurance-device-mix", "endurance-no-way", "endurance-cut-no-curve", "endurance-season"];
661
+ export declare const ENDURANCE_CODES: readonly ["endurance-twice", "endurance-level-unknown", "endurance-resource-unknown", "endurance-part-unknown", "endurance-range", "endurance-date", "endurance-converter-empty", "endurance-curve", "endurance-bound", "endurance-prior-case", "endurance-cycle", "endurance-devices", "endurance-device-mix", "endurance-no-way", "endurance-cut-no-curve", "endurance-season", "endurance-monthly"];
632
662
  /** A code of `ENDURANCE_CODES`. */
633
663
  export type EnduranceCode = (typeof ENDURANCE_CODES)[number];
634
664
  /** A fault of the gate of an endurance layer. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAUiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;WAKA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;wBAyKxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;;;;;wBAOK,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;wBAa9F,UAAU,OAAO,gBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuC/C,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBCta7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;WAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;iBCpDrG,oBAAoB;;;;;;WAM1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkEK,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBCjFhF,SAAS,OAAO,UAAU,cAAc;;;;;;;;;wBAoBxC,SAAS,OA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OAAO,gBAAgB,eAAe,SAAS,uBAAuB;;YA0ExF,iBAAiB;;iBAGZ;;WAEN;;WAEA;;WAEA;;;iBAIM;WACN,OAAO;WACP,WAAW;;;;;;;iBAQL;WACN,SAAS;WACT,QAAQ;;;iBAIF;WACN;WACA;WACA;WACA;;WAEA;;WAEA;;;;;;WAMA,OAAO;;WAEP,WAAW;;WAEX,OAAOA;;WAEP;;;;;WAKA,OAAO;;;iBAID;WACN;WACA;WACA;WACA,OAAO;;WAEP;;WAEA,gBAAgB;;WAEhB;;WAEA;;WAEA,OAAOA;;;;;;;;;;;;;;;;wBAiBF,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;qBCzzBpF;;YAqCD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBA6KtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBC9OnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
1
+ {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAA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;WAEhB;;WAEA;;WAEA,OAAOA;;;;;;;;;;;;;;;;wBAiBF,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBCtzBpF;;YAuCD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBA2MtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBCjRnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
package/build/index.js CHANGED
@@ -1,426 +1,9 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
- import { C as reachOf, D as exact, E as dense, S as partsOf, T as addTo, _ as Program, a as hasEnduranceError, b as drawBlock, c as caseStopped, d as giftNeed, f as giftResource, g as storeAmounts, h as sowDays, i as curveFault, l as drawDemand, m as seasonSupply, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as caseParts, w as valueAt, x as fewestRow, y as deviceUse } from "./join-D4KzcbbY.js";
2
+ import { A as drawBlock, C as fixStops, D as Program, E as seasonPlan, F as dense, I as exact, L as isSource, M as reachOf, N as valueAt, O as caseParts, P as addTo, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as fewestRow, k as deviceUse, l as drawDemand, m as monthEdges, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as shareOf, w as seasonBest, x as fewestOpen, y as sowDays } from "./join-BB1qLU4e.js";
3
3
  import { DEFAULT_MAX_SETS, STACK_SCHEMA, dateOfDay, dayNumber, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
4
4
  import { ONE, ZERO, add, div, equals, mul, neg, sign, sub, toNumber } from "@mark1russell7/rational";
5
5
  import { solveLexicographic } from "@mark1russell7/linear";
6
6
  import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
7
- // src/seasonal.ts
8
- /**
9
- * This function gives the parts of the programs of a case with a season. `parts` are the parts of the case with the
10
- * stock after the sowings (`seasonSupply`).
11
- */
12
- function seasonPlan(supply, parts, caseCuts, draws, devices) {
13
- const total = new Map(supply.stock);
14
- const harvests = supply.lots.filter((lot) => parts.resources.has(lot.resource));
15
- for (const lot of harvests) total.set(lot.resource, (total.get(lot.resource) ?? 0) + lot.amount);
16
- const all = partsOf(total, parts.direct, parts.cooks, parts.makers);
17
- const lots = [...all.stocked.filter((resource) => (supply.stock.get(resource) ?? 0) > 0).map((resource) => ({
18
- resource,
19
- day: 0,
20
- spoils: 1e400,
21
- amount: exact(supply.stock.get(resource) ?? 0)
22
- })), ...harvests.map((lot) => ({
23
- resource: lot.resource,
24
- day: Math.max(0, lot.day),
25
- spoils: lot.spoils,
26
- amount: exact(lot.amount)
27
- }))];
28
- const inside = (day) => day > 0 && day < supply.horizon;
29
- return {
30
- parts: all,
31
- caseCuts,
32
- draws,
33
- devices,
34
- lots,
35
- edges: [.../* @__PURE__ */ new Set([
36
- 0,
37
- supply.horizon,
38
- ...lots.flatMap((lot) => [lot.day, lot.spoils]).filter(inside)
39
- ])].sort((a, b) => a - b)
40
- };
41
- }
42
- const edgeOf = (plan, index) => exact(plan.edges[index] ?? 0);
43
- const lengthOf = (plan, index) => sub(edgeOf(plan, index + 1), edgeOf(plan, index));
44
- const segmentsOf = (plan) => plan.edges.length - 1;
45
- /** 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. */
46
- function fixedFed(plan, fix, segment) {
47
- if (segment < fix.segment) return lengthOf(plan, segment);
48
- if (segment === fix.segment) return sub(fix.stop, edgeOf(plan, segment));
49
- return ZERO;
50
- }
51
- /**
52
- * 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.
53
- * The share of each stock is the sum of the takes of the lots that are ready and not spoiled in the whole segment.
54
- */
55
- function addCell(program, plan, draw, segment, fed) {
56
- const block = drawBlock(program, plan.parts, draw);
57
- const demand = exact(drawDemand(draw, plan.caseCuts));
58
- const need = new Map(block.gifts);
59
- if (typeof fed === "number") {
60
- addTo(need, fed, neg(demand));
61
- program.push(need, ">=", ZERO);
62
- } else program.push(need, ">=", mul(demand, fed));
63
- const from = plan.edges[segment] ?? 0;
64
- const to = plan.edges[segment + 1] ?? 1e400;
65
- const takes = /* @__PURE__ */ new Map();
66
- for (const [resource, share] of block.shares) {
67
- const row = /* @__PURE__ */ new Map([[share, ONE]]);
68
- for (const lot of plan.lots) {
69
- if (lot.resource !== resource || lot.day > from || lot.spoils < to) continue;
70
- const column = program.next();
71
- takes.set(lot, column);
72
- addTo(row, column, neg(ONE));
73
- }
74
- program.push(row, "=", ZERO);
75
- }
76
- return {
77
- draw,
78
- segment,
79
- block,
80
- fed,
81
- takes
82
- };
83
- }
84
- /** This function adds the row of each lot: the takes of all the cells are not more than its amount. */
85
- function lotRows(program, plan, cells) {
86
- for (const lot of plan.lots) {
87
- const row = /* @__PURE__ */ new Map();
88
- for (const cell of cells) {
89
- const column = cell.takes.get(lot);
90
- if (column !== void 0) addTo(row, column, ONE);
91
- }
92
- if (row.size > 0) program.push(row, "<=", lot.amount);
93
- }
94
- }
95
- /**
96
- * 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
97
- * 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.
98
- */
99
- function addFixed(program, plan, fixed, cells) {
100
- const kept = /* @__PURE__ */ new Map();
101
- for (const draw of plan.draws) {
102
- const fix = fixed.get(draw.need);
103
- if (fix === void 0) continue;
104
- for (let segment = 0; segment <= fix.segment; segment += 1) {
105
- const fed = fixedFed(plan, fix, segment);
106
- const keep = fix.keep.get(segment) ?? /* @__PURE__ */ new Map();
107
- const into = kept.get(segment) ?? /* @__PURE__ */ new Map();
108
- kept.set(segment, into);
109
- for (const [key, value] of keep) into.set(key, add(into.get(key) ?? ZERO, value));
110
- if (sign(fed) <= 0) continue;
111
- const cell = addCell(program, plan, draw, segment, fed);
112
- cells.push(cell);
113
- const { limits, stopped } = deviceUse(cell.block.runs);
114
- for (const index of stopped) program.push(/* @__PURE__ */ new Map([[index, ONE]]), "<=", ZERO);
115
- for (const [key, limit] of limits) program.push(limit.row, "<=", mul(keep.get(key) ?? ZERO, fed));
116
- }
117
- }
118
- return kept;
119
- }
120
- /** This function gives the device-days of each day that the fixed draws leave in a segment. */
121
- function roomOf(plan, kept, segment, key, devices) {
122
- const left = sub(exact(plan.devices.get(key) ?? devices), kept.get(segment)?.get(key) ?? ZERO);
123
- return sign(left) > 0 ? left : ZERO;
124
- }
125
- /**
126
- * This function gives the program of one step with the stop of the open draws in segment `segment`. The open draws are fed in
127
- * each segment before it. In it, each one is fed for `t - edge` days or more, and their runs share the device-days that
128
- * the fixed draws leave, for `t - edge` days. This is the safe side, as in `bestEndurance`.
129
- */
130
- function buildStep$1(plan, fixed, open, segment) {
131
- const program = new Program();
132
- const t = program.next();
133
- program.push(/* @__PURE__ */ new Map([[t, ONE]]), "<=", edgeOf(plan, segment + 1));
134
- const cells = [];
135
- const kept = addFixed(program, plan, fixed, cells);
136
- const opened = new Set(open.map((draw) => draw.need));
137
- const floors = /* @__PURE__ */ new Map();
138
- for (const draw of plan.draws) {
139
- if (!opened.has(draw.need)) continue;
140
- for (let index = 0; index < segment; index += 1) cells.push(addCell(program, plan, draw, index, lengthOf(plan, index)));
141
- const fed = program.next();
142
- program.push(/* @__PURE__ */ new Map([[fed, ONE]]), "<=", lengthOf(plan, segment));
143
- floors.set(draw.need, program.push(/* @__PURE__ */ new Map([[fed, ONE], [t, neg(ONE)]]), ">=", neg(edgeOf(plan, segment))));
144
- cells.push(addCell(program, plan, draw, segment, fed));
145
- }
146
- const shared = /* @__PURE__ */ new Map();
147
- for (let index = 0; index <= segment; index += 1) {
148
- const { limits, stopped } = deviceUse(cells.filter((cell) => cell.segment === index && opened.has(cell.draw.need)).flatMap((cell) => [...cell.block.runs]));
149
- for (const column of stopped) program.push(/* @__PURE__ */ new Map([[column, ONE]]), "<=", ZERO);
150
- const bySegment = /* @__PURE__ */ new Map();
151
- shared.set(index, bySegment);
152
- for (const [key, limit] of limits) {
153
- const room = roomOf(plan, kept, index, key, limit.devices);
154
- bySegment.set(key, {
155
- row: limit.row,
156
- room,
157
- converters: limit.converters
158
- });
159
- const row = new Map(limit.row);
160
- if (index < segment) program.push(row, "<=", mul(room, lengthOf(plan, index)));
161
- else {
162
- addTo(row, t, neg(room));
163
- program.push(row, "<=", neg(mul(room, edgeOf(plan, segment))));
164
- }
165
- }
166
- }
167
- lotRows(program, plan, cells);
168
- return {
169
- program,
170
- t,
171
- cells,
172
- floors,
173
- shared,
174
- segment
175
- };
176
- }
177
- /**
178
- * This function gives the largest common first stop of the open draws, with the fixed draws at their stops. The days to
179
- * a first stop are not a linear function of the takes, so the function tries the segments in order. When the days reach
180
- * the end of a segment, it tries the next segment. The days of the last step are exact.
181
- * After the largest days, the step takes the objectives of `tail`.
182
- */
183
- function firstStop(plan, fixed, open, tail = () => []) {
184
- const segments = segmentsOf(plan);
185
- for (let segment = 0; segment < segments; segment += 1) {
186
- const step = buildStep$1(plan, fixed, open, segment);
187
- const most = {
188
- sense: "max",
189
- coefficients: dense(/* @__PURE__ */ new Map([[step.t, ONE]]), step.program.count)
190
- };
191
- const solved = solveLexicographic(step.program.constraints(), [most]);
192
- 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.");
193
- const days = solved.values[0] ?? ZERO;
194
- const end = edgeOf(plan, segment + 1);
195
- if (segment + 1 < segments && equals(days, end)) continue;
196
- const full = tail(step).length === 0 ? solved : solveLexicographic(step.program.constraints(), [most, ...tail(step)]);
197
- if (full.status !== "optimal") throw new Error("The step of a season has no optimum for its later objectives.");
198
- const first = full.stages[0]?.result;
199
- return {
200
- step,
201
- x: full.x,
202
- dual: first?.status === "optimal" ? first.dual : [],
203
- days,
204
- atHorizon: segment + 1 === segments && equals(days, end)
205
- };
206
- }
207
- throw new Error("A season plan has no segment.");
208
- }
209
- /** This function gives the fewest device-days of the runs of the open cells of a step, as an objective. */
210
- function fewestOpen(step, open) {
211
- return {
212
- sense: "min",
213
- coefficients: dense(fewestRow(step.cells.filter((cell) => open.has(cell.draw.need)).flatMap((cell) => [...cell.block.runs])), step.program.count)
214
- };
215
- }
216
- /** This function gives the smallest sum of the shares of the stocks, each over the total of its lots, as an objective. */
217
- function leastShares(plan, cells, count) {
218
- const least = /* @__PURE__ */ new Map();
219
- for (const cell of cells) for (const [resource, index] of cell.block.shares) addTo(least, index, div(ONE, exact(plan.parts.stock.get(resource) ?? 1)));
220
- return {
221
- sense: "min",
222
- coefficients: dense(least, count)
223
- };
224
- }
225
- /** This function fixes the open draws of `done` at the stop: the device-days of each day that they keep, and their capped converters. */
226
- function fixStops(plan, stop, done, fixed) {
227
- const { step, x, days } = stop;
228
- const fedIn = (segment) => segment < step.segment ? lengthOf(plan, segment) : sub(days, edgeOf(plan, step.segment));
229
- const full = /* @__PURE__ */ new Set();
230
- for (const [segment, bySegment] of step.shared) for (const [key, limit] of bySegment) if (equals(valueAt(limit.row, x), mul(limit.room, fedIn(segment)))) full.add(`${String(segment)}\u0000${key}`);
231
- for (const draw of done) {
232
- const keep = /* @__PURE__ */ new Map();
233
- const used = /* @__PURE__ */ new Set();
234
- for (const cell of step.cells) {
235
- if (cell.draw.need !== draw.need) continue;
236
- const fed = fedIn(cell.segment);
237
- const bySegment = /* @__PURE__ */ new Map();
238
- keep.set(cell.segment, bySegment);
239
- for (const [key, limit] of deviceUse(cell.block.runs).limits) {
240
- bySegment.set(key, sign(fed) > 0 ? div(valueAt(limit.row, x), fed) : ZERO);
241
- if (full.has(`${String(cell.segment)}\u0000${key}`)) for (const converter of limit.converters) used.add(converter);
242
- }
243
- }
244
- const { reach } = reachOf(plan.parts, /* @__PURE__ */ new Set([draw.need]));
245
- const capped = sign(days) > 0 ? [...reach].filter((converter) => converter.perDay !== void 0 && (!(converter.perDay > 0) || used.has(converter))).map((converter) => converter.id).sort() : [];
246
- fixed.set(draw.need, {
247
- stop: days,
248
- segment: step.segment,
249
- keep,
250
- atHorizon: stop.atHorizon,
251
- capped
252
- });
253
- }
254
- }
255
- /** This function gives the sum of the take of each resource of the cells of one need, more than 0 only. */
256
- function takesOf(cells, need, x) {
257
- const sums = /* @__PURE__ */ new Map();
258
- for (const cell of cells) {
259
- if (cell.draw.need !== need) continue;
260
- for (const [resource, index] of cell.block.shares) sums.set(resource, add(sums.get(resource) ?? ZERO, x[index] ?? ZERO));
261
- }
262
- const out = {};
263
- for (const [resource, value] of [...sums].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) if (sign(value) > 0) out[resource] = toNumber(value);
264
- return out;
265
- }
266
- /** 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. */
267
- function usedUp(plan, cells, x, closure, stored) {
268
- return [...closure].filter((resource) => stored.has(resource)).filter((resource) => {
269
- let taken = ZERO;
270
- let amount = ZERO;
271
- for (const lot of plan.lots) {
272
- if (lot.resource !== resource) continue;
273
- amount = add(amount, lot.amount);
274
- for (const cell of cells) taken = add(taken, x[cell.takes.get(lot) ?? -1] ?? ZERO);
275
- }
276
- return equals(taken, amount);
277
- }).sort();
278
- }
279
- /** This function tells if the cells of two draws or more of `cells` can use the limited device `key`. */
280
- function sharedKey(cells, key) {
281
- return new Set(cells.filter((cell) => deviceUse(cell.block.runs).limits.has(key)).map((cell) => cell.draw.need)).size > 1;
282
- }
283
- /**
284
- * This function gives the last program of the best endurance with a season. Each draw keeps its first stop. After it, a later
285
- * harvest can feed the draw again (`again`). The objectives come in this order:
286
- * - the most fed days after the stops for each level, in the order of the levels.
287
- * - the earliest fed days.
288
- * - the smallest sum of the shares of the stocks.
289
- * - the fewest device-days.
290
- *
291
- * In a segment after the stops, the cells of two draws or more that can use one limited device take turns. Their fed days
292
- * together are not more than the segment, and each one has the device-days of each day that the stops leave. This is the
293
- * safe side: the cells do not use one device at the same time. Each other cell starts at the start of the segment.
294
- */
295
- function seasonBest(plan, fixed, levels, stored) {
296
- const program = new Program();
297
- const cells = [];
298
- const kept = addFixed(program, plan, fixed, cells);
299
- const segments = segmentsOf(plan);
300
- const again = /* @__PURE__ */ new Map();
301
- const taking = /* @__PURE__ */ new Set();
302
- for (const draw of plan.draws) {
303
- const fix = fixed.get(draw.need);
304
- for (let segment = fix.segment + 1; segment < segments; segment += 1) {
305
- const fed = program.next();
306
- program.push(/* @__PURE__ */ new Map([[fed, ONE]]), "<=", lengthOf(plan, segment));
307
- const cell = addCell(program, plan, draw, segment, fed);
308
- cells.push(cell);
309
- again.set(cell, fed);
310
- }
311
- }
312
- for (let segment = 0; segment < segments; segment += 1) {
313
- const later = [...again.keys()].filter((cell) => cell.segment === segment);
314
- const { limits, stopped } = deviceUse(later.flatMap((cell) => [...cell.block.runs]));
315
- for (const column of stopped) program.push(/* @__PURE__ */ new Map([[column, ONE]]), "<=", ZERO);
316
- const turns = new Set(later.filter((cell) => [...deviceUse(cell.block.runs).limits.keys()].some((key) => sharedKey(later, key))));
317
- if (turns.size > 0) {
318
- const row = /* @__PURE__ */ new Map();
319
- for (const cell of turns) addTo(row, again.get(cell), ONE);
320
- program.push(row, "<=", lengthOf(plan, segment));
321
- for (const cell of turns) taking.add(cell);
322
- }
323
- for (const [key, limit] of limits) {
324
- const room = roomOf(plan, kept, segment, key, limit.devices);
325
- for (const cell of later) {
326
- const own = deviceUse(cell.block.runs).limits.get(key);
327
- if (own === void 0) continue;
328
- const row = new Map(own.row);
329
- addTo(row, again.get(cell), neg(room));
330
- program.push(row, "<=", ZERO);
331
- }
332
- }
333
- }
334
- lotRows(program, plan, cells);
335
- const objectives = levels.map((level) => {
336
- const needs = new Set(level.map((draw) => draw.need));
337
- const row = /* @__PURE__ */ new Map();
338
- for (const [cell, fed] of again) if (needs.has(cell.draw.need)) addTo(row, fed, ONE);
339
- return {
340
- sense: "max",
341
- coefficients: dense(row, program.count)
342
- };
343
- });
344
- const early = /* @__PURE__ */ new Map();
345
- const horizon = edgeOf(plan, segments);
346
- for (const [cell, fed] of again) addTo(early, fed, sub(horizon, edgeOf(plan, cell.segment)));
347
- objectives.push({
348
- sense: "max",
349
- coefficients: dense(early, program.count)
350
- });
351
- objectives.push(leastShares(plan, cells, program.count));
352
- objectives.push({
353
- sense: "min",
354
- coefficients: dense(fewestRow(cells.flatMap((cell) => [...cell.block.runs])), program.count)
355
- });
356
- const solved = solveLexicographic(program.constraints(), objectives);
357
- 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.");
358
- const x = solved.x;
359
- const turn = /* @__PURE__ */ new Map();
360
- const offset = /* @__PURE__ */ new Map();
361
- for (const cell of [...taking].sort((a, b) => plan.draws.indexOf(a.draw) - plan.draws.indexOf(b.draw))) {
362
- const start = offset.get(cell.segment) ?? ZERO;
363
- turn.set(cell, start);
364
- offset.set(cell.segment, add(start, x[again.get(cell)] ?? ZERO));
365
- }
366
- const needs = {};
367
- for (const draw of plan.draws) {
368
- const fix = fixed.get(draw.need);
369
- const spans = [];
370
- for (const [cell, fed] of again) {
371
- if (cell.draw.need !== draw.need) continue;
372
- const value = x[fed] ?? ZERO;
373
- if (sign(value) <= 0) continue;
374
- const start = add(edgeOf(plan, cell.segment), taking.has(cell) ? turn.get(cell) ?? ZERO : ZERO);
375
- const from = toNumber(start);
376
- const to = toNumber(add(start, value));
377
- const last = spans[spans.length - 1];
378
- if (last !== void 0 && last.to === from) last.to = to;
379
- else spans.push({
380
- from,
381
- to
382
- });
383
- }
384
- const { closure } = reachOf(plan.parts, /* @__PURE__ */ new Set([draw.need]));
385
- needs[draw.need] = {
386
- days: toNumber(fix.stop),
387
- binding: usedUp(plan, cells, x, closure, stored),
388
- takes: takesOf(cells, draw.need, x),
389
- ...fix.capped.length === 0 ? {} : { capped: fix.capped },
390
- ...fix.atHorizon ? { atHorizon: true } : {},
391
- ...spans.length === 0 ? {} : { again: spans }
392
- };
393
- }
394
- return { needs };
395
- }
396
- /**
397
- * This function gives the joint days of the draws of a plan with a season. The objectives come in this order:
398
- * - the largest common first stop.
399
- * - the smallest sum of the shares of the stocks.
400
- * - the fewest device-days.
401
- */
402
- function seasonJoint(plan, stored) {
403
- const open = new Set(plan.draws.map((draw) => draw.need));
404
- const stop = firstStop(plan, /* @__PURE__ */ new Map(), plan.draws, (step) => [leastShares(plan, step.cells, step.program.count), fewestOpen(step, open)]);
405
- const { step, x } = stop;
406
- const takes = {};
407
- for (const draw of plan.draws) takes[draw.need] = takesOf(step.cells, draw.need, x);
408
- const total = /* @__PURE__ */ new Map();
409
- 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));
410
- const runs = {};
411
- 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);
412
- const fixed = /* @__PURE__ */ new Map();
413
- fixStops(plan, stop, plan.draws, fixed);
414
- const capped = [...new Set([...fixed.values()].flatMap((fix) => fix.capped))].sort();
415
- return {
416
- days: toNumber(stop.days),
417
- atHorizon: stop.atHorizon,
418
- takes,
419
- binding: usedUp(plan, step.cells, x, reachOf(plan.parts, open).closure, stored),
420
- runs,
421
- capped
422
- };
423
- }
424
7
  // src/joint.ts
425
8
  /**
426
9
  * This function gives the joint days of a set of draws. These are the largest count of days `d` at which each draw holds `d` days.
@@ -480,7 +63,8 @@ function jointDays(layer, caseCuts, options, needs) {
480
63
  if (plan.length === 0) return endless;
481
64
  const parts = caseParts(layer, stoppedParts, stock, planned);
482
65
  if (supply !== void 0) {
483
- const { atHorizon, ...joint } = seasonJoint(seasonPlan(supply, parts, caseCuts, plan, new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0])).limits].map(([key, limit]) => [key, limit.devices]))), new Set(layer.stores.map((store) => store.resource)));
66
+ const devices = new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0])).limits].map(([key, limit]) => [key, limit.devices]));
67
+ const { atHorizon, ...joint } = seasonJoint(seasonPlan(supply, parts, caseCuts, plan, devices), new Set(layer.stores.map((store) => store.resource)));
484
68
  return {
485
69
  ...base,
486
70
  ...joint,
@@ -720,7 +304,8 @@ function bestSeason(layer, caseCuts, options, stoppedParts) {
720
304
  const supply = seasonSupply(layer, stoppedParts, options);
721
305
  const draws = caseDraws(layer, caseCuts, stoppedParts);
722
306
  const parts = caseParts(layer, stoppedParts, supply.stock, new Set(draws.map((draw) => draw.need)));
723
- const plan = seasonPlan(supply, parts, caseCuts, draws, new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0])).limits].map(([key, limit]) => [key, limit.devices])));
307
+ const devices = new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0])).limits].map(([key, limit]) => [key, limit.devices]));
308
+ const plan = seasonPlan(supply, parts, caseCuts, draws, devices);
724
309
  const harvests = supply.harvests.length === 0 ? {} : { harvests: supply.harvests };
725
310
  if (draws.length === 0) return {
726
311
  case: caseCuts.case,
@@ -1385,7 +970,7 @@ function caseShortfall(layer, caseCuts, endurance, options = {}) {
1385
970
  /** The shares, with the default first. */
1386
971
  const SHARES = ["take", "best"];
1387
972
  /** This function gives the share of the options. The default is `take`. */
1388
- function shareOf(options) {
973
+ function shareOf$1(options) {
1389
974
  const share = options.share ?? "take";
1390
975
  if (!SHARES.includes(share)) throw new RangeError(`The share ${String(options.share)} is not ${SHARES.join(" or ")}.`);
1391
976
  return share;
@@ -1416,7 +1001,7 @@ const YEAR_STARTS = 12;
1416
1001
  function yearShortfall(layer, place, options) {
1417
1002
  horizonOf(options);
1418
1003
  budgetsOf(options);
1419
- const share = shareOf(options);
1004
+ const share = shareOf$1(options);
1420
1005
  const dates = startDates(layer, options);
1421
1006
  const levels = zeroLevels(layer);
1422
1007
  const independent = zeroLevels(layer);
@@ -1557,7 +1142,7 @@ function addDays(days, shortfall, count) {
1557
1142
  function caseOutlook(layer, caseCuts, options) {
1558
1143
  const horizon = horizonOf(options);
1559
1144
  budgetsOf(options);
1560
- const share = shareOf(options);
1145
+ const share = shareOf$1(options);
1561
1146
  const endurance = shareEndurance(layer, caseCuts, options, share);
1562
1147
  const stopped = caseDraws(layer, caseCuts, caseStopped(caseCuts, options));
1563
1148
  const stoppedNeeds = new Set(stopped.map((draw) => draw.need));
@@ -1857,6 +1442,6 @@ const SAMPLE_ENDURANCE = {
1857
1442
  asOf: "2025-12-01"
1858
1443
  }]
1859
1444
  };
1860
- export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, joinEndurance, jointDays, longestStop, minimalStops, seasonSupply, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
1445
+ export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, isSource, joinEndurance, jointDays, longestStop, minimalStops, monthEdges, monthOf, monthlyShares, seasonSupply, shareOf, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
1861
1446
 
1862
1447
  //# sourceMappingURL=index.js.map