@mark1russell7/stack-endurance 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/build/index.d.ts +34 -13
- package/build/index.d.ts.map +1 -1
- package/build/index.js +156 -37
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,9 +53,9 @@ The cuts of one case come from one event. `levels` takes each cut longer togethe
|
|
|
53
53
|
|
|
54
54
|
`independent` is the shortfall when the cuts are independent (`independentStop`). At each time, the supply is stopped when the cuts that are still on contain a minimal set. The query adds the chance of each such state of the cuts. A stop of two cuts in series is then `1 - (1 - s1)(1 - s2)`, and a stop through a need of `any` of two parts is `s1 * s2`. `independent` is not more than `upper`. Between two bend times the chance is not linear, so the curve has more points, each within `1e-6` of the chance.
|
|
55
55
|
|
|
56
|
-
Only the cuts of the supply, and of the parts that it needs through the stack, count. With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core, with the cut parts as `among`). Thus a case with more than 12 such cuts has exact sets. When that search passes its budget, the query examines each set of 12 cuts or fewer. With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` names the need.
|
|
56
|
+
Only the cuts of the supply, and of the parts that it needs through the stack, count. With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core, with the cut parts as `among`). Thus a case with more than 12 such cuts has exact sets. When that search passes its budget, the query examines each set of 12 cuts or fewer. The option `maxSets` sets the budget: the largest count of sets in one step of the search. The default is 4096. With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` names the need.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Two groups of cuts that share no minimal set are independent, so the independent stop takes the product over the groups. In a group of up to 12 cuts, it adds the chance of each state of the cuts. In a larger group, it uses the Shannon expansion of `pathSetReliability` (`@mark1russell7/collections`). The expansion merges two states with the same sets left, so sets with few shared cuts give a small expansion. The expansion is exponential in the worst case. The groups share one budget, `INDEPENDENT_MAX_WORK`, and the option `maxWork` changes it. When the expansions pass the budget, `independent` is `upper`, and `independentUpper` names the need.
|
|
59
59
|
|
|
60
60
|
## The entries
|
|
61
61
|
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as Draw, c as Endurance, d as IsoDate, f as Prior, h as Survival, i as DirectUse, l as EnduranceLayer, m as Store, n as Converter, o as DrawEndurance, p as Resource, r as Cut, s as ENDURANCE_SCHEMA, t as CaseCuts, u as Gift } from "./layer-DnyqqdlU.js";
|
|
2
|
-
import { Fault, LayerParse, LayerPiece, Stack, curveFault } from "@mark1russell7/system-stack";
|
|
2
|
+
import { Fault, LayerParse, LayerPiece, PathOptions, Stack, curveFault } from "@mark1russell7/system-stack";
|
|
3
3
|
/** The options of the queries of a case. */
|
|
4
4
|
export interface CaseOptions {
|
|
5
5
|
/** The date of the query. A store whose due date is on this date or before it gives nothing. */
|
|
@@ -65,7 +65,15 @@ export declare function tailDays(curve: Survival, from: number, to?: number): nu
|
|
|
65
65
|
* With a horizon of `h` days, the shortfall counts only the first `h` days of each cut. A draw that holds `h` days has no shortfall.
|
|
66
66
|
* Thus a plan can aim at a target, for example 14 days and then 90 days.
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
/**
|
|
69
|
+
* The options of `stopCurves`. With a stack, `maxSets` is the budget of the search of the needs (`stopSets` of the core).
|
|
70
|
+
* When the search passes it, `minimalStops` gives the sets.
|
|
71
|
+
*/
|
|
72
|
+
export interface StopCurveOptions extends Pick<CaseOptions, "stack" | "down">, Pick<PathOptions, "maxSets"> {
|
|
73
|
+
/** The budget of `independentStop` for the curve of each draw, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`. */
|
|
74
|
+
readonly maxWork?: number | undefined;
|
|
75
|
+
}
|
|
76
|
+
export interface ShortfallOptions extends StopCurveOptions {
|
|
69
77
|
/** The horizon in days, more than 0. The default is no horizon. */
|
|
70
78
|
readonly horizon?: number | undefined;
|
|
71
79
|
}
|
|
@@ -103,7 +111,7 @@ export declare function eventStop(curves: readonly Survival[], stops: (cuts: rea
|
|
|
103
111
|
*/
|
|
104
112
|
export declare function longestStop(curves: readonly Survival[]): Survival;
|
|
105
113
|
/**
|
|
106
|
-
* The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop`
|
|
114
|
+
* The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop` adds the chance of each state.
|
|
107
115
|
* With a stack, `stopCurves` finds the minimal sets from the needs, so a larger count of cuts can have exact sets.
|
|
108
116
|
*/
|
|
109
117
|
export declare const MINIMAL_STOP_CUTS = 12;
|
|
@@ -124,6 +132,12 @@ export declare function minimalStops(count: number, stops: (cuts: readonly numbe
|
|
|
124
132
|
export declare function upperStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival;
|
|
125
133
|
/** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */
|
|
126
134
|
export declare const INDEPENDENT_TOLERANCE = 1e-6;
|
|
135
|
+
/**
|
|
136
|
+
* The default budget of `independentStop` for its groups of more than `MINIMAL_STOP_CUTS` cuts.
|
|
137
|
+
* The budget counts the steps of the expansion times the count of points of the curve.
|
|
138
|
+
* It is near the work of the sum over the states of 12 cuts.
|
|
139
|
+
*/
|
|
140
|
+
export declare const INDEPENDENT_MAX_WORK: number;
|
|
127
141
|
/**
|
|
128
142
|
* This function gives the curve of a stop of some cuts when the cuts are independent.
|
|
129
143
|
* At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.
|
|
@@ -138,13 +152,20 @@ export declare const INDEPENDENT_TOLERANCE = 1e-6;
|
|
|
138
152
|
* Thus `|f''| <= (sum |s'|)^2 - sum s'^2`, and the line of a piece of length `h` is within `h^2 |f''| / 8` of the chance.
|
|
139
153
|
* The count of pieces keeps each line within `INDEPENDENT_TOLERANCE`. With a margin of 10 %, the count of points is less than `n / sqrt(7.2 * INDEPENDENT_TOLERANCE)` plus the segments, for `n` cuts.
|
|
140
154
|
*
|
|
141
|
-
*
|
|
155
|
+
* - Up to `MINIMAL_STOP_CUTS` cuts in the sets, the function adds the chance of each of the 2 to the power of that count of states.
|
|
156
|
+
* - Two groups of cuts that share no set are independent, so the chance that the supply works is the product over the groups.
|
|
157
|
+
* For example, 20 stages of 2 feeds give 20 groups of 2 cuts.
|
|
158
|
+
* - In a group of more than `MINIMAL_STOP_CUTS` cuts, it uses the Shannon expansion of `pathSetReliability` of collections.
|
|
159
|
+
* The expansion merges two states with the same sets left, and it drops a set that holds another set.
|
|
160
|
+
* - The expansion is exponential in the worst case. The groups share one budget, `maxWork`.
|
|
161
|
+
* When the steps of the expansions times the count of points of the curve pass it, the result is `undefined`.
|
|
142
162
|
*
|
|
143
163
|
* @param curves - The curves of the cuts, each one good for `checkEndurance`
|
|
144
|
-
* @param sets - The minimal sets of the cuts. With `undefined`, as for
|
|
145
|
-
* @
|
|
164
|
+
* @param sets - The minimal sets of the cuts. With `undefined`, as for no minimal sets, the result is `undefined`. With no sets, it is `[[0, 0]]`
|
|
165
|
+
* @param maxWork - The budget of the expansions of the groups of more than `MINIMAL_STOP_CUTS` cuts, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`
|
|
166
|
+
* @throws RangeError when a curve does not end at a chance of 0, or for a bad `maxWork`
|
|
146
167
|
*/
|
|
147
|
-
export declare function independentStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival | undefined;
|
|
168
|
+
export declare function independentStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined, maxWork?: number): Survival | undefined;
|
|
148
169
|
/**
|
|
149
170
|
* The curves of the stop of a draw. `event` is for one event that makes each cut longer together, and `independent` is for independent cuts.
|
|
150
171
|
* `upper` is an upper limit for each dependence.
|
|
@@ -159,7 +180,7 @@ export interface StopCurves {
|
|
|
159
180
|
* With a stack, the search of the needs passed its budget. With no stack, more than `MINIMAL_STOP_CUTS` cuts count.
|
|
160
181
|
*/
|
|
161
182
|
readonly coarse: boolean;
|
|
162
|
-
/** This is true when `independent` is `upper`: `coarse` is true, or the
|
|
183
|
+
/** This is true when `independent` is `upper`: `coarse` is true, or the expansion of `independentStop` passed its budget. */
|
|
163
184
|
readonly independentUpper: boolean;
|
|
164
185
|
}
|
|
165
186
|
/**
|
|
@@ -169,13 +190,13 @@ export interface StopCurves {
|
|
|
169
190
|
* - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.
|
|
170
191
|
* - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.
|
|
171
192
|
* - With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core), so the count of cuts has no limit of `MINIMAL_STOP_CUTS`.
|
|
172
|
-
* When that search passes its budget, `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.
|
|
193
|
+
* When that search passes its budget (the option `maxSets`), `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.
|
|
173
194
|
* - A cut with no `duration` gives no curve when it is in a minimal set, or when the query has no minimal sets.
|
|
174
195
|
* - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.
|
|
175
196
|
* - With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` is true.
|
|
176
|
-
* - When the
|
|
197
|
+
* - When the expansion of `independentStop` passes its budget, `independent` is `upper`, and `independentUpper` is true.
|
|
177
198
|
*/
|
|
178
|
-
export declare function stopCurves(caseCuts: CaseCuts, draw: Draw, options?:
|
|
199
|
+
export declare function stopCurves(caseCuts: CaseCuts, draw: Draw, options?: StopCurveOptions): StopCurves | undefined;
|
|
179
200
|
/** The shortfall of each level, in user-days, and the draws that the query cannot read. */
|
|
180
201
|
export interface Shortfall {
|
|
181
202
|
/**
|
|
@@ -205,7 +226,7 @@ export interface Shortfall {
|
|
|
205
226
|
* @param caseCuts - The case
|
|
206
227
|
* @param endurance - The endurance of the case, from `enduranceOf`
|
|
207
228
|
* @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon
|
|
208
|
-
* @throws RangeError when the horizon is not a number more than 0
|
|
229
|
+
* @throws RangeError when the horizon is not a number more than 0, or `maxSets` is not a whole number from 1
|
|
209
230
|
*/
|
|
210
231
|
export declare function caseShortfall(layer: EnduranceLayer, caseCuts: CaseCuts, endurance: Endurance, options?: ShortfallOptions): Shortfall;
|
|
211
232
|
/** The shortfall of one year at one place, with the part of each case. */
|
|
@@ -230,7 +251,7 @@ export interface YearShortfall extends Shortfall {
|
|
|
230
251
|
* @param layer - The endurance layer, with its cases and priors
|
|
231
252
|
* @param place - The place of the priors
|
|
232
253
|
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
233
|
-
* @throws RangeError
|
|
254
|
+
* @throws RangeError for a bad date, horizon or `maxSets`: refer to `caseShortfall` and `enduranceOf`
|
|
234
255
|
*/
|
|
235
256
|
export declare function yearShortfall(layer: EnduranceLayer, place: string, options: CaseOptions & ShortfallOptions): YearShortfall;
|
|
236
257
|
/**
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/endurance.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAOiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,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;;;;;;;;;;;;;;;;;;;;wBAiKxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/endurance.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAOiB;;WAEN,IAAI;;WAE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A2B;aAAuB;aAAuB,WAAW;aAAoB,WAAW;;;;;;;;;;;;;;;;wBAgB9G,cAAc,OAAO,gBAAgB,eAAe,SAAS,cAAc,mBAAmB;;;;;;;;;;;;;;;;;;;qBChjBjG;;YA6BD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBAyHtD,kBAAkB,iBAAiB;;;;;;;;;;;;;wBChLnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCV5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
2
|
import { a as hasEnduranceError, c as drawDemand, d as giftResource, f as storeAmounts, i as curveFault, l as enduranceOf, n as ENDURANCE_CODES, o as caseDraws, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed } from "./join-BiG5NScO.js";
|
|
3
3
|
import { DEFAULT_MAX_SETS, STACK_SCHEMA, neededParts, stopSets } from "@mark1russell7/system-stack";
|
|
4
|
+
import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
4
5
|
// src/stops.ts
|
|
5
6
|
/**
|
|
6
7
|
* This function gives the minimal sets of cuts that stop a supply, from the paths of the needs of the stack (`stopSets` of the core).
|
|
@@ -9,14 +10,15 @@ import { DEFAULT_MAX_SETS, STACK_SCHEMA, neededParts, stopSets } from "@mark1rus
|
|
|
9
10
|
* - `parts` has the part of each cut that counts. Two cuts of one part are two cuts: each one stops what the part stops.
|
|
10
11
|
* - A cut of the supply stops it alone. The other sets come from `stopSets` with the cut parts as `among`, so no other part can fail.
|
|
11
12
|
* - The parts of `down` are down for the full event. The caller makes sure that they do not stop the supply with no cut.
|
|
12
|
-
* - The result is `undefined` when the search passes its budget, or when the sets of cuts are more than `
|
|
13
|
+
* - The result is `undefined` when the search passes its budget, or when the sets of cuts are more than `maxSets`.
|
|
13
14
|
*
|
|
14
15
|
* @param stack - The base stack
|
|
15
16
|
* @param supply - The part of the supply of a draw
|
|
16
17
|
* @param parts - The part of each cut that counts
|
|
17
18
|
* @param down - The parts that are down for the full event
|
|
19
|
+
* @param maxSets - The largest count of sets in one step of the search, and of the sets of cuts (`maxSets` of `stopSets`)
|
|
18
20
|
*/
|
|
19
|
-
function stackStops(stack, supply, parts, down = []) {
|
|
21
|
+
function stackStops(stack, supply, parts, down = [], maxSets = DEFAULT_MAX_SETS) {
|
|
20
22
|
const cutsOf = /* @__PURE__ */ new Map();
|
|
21
23
|
for (const [index, part] of parts.entries()) cutsOf.set(part, [...cutsOf.get(part) ?? [], index]);
|
|
22
24
|
const own = (cutsOf.get(supply) ?? []).map((index) => [index]);
|
|
@@ -24,7 +26,8 @@ function stackStops(stack, supply, parts, down = []) {
|
|
|
24
26
|
const found = stopSets(stack, supply, {
|
|
25
27
|
down,
|
|
26
28
|
among,
|
|
27
|
-
size: among.length
|
|
29
|
+
size: among.length,
|
|
30
|
+
maxSets
|
|
28
31
|
});
|
|
29
32
|
if (found.kind === "budget") return void 0;
|
|
30
33
|
if (found.sets.some((set) => set.length === 0)) return own;
|
|
@@ -33,7 +36,7 @@ function stackStops(stack, supply, parts, down = []) {
|
|
|
33
36
|
let choices = [[]];
|
|
34
37
|
for (const part of set) {
|
|
35
38
|
const cuts = cutsOf.get(part) ?? [];
|
|
36
|
-
if (choices.length * cuts.length + out.length >
|
|
39
|
+
if (choices.length * cuts.length + out.length > maxSets) return void 0;
|
|
37
40
|
choices = choices.flatMap((choice) => cuts.map((cut) => [...choice, cut]));
|
|
38
41
|
}
|
|
39
42
|
out.push(...choices.map((choice) => choice.sort((x, y) => x - y)));
|
|
@@ -85,6 +88,16 @@ function horizonOf(options) {
|
|
|
85
88
|
if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);
|
|
86
89
|
return horizon;
|
|
87
90
|
}
|
|
91
|
+
function budgetsOf(options) {
|
|
92
|
+
const maxSets = options.maxSets ?? DEFAULT_MAX_SETS;
|
|
93
|
+
if (!Number.isInteger(maxSets) || maxSets < 1) throw new RangeError(`The option maxSets is ${String(options.maxSets)}: it is not a whole number from 1.`);
|
|
94
|
+
const maxWork = options.maxWork ?? INDEPENDENT_MAX_WORK;
|
|
95
|
+
if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The option maxWork is ${String(options.maxWork)}: it is not a whole number from 1.`);
|
|
96
|
+
return {
|
|
97
|
+
maxSets,
|
|
98
|
+
maxWork
|
|
99
|
+
};
|
|
100
|
+
}
|
|
88
101
|
/**
|
|
89
102
|
* This function gives the days at which the chance of the curve falls to `chance`. With `0.1`, it is the 90th percentile of the duration.
|
|
90
103
|
* When the curve does not fall to `chance`, the result is `Infinity`.
|
|
@@ -170,7 +183,7 @@ function longestStop(curves) {
|
|
|
170
183
|
return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);
|
|
171
184
|
}
|
|
172
185
|
/**
|
|
173
|
-
* The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop`
|
|
186
|
+
* The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop` adds the chance of each state.
|
|
174
187
|
* With a stack, `stopCurves` finds the minimal sets from the needs, so a larger count of cuts can have exact sets.
|
|
175
188
|
*/
|
|
176
189
|
const MINIMAL_STOP_CUTS = 12;
|
|
@@ -223,6 +236,12 @@ function upperStop(curves, sets) {
|
|
|
223
236
|
/** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */
|
|
224
237
|
const INDEPENDENT_TOLERANCE = 1e-6;
|
|
225
238
|
/**
|
|
239
|
+
* The default budget of `independentStop` for its groups of more than `MINIMAL_STOP_CUTS` cuts.
|
|
240
|
+
* The budget counts the steps of the expansion times the count of points of the curve.
|
|
241
|
+
* It is near the work of the sum over the states of 12 cuts.
|
|
242
|
+
*/
|
|
243
|
+
const INDEPENDENT_MAX_WORK = 2 ** 26;
|
|
244
|
+
/**
|
|
226
245
|
* This function gives the curve of a stop of some cuts when the cuts are independent.
|
|
227
246
|
* At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.
|
|
228
247
|
* Its chance is a sum over each set of cuts that stops the supply.
|
|
@@ -236,25 +255,86 @@ const INDEPENDENT_TOLERANCE = 1e-6;
|
|
|
236
255
|
* Thus `|f''| <= (sum |s'|)^2 - sum s'^2`, and the line of a piece of length `h` is within `h^2 |f''| / 8` of the chance.
|
|
237
256
|
* The count of pieces keeps each line within `INDEPENDENT_TOLERANCE`. With a margin of 10 %, the count of points is less than `n / sqrt(7.2 * INDEPENDENT_TOLERANCE)` plus the segments, for `n` cuts.
|
|
238
257
|
*
|
|
239
|
-
*
|
|
258
|
+
* - Up to `MINIMAL_STOP_CUTS` cuts in the sets, the function adds the chance of each of the 2 to the power of that count of states.
|
|
259
|
+
* - Two groups of cuts that share no set are independent, so the chance that the supply works is the product over the groups.
|
|
260
|
+
* For example, 20 stages of 2 feeds give 20 groups of 2 cuts.
|
|
261
|
+
* - In a group of more than `MINIMAL_STOP_CUTS` cuts, it uses the Shannon expansion of `pathSetReliability` of collections.
|
|
262
|
+
* The expansion merges two states with the same sets left, and it drops a set that holds another set.
|
|
263
|
+
* - The expansion is exponential in the worst case. The groups share one budget, `maxWork`.
|
|
264
|
+
* When the steps of the expansions times the count of points of the curve pass it, the result is `undefined`.
|
|
240
265
|
*
|
|
241
266
|
* @param curves - The curves of the cuts, each one good for `checkEndurance`
|
|
242
|
-
* @param sets - The minimal sets of the cuts. With `undefined`, as for
|
|
243
|
-
* @
|
|
267
|
+
* @param sets - The minimal sets of the cuts. With `undefined`, as for no minimal sets, the result is `undefined`. With no sets, it is `[[0, 0]]`
|
|
268
|
+
* @param maxWork - The budget of the expansions of the groups of more than `MINIMAL_STOP_CUTS` cuts, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`
|
|
269
|
+
* @throws RangeError when a curve does not end at a chance of 0, or for a bad `maxWork`
|
|
244
270
|
*/
|
|
245
|
-
function independentStop(curves, sets) {
|
|
271
|
+
function independentStop(curves, sets, maxWork = INDEPENDENT_MAX_WORK) {
|
|
272
|
+
if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The budget maxWork is ${String(maxWork)}: it is not a whole number from 1.`);
|
|
246
273
|
if (sets === void 0) return void 0;
|
|
247
274
|
if (sets.length === 0) return [[0, 0]];
|
|
248
275
|
const used = [...new Set(sets.flat())].sort((x, y) => x - y);
|
|
249
|
-
if (used.length > 12) return void 0;
|
|
250
276
|
const usedCurves = used.map((index) => curves[index] ?? []);
|
|
251
|
-
const
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
|
|
277
|
+
const usedSets = sets.map((set) => set.map((index) => used.indexOf(index)));
|
|
278
|
+
const points = independentPoints(usedCurves);
|
|
279
|
+
const groupChances = [];
|
|
280
|
+
let work = maxWork;
|
|
281
|
+
for (const group of cutGroups(used.length, usedSets)) {
|
|
282
|
+
const curvesOf = group.map((index) => usedCurves[index] ?? []);
|
|
283
|
+
const setsOf = usedSets.filter((set) => group.includes(set[0] ?? -1)).map((set) => set.map((index) => group.indexOf(index)));
|
|
284
|
+
if (group.length <= 12) {
|
|
285
|
+
groupChances.push(stateChance(curvesOf, setsOf));
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const expanded = expandedChances(curvesOf, setsOf, points, work);
|
|
289
|
+
if (expanded === void 0) return void 0;
|
|
290
|
+
work -= expanded.steps * points.length;
|
|
291
|
+
const chanceOf = new Map(points.map((days, index) => [days, expanded.chances[index] ?? 0]));
|
|
292
|
+
groupChances.push((days) => {
|
|
293
|
+
const chance = chanceOf.get(days);
|
|
294
|
+
if (chance === void 0) throw new Error(`The expansion has no chance at ${String(days)} days.`);
|
|
295
|
+
return chance;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const [only] = groupChances;
|
|
299
|
+
if (groupChances.length === 1 && only !== void 0) return curveFrom(points, only);
|
|
300
|
+
return curveFrom(points, (days) => Math.min(1, Math.max(0, 1 - groupChances.reduce((works, chanceAt) => works * (1 - chanceAt(days)), 1))));
|
|
301
|
+
}
|
|
302
|
+
/** The groups of the cuts `0` to `count - 1`: two cuts are in one group when a chain of sets joins them. Each set has its cuts in one group. */
|
|
303
|
+
function cutGroups(count, sets) {
|
|
304
|
+
const next = Array.from({ length: count }, () => /* @__PURE__ */ new Set());
|
|
305
|
+
for (const set of sets) for (const [at, index] of set.entries()) next[index]?.add(set[(at + 1) % set.length] ?? index);
|
|
306
|
+
return stronglyConnectedComponents(Array.from({ length: count }, (_, index) => index), (index) => next[index] ?? []);
|
|
307
|
+
}
|
|
308
|
+
/** The times of `independentStop`: the points of the curves, and the pieces that keep each line within `INDEPENDENT_TOLERANCE`. */
|
|
309
|
+
function independentPoints(curves) {
|
|
310
|
+
const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);
|
|
311
|
+
const points = [];
|
|
312
|
+
for (const [index, t1] of times.entries()) {
|
|
313
|
+
const t0 = times[index - 1];
|
|
314
|
+
if (t0 !== void 0) {
|
|
315
|
+
const h = t1 - t0;
|
|
316
|
+
const slopes = curves.map((curve) => Math.abs(survivalAt(curve, t1) - survivalAt(curve, t0)) / h);
|
|
317
|
+
const sum = slopes.reduce((total, slope) => total + slope, 0);
|
|
318
|
+
const bound = Math.max(0, sum * sum - slopes.reduce((total, slope) => total + slope * slope, 0));
|
|
319
|
+
const pieces = Math.ceil(h * Math.sqrt(bound / (7.2 * INDEPENDENT_TOLERANCE)));
|
|
320
|
+
for (let piece = 1; piece < pieces; piece += 1) {
|
|
321
|
+
const days = t0 + h * piece / pieces;
|
|
322
|
+
if (days > (points[points.length - 1] ?? t0) && days < t1) points.push(days);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
points.push(t1);
|
|
326
|
+
}
|
|
327
|
+
return points;
|
|
328
|
+
}
|
|
329
|
+
/** The chance of a stop at a time, as the sum over each state of `MINIMAL_STOP_CUTS` cuts or fewer. Bit k of a state is 1 when cut k is on. */
|
|
330
|
+
function stateChance(curves, sets) {
|
|
331
|
+
const setMasks = sets.map((set) => set.reduce((mask, index) => mask | 1 << index, 0));
|
|
332
|
+
const stopping = Array.from({ length: 1 << curves.length }, (_, mask) => setMasks.some((set) => (set & mask) === set));
|
|
333
|
+
const states = new Float64Array(1 << curves.length);
|
|
334
|
+
return (days) => {
|
|
255
335
|
states[0] = 1;
|
|
256
336
|
let length = 1;
|
|
257
|
-
for (const curve of
|
|
337
|
+
for (const curve of curves) {
|
|
258
338
|
const on = survivalAt(curve, days);
|
|
259
339
|
for (let mask = 0; mask < length; mask += 1) {
|
|
260
340
|
const chance = states[mask] ?? 0;
|
|
@@ -267,24 +347,60 @@ function independentStop(curves, sets) {
|
|
|
267
347
|
for (let mask = 0; mask < length; mask += 1) if (stopping[mask]) total += states[mask] ?? 0;
|
|
268
348
|
return Math.min(1, Math.max(0, total));
|
|
269
349
|
};
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
350
|
+
}
|
|
351
|
+
/** The count of times in one expansion of `expandedChances`: the length of the vectors of its ring. */
|
|
352
|
+
const EXPANSION_WIDTH = 64;
|
|
353
|
+
/**
|
|
354
|
+
* The ring of the vectors of `width` chances, one for each time, for `pathSetReliability` of collections.
|
|
355
|
+
* Each operation is on each time alone. In the order, `a` is less than `b` when it is less or equal at each time, and not equal.
|
|
356
|
+
*/
|
|
357
|
+
function vectorRing(width) {
|
|
358
|
+
const zip = (a, b, op) => {
|
|
359
|
+
const out = new Float64Array(width);
|
|
360
|
+
for (let index = 0; index < width; index += 1) out[index] = op(a[index] ?? 0, b[index] ?? 0);
|
|
361
|
+
return out;
|
|
362
|
+
};
|
|
363
|
+
return {
|
|
364
|
+
zero: new Float64Array(width),
|
|
365
|
+
one: new Float64Array(width).fill(1),
|
|
366
|
+
add: (a, b) => zip(a, b, (x, y) => x + y),
|
|
367
|
+
sub: (a, b) => zip(a, b, (x, y) => x - y),
|
|
368
|
+
mul: (a, b) => zip(a, b, (x, y) => x * y),
|
|
369
|
+
compare: (a, b) => {
|
|
370
|
+
let less = false;
|
|
371
|
+
let more = false;
|
|
372
|
+
for (let index = 0; index < width; index += 1) {
|
|
373
|
+
const [x, y] = [a[index] ?? 0, b[index] ?? 0];
|
|
374
|
+
if (x < y) less = true;
|
|
375
|
+
else if (x > y) more = true;
|
|
376
|
+
else if (x !== y) return NaN;
|
|
283
377
|
}
|
|
378
|
+
return less ? more ? NaN : -1 : more ? 1 : 0;
|
|
284
379
|
}
|
|
285
|
-
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* The chance of a stop at each point, from the Shannon expansion of `pathSetReliability`. A set works when each of its cuts is on.
|
|
384
|
+
* One call gives `EXPANSION_WIDTH` points. When the steps of one expansion times the count of points pass `maxWork`, the result is `undefined`.
|
|
385
|
+
* Else `steps` is the count of steps of one expansion.
|
|
386
|
+
*/
|
|
387
|
+
function expandedChances(curves, sets, points, maxWork) {
|
|
388
|
+
const maxSteps = Math.floor(maxWork / points.length);
|
|
389
|
+
if (maxSteps < 1) return void 0;
|
|
390
|
+
const out = [];
|
|
391
|
+
let steps = 0;
|
|
392
|
+
for (let start = 0; start < points.length; start += EXPANSION_WIDTH) {
|
|
393
|
+
const times = points.slice(start, start + EXPANSION_WIDTH);
|
|
394
|
+
const chances = curves.map((curve) => Float64Array.from(times, (days) => survivalAt(curve, days)));
|
|
395
|
+
const result = pathSetReliability(sets, chances, vectorRing(times.length), { maxSteps });
|
|
396
|
+
if (result.kind === "budget") return void 0;
|
|
397
|
+
steps = result.steps;
|
|
398
|
+
for (const chance of result.value) out.push(Math.min(1, Math.max(0, chance)));
|
|
286
399
|
}
|
|
287
|
-
return
|
|
400
|
+
return {
|
|
401
|
+
chances: out,
|
|
402
|
+
steps
|
|
403
|
+
};
|
|
288
404
|
}
|
|
289
405
|
function stoppedMemo(caseCuts, options) {
|
|
290
406
|
const memo = /* @__PURE__ */ new Map();
|
|
@@ -315,7 +431,7 @@ function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
|
|
|
315
431
|
if (!stops(relevant.map((_, index) => index))) return void 0;
|
|
316
432
|
const given = relevant.map((index) => caseCuts.cuts[index]?.duration);
|
|
317
433
|
const parts = relevant.map((index) => caseCuts.cuts[index]?.part ?? "");
|
|
318
|
-
const sets = (options.stack === void 0 ? void 0 : stackStops(options.stack, draw.supply, parts, options.down)) ?? minimalStops(given.length, stops);
|
|
434
|
+
const sets = (options.stack === void 0 ? void 0 : stackStops(options.stack, draw.supply, parts, options.down, budgetsOf(options).maxSets)) ?? minimalStops(given.length, stops);
|
|
319
435
|
const unsourced = given.flatMap((curve, index) => curve === void 0 ? [index] : []);
|
|
320
436
|
if (unsourced.length > 0 && (sets === void 0 || sets.some((set) => set.some((index) => unsourced.includes(index))))) return void 0;
|
|
321
437
|
const kept = given.flatMap((curve, index) => curve === void 0 ? [] : [index]);
|
|
@@ -323,7 +439,7 @@ function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
|
|
|
323
439
|
const keptStops = (cuts) => stops(cuts.map((index) => kept[index] ?? -1));
|
|
324
440
|
const keptSets = sets?.map((set) => set.map((index) => kept.indexOf(index)));
|
|
325
441
|
const upper = upperStop(curves, keptSets);
|
|
326
|
-
const independent = independentStop(curves, keptSets);
|
|
442
|
+
const independent = independentStop(curves, keptSets, budgetsOf(options).maxWork);
|
|
327
443
|
return {
|
|
328
444
|
event: eventStop(curves, keptStops),
|
|
329
445
|
independent: independent ?? upper,
|
|
@@ -339,13 +455,14 @@ function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
|
|
|
339
455
|
* - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.
|
|
340
456
|
* - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.
|
|
341
457
|
* - With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core), so the count of cuts has no limit of `MINIMAL_STOP_CUTS`.
|
|
342
|
-
* When that search passes its budget, `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.
|
|
458
|
+
* When that search passes its budget (the option `maxSets`), `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.
|
|
343
459
|
* - A cut with no `duration` gives no curve when it is in a minimal set, or when the query has no minimal sets.
|
|
344
460
|
* - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.
|
|
345
461
|
* - With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` is true.
|
|
346
|
-
* - When the
|
|
462
|
+
* - When the expansion of `independentStop` passes its budget, `independent` is `upper`, and `independentUpper` is true.
|
|
347
463
|
*/
|
|
348
464
|
function stopCurves(caseCuts, draw, options = {}) {
|
|
465
|
+
budgetsOf(options);
|
|
349
466
|
return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));
|
|
350
467
|
}
|
|
351
468
|
function zeroLevels(layer) {
|
|
@@ -359,10 +476,11 @@ function zeroLevels(layer) {
|
|
|
359
476
|
* @param caseCuts - The case
|
|
360
477
|
* @param endurance - The endurance of the case, from `enduranceOf`
|
|
361
478
|
* @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon
|
|
362
|
-
* @throws RangeError when the horizon is not a number more than 0
|
|
479
|
+
* @throws RangeError when the horizon is not a number more than 0, or `maxSets` is not a whole number from 1
|
|
363
480
|
*/
|
|
364
481
|
function caseShortfall(layer, caseCuts, endurance, options = {}) {
|
|
365
482
|
const horizon = horizonOf(options);
|
|
483
|
+
budgetsOf(options);
|
|
366
484
|
const levels = zeroLevels(layer);
|
|
367
485
|
const independent = zeroLevels(layer);
|
|
368
486
|
const upper = zeroLevels(layer);
|
|
@@ -404,10 +522,11 @@ function caseShortfall(layer, caseCuts, endurance, options = {}) {
|
|
|
404
522
|
* @param layer - The endurance layer, with its cases and priors
|
|
405
523
|
* @param place - The place of the priors
|
|
406
524
|
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
407
|
-
* @throws RangeError
|
|
525
|
+
* @throws RangeError for a bad date, horizon or `maxSets`: refer to `caseShortfall` and `enduranceOf`
|
|
408
526
|
*/
|
|
409
527
|
function yearShortfall(layer, place, options) {
|
|
410
528
|
horizonOf(options);
|
|
529
|
+
budgetsOf(options);
|
|
411
530
|
const levels = zeroLevels(layer);
|
|
412
531
|
const independent = zeroLevels(layer);
|
|
413
532
|
const upper = zeroLevels(layer);
|
|
@@ -669,6 +788,6 @@ const SAMPLE_ENDURANCE = {
|
|
|
669
788
|
asOf: "2025-12-01"
|
|
670
789
|
}]
|
|
671
790
|
};
|
|
672
|
-
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, caseDraws, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, independentStop, joinEndurance, longestStop, minimalStops, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
791
|
+
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, caseDraws, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, independentStop, joinEndurance, longestStop, minimalStops, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
673
792
|
|
|
674
793
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/stops.ts","../src/shortfall.ts","../src/sample.ts"],"sourcesContent":["import { DEFAULT_MAX_SETS, stopSets, type Stack } from \"@mark1russell7/system-stack\";\n\n// The minimal stop sets of a supply from the structure of the needs. The index does not give this entry: `stopCurves` uses it.\n\n/**\n * This function gives the minimal sets of cuts that stop a supply, from the paths of the needs of the stack (`stopSets` of the core).\n * A set is a list of indexes of `parts`, from the smallest set. Two sets of one size are in the order of `minimalStops`.\n *\n * - `parts` has the part of each cut that counts. Two cuts of one part are two cuts: each one stops what the part stops.\n * - A cut of the supply stops it alone. The other sets come from `stopSets` with the cut parts as `among`, so no other part can fail.\n * - The parts of `down` are down for the full event. The caller makes sure that they do not stop the supply with no cut.\n * - The result is `undefined` when the search passes its budget, or when the sets of cuts are more than `DEFAULT_MAX_SETS`.\n *\n * @param stack - The base stack\n * @param supply - The part of the supply of a draw\n * @param parts - The part of each cut that counts\n * @param down - The parts that are down for the full event\n */\nexport function stackStops(stack: Stack, supply: string, parts: readonly string[], down: readonly string[] = []): number[][] | undefined {\n const cutsOf = new Map<string, number[]>();\n for (const [index, part] of parts.entries()) cutsOf.set(part, [...(cutsOf.get(part) ?? []), index]);\n const own = (cutsOf.get(supply) ?? []).map((index) => [index]);\n const among = [...cutsOf.keys()].filter((part) => part !== supply);\n const found = stopSets(stack, supply, { down, among, size: among.length });\n if (found.kind === \"budget\") return undefined;\n // The empty set: the supply is not in the stack, or it does not work in the base stack.\n // In both, `stopped` of the core does not count it as stopped, so only a cut of the supply stops it.\n if (found.sets.some((set) => set.length === 0)) return own;\n const out = [...own];\n for (const set of found.sets) {\n // Each choice of one cut for each part of the set is a minimal set of cuts.\n let choices: number[][] = [[]];\n for (const part of set) {\n const cuts = cutsOf.get(part) ?? [];\n if (choices.length * cuts.length + out.length > DEFAULT_MAX_SETS) return undefined;\n choices = choices.flatMap((choice) => cuts.map((cut) => [...choice, cut]));\n }\n out.push(...choices.map((choice) => choice.sort((x, y) => x - y)));\n }\n return out.sort(byMask);\n}\n\n/** The order of `minimalStops`: the smaller set first, then the set whose largest different index is smaller. */\nfunction byMask(a: readonly number[], b: readonly number[]): number {\n if (a.length !== b.length) return a.length - b.length;\n for (let index = a.length - 1; index >= 0; index -= 1) {\n const difference = (a[index] ?? 0) - (b[index] ?? 0);\n if (difference !== 0) return difference;\n }\n return 0;\n}\n","import { neededParts } from \"@mark1russell7/system-stack\";\nimport { caseDraws, caseStopped, enduranceOf, type CaseOptions } from \"./endurance.ts\";\nimport type { CaseCuts, Draw, Endurance, EnduranceLayer, Prior, Survival } from \"./layer.ts\";\nimport { stackStops } from \"./stops.ts\";\n\n// The shortfall: the user-days in which a draw does not get its need, for one case and for one year.\n\n/** This function gives the chance that a cut lasts more than `days`, linear between the points of the curve. After the last point it is 0. */\nexport function survivalAt(curve: Survival, days: number): number {\n if (days <= 0) return curve[0]?.[1] ?? 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (days < t1) {\n // The chance stays between the chances of the two points, so a rounding does not go below the lower one.\n const chance = p0 + (p1 - p0) * ((days - t0) / (t1 - t0));\n return Math.min(Math.max(p0, p1), Math.max(Math.min(p0, p1), chance));\n }\n if (days === t1) return p1;\n }\n return 0;\n}\n\n/**\n * This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.\n * It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.\n * With no horizon, the area goes to the end of the curve.\n */\nexport function tailDays(curve: Survival, from: number, to: number = Infinity): number {\n let area = 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0] = curve[index - 1] ?? [0, 1];\n const [t1] = curve[index] ?? [0, 0];\n const start = Math.max(t0, from);\n const end = Math.min(t1, to);\n if (start < end) area += ((survivalAt(curve, start) + survivalAt(curve, end)) / 2) * (end - start);\n }\n return area;\n}\n\n/**\n * The options of a shortfall: the stack or the parts that are also down, as for `enduranceOf`, and a horizon.\n * With a horizon of `h` days, the shortfall counts only the first `h` days of each cut. A draw that holds `h` days has no shortfall.\n * Thus a plan can aim at a target, for example 14 days and then 90 days.\n */\nexport interface ShortfallOptions extends Pick<CaseOptions, \"stack\" | \"down\"> {\n /** The horizon in days, more than 0. The default is no horizon. */\n readonly horizon?: number | undefined;\n}\n\nfunction horizonOf(options: ShortfallOptions): number {\n const horizon = options.horizon ?? Infinity;\n if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);\n return horizon;\n}\n\n/**\n * This function gives the days at which the chance of the curve falls to `chance`. With `0.1`, it is the 90th percentile of the duration.\n * When the curve does not fall to `chance`, the result is `Infinity`.\n */\nexport function survivalQuantile(curve: Survival, chance: number): number {\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (p0 <= chance) return t0;\n if (p1 <= chance) return t0 + ((p0 - chance) * (t1 - t0)) / (p0 - p1);\n }\n return Infinity;\n}\n\n/** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */\nexport function yearChance(prior: Prior): number {\n return 1 - Math.exp(-prior.perYear * prior.reach);\n}\n\n/** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */\nexport function yearRate(prior: Prior): number {\n return prior.perYear * prior.reach;\n}\n\n/** This function gives the times at which a curve of the result can bend: each point of each curve, and each crossing of two curves. */\nfunction bendTimes(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const out = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n for (const [i, a] of curves.entries()) {\n for (const b of curves.slice(i + 1)) {\n const d0 = survivalAt(a, t0) - survivalAt(b, t0);\n const d1 = survivalAt(a, t1) - survivalAt(b, t1);\n if (d0 * d1 < 0) out.add(t0 + ((t1 - t0) * d0) / (d0 - d1));\n }\n }\n }\n return [...out].sort((x, y) => x - y);\n}\n\n/**\n * This function makes a survival curve from a chance at each time. It stops at the first chance of 0, and it removes an increase of rounding.\n *\n * @throws RangeError when the chance at the last time is more than 0, as for curves that do not end at a chance of 0\n */\nfunction curveFrom(times: readonly number[], chanceAt: (days: number) => number): Survival {\n const out: [number, number][] = [];\n for (const days of times) {\n const chance = Math.min(out[out.length - 1]?.[1] ?? 1, chanceAt(days));\n out.push([days, chance]);\n if (chance === 0) return out;\n }\n throw new RangeError(\"The curves do not fall to a chance of 0 at their last point.\");\n}\n\n/**\n * This function gives the curve of a stop of some cuts when one event makes each cut longer together.\n * At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.\n *\n * - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).\n * - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.\n * - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.\n * - When no set of cuts stops the supply, the result is `[[0, 0]]`. This curve does not start at `[0, 1]`, so `checkEndurance` refuses it.\n *\n * The result is not a limit. When the cuts are independent, a stop of two cuts in series can be longer. A stop through a need of `any` can be shorter.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param stops - This function tells if the cuts of a list of indexes stop the supply. A larger list stops it when a smaller list does.\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function eventStop(curves: readonly Survival[], stops: (cuts: readonly number[]) => boolean): Survival {\n return curveFrom(bendTimes(curves), (days) => {\n const chances = curves.map((curve) => survivalAt(curve, days));\n for (const level of [...new Set(chances)].sort((x, y) => y - x)) {\n if (stops(chances.flatMap((chance, index) => (chance >= level ? [index] : [])))) return level;\n }\n return 0;\n });\n}\n\n/**\n * This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.\n * It is `eventStop` when any one cut stops the supply.\n *\n * @param curves - The curves, each one good for `checkEndurance`\n * @throws RangeError when there is no curve, or when a curve does not end at a chance of 0\n */\nexport function longestStop(curves: readonly Survival[]): Survival {\n const first = curves[0];\n if (first === undefined) throw new RangeError(\"longestStop needs one or more curves.\");\n return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);\n}\n\n/**\n * The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop` examines each state.\n * With a stack, `stopCurves` finds the minimal sets from the needs, so a larger count of cuts can have exact sets.\n */\nexport const MINIMAL_STOP_CUTS = 12;\n\n/**\n * This function gives the minimal sets of cuts that stop the supply: each set stops it, and no smaller part of a set stops it.\n * With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.\n */\nexport function minimalStops(count: number, stops: (cuts: readonly number[]) => boolean): number[][] | undefined {\n if (count > MINIMAL_STOP_CUTS) return undefined;\n const found: number[][] = [];\n const masks: number[] = [];\n const all = Array.from({ length: 1 << count }, (_, mask) => mask).sort((x, y) => popCount(x) - popCount(y) || x - y);\n for (const mask of all) {\n if (mask === 0 || masks.some((other) => (other & mask) === other)) continue;\n const cuts = Array.from({ length: count }, (_, index) => index).filter((index) => (mask >> index) & 1);\n if (!stops(cuts)) continue;\n masks.push(mask);\n found.push(cuts);\n }\n return found;\n}\n\nfunction popCount(mask: number): number {\n let total = 0;\n for (let rest = mask; rest > 0; rest &= rest - 1) total += 1;\n return total;\n}\n\n/**\n * This function gives an upper limit of the curve of a stop for each dependence of the cuts.\n * At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.\n * With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.\n *\n * @param curves - The curves of the cuts\n * @param sets - The minimal sets of `minimalStops`, or `undefined`\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function upperStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival {\n const groups = sets ?? curves.map((_, index) => [index]);\n const sum = (days: number): number => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);\n // The sum is linear between two times of bendTimes. A point where it falls through 1 is a bend of min(1, sum).\n const times = bendTimes(curves);\n const bends = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n const s0 = sum(t0) - 1;\n const s1 = sum(t1) - 1;\n if (s0 * s1 < 0) bends.add(t0 + ((t1 - t0) * s0) / (s0 - s1));\n }\n return curveFrom([...bends].sort((x, y) => x - y), (days) => Math.min(1, sum(days)));\n}\n\n/** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */\nexport const INDEPENDENT_TOLERANCE = 1e-6;\n\n/**\n * This function gives the curve of a stop of some cuts when the cuts are independent.\n * At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.\n * Its chance is a sum over each set of cuts that stops the supply.\n * Each term is the product of `s(t)` for the cuts that are on, and of `1 - s(t)` for the other cuts.\n *\n * - When any one cut stops the supply, the result is `1 - prod(1 - s)`. It is not less than the longest cut (`eventStop`).\n * - When the supply needs `any` of two parts, the stop of the two is `s1 * s2`. It is not more than the shorter cut.\n * - The result is not more than `upperStop` of the same sets, because `upperStop` is a limit for each dependence.\n * - Between two points of the curves the chance is a polynomial, not a line. The function splits each such segment into equal pieces.\n * The chance is linear in each `s`, and each mixed second derivative is between -1 and 1.\n * Thus `|f''| <= (sum |s'|)^2 - sum s'^2`, and the line of a piece of length `h` is within `h^2 |f''| / 8` of the chance.\n * The count of pieces keeps each line within `INDEPENDENT_TOLERANCE`. With a margin of 10 %, the count of points is less than `n / sqrt(7.2 * INDEPENDENT_TOLERANCE)` plus the segments, for `n` cuts.\n *\n * The count of states is 2 to the power of the count of cuts in the sets. Past `MINIMAL_STOP_CUTS` such cuts, the result is `undefined`.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param sets - The minimal sets of the cuts. With `undefined`, as for too many cuts, the result is `undefined`. With no sets, it is `[[0, 0]]`\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function independentStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival | undefined {\n if (sets === undefined) return undefined;\n // With no set, no cuts stop the supply, as for `eventStop` and `upperStop`.\n if (sets.length === 0) return [[0, 0]];\n // Only the cuts of a set change the chance. Their place in `used` is their bit in a state.\n const used = [...new Set(sets.flat())].sort((x, y) => x - y);\n if (used.length > MINIMAL_STOP_CUTS) return undefined;\n const usedCurves = used.map((index) => curves[index] ?? []);\n const setMasks = sets.map((set) => set.reduce((mask, index) => mask | (1 << used.indexOf(index)), 0));\n const stopping = Array.from({ length: 1 << used.length }, (_, mask) => setMasks.some((set) => (set & mask) === set));\n const states = new Float64Array(1 << used.length);\n const chanceAt = (days: number): number => {\n // The chance of each state of the cuts, one cut at a time. Bit k of a state is 1 when cut k is on.\n states[0] = 1;\n let length = 1;\n for (const curve of usedCurves) {\n const on = survivalAt(curve, days);\n for (let mask = 0; mask < length; mask += 1) {\n const chance = states[mask] ?? 0;\n states[mask + length] = chance * on;\n states[mask] = chance * (1 - on);\n }\n length *= 2;\n }\n let total = 0;\n for (let mask = 0; mask < length; mask += 1) if (stopping[mask]) total += states[mask] ?? 0;\n return Math.min(1, Math.max(0, total));\n };\n const times = [...new Set(usedCurves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const points: number[] = [];\n for (const [index, t1] of times.entries()) {\n const t0 = times[index - 1];\n if (t0 !== undefined) {\n const h = t1 - t0;\n const slopes = usedCurves.map((curve) => Math.abs(survivalAt(curve, t1) - survivalAt(curve, t0)) / h);\n const sum = slopes.reduce((total, slope) => total + slope, 0);\n const bound = Math.max(0, sum * sum - slopes.reduce((total, slope) => total + slope * slope, 0));\n // A margin of 10 % keeps the rounding of the chance under the tolerance.\n const pieces = Math.ceil(h * Math.sqrt(bound / (8 * 0.9 * INDEPENDENT_TOLERANCE)));\n for (let piece = 1; piece < pieces; piece += 1) {\n const days = t0 + (h * piece) / pieces;\n // Two times that are next to each other as floats have no time between them.\n if (days > (points[points.length - 1] ?? t0) && days < t1) points.push(days);\n }\n }\n points.push(t1);\n }\n return curveFrom(points, chanceAt);\n}\n\n/**\n * The curves of the stop of a draw. `event` is for one event that makes each cut longer together, and `independent` is for independent cuts.\n * `upper` is an upper limit for each dependence.\n */\nexport interface StopCurves {\n readonly event: Survival;\n /** The stop when the cuts are independent (`independentStop`). When `independentUpper` is true, it is `upper`. */\n readonly independent: Survival;\n readonly upper: Survival;\n /**\n * This is true when `upper` is the sum of the curves of the cuts that count, because the query has no minimal sets.\n * With a stack, the search of the needs passed its budget. With no stack, more than `MINIMAL_STOP_CUTS` cuts count.\n */\n readonly coarse: boolean;\n /** This is true when `independent` is `upper`: `coarse` is true, or the minimal sets have more than `MINIMAL_STOP_CUTS` cuts. */\n readonly independentUpper: boolean;\n}\n\n/** This function gives the parts of the stack that are down for a list of cut indexes. A case uses one memo for each of its draws. */\ntype StoppedOf = (cuts: readonly number[]) => ReadonlySet<string>;\n\nfunction stoppedMemo(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): StoppedOf {\n const memo = new Map<string, ReadonlySet<string>>();\n return (cuts) => {\n const key = cuts.join(\",\");\n let found = memo.get(key);\n if (found === undefined) {\n found = caseStopped({ ...caseCuts, cuts: cuts.flatMap((index) => caseCuts.cuts[index] ?? []) }, options);\n memo.set(key, found);\n }\n return found;\n };\n}\n\n/** This function gives the parts whose cut can stop a supply: the supply, and each part that it needs through the stack. */\nfunction supplyReach(supply: string, options: Pick<CaseOptions, \"stack\">): Set<string> {\n const reach = options.stack === undefined ? new Set<string>() : neededParts(options.stack, supply);\n reach.add(supply);\n return reach;\n}\n\nfunction stopCurvesWith(caseCuts: CaseCuts, draw: Draw, options: Pick<CaseOptions, \"stack\" | \"down\">, stoppedOf: StoppedOf): StopCurves | undefined {\n const reach = supplyReach(draw.supply, options);\n const relevant = caseCuts.cuts.flatMap((cut, index) => (reach.has(cut.part) ? [index] : []));\n const stops = (cuts: readonly number[]): boolean => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);\n if (stops([])) return undefined;\n if (!stops(relevant.map((_, index) => index))) return undefined;\n const given = relevant.map((index) => caseCuts.cuts[index]?.duration);\n // With a stack, the needs give the minimal sets. When their search passes its budget, the sets of each list of cuts are the check.\n const parts = relevant.map((index) => caseCuts.cuts[index]?.part ?? \"\");\n const structural = options.stack === undefined ? undefined : stackStops(options.stack, draw.supply, parts, options.down);\n const sets = structural ?? minimalStops(given.length, stops);\n // The stop has no curve when a cut with no curve can be part of it. With no minimal sets, the query cannot tell.\n const unsourced = given.flatMap((curve, index) => (curve === undefined ? [index] : []));\n if (unsourced.length > 0 && (sets === undefined || sets.some((set) => set.some((index) => unsourced.includes(index))))) return undefined;\n // A cut with no curve is in no minimal set here, so it does not change a stop. The curves do not include it.\n const kept = given.flatMap((curve, index) => (curve === undefined ? [] : [index]));\n const curves = kept.map((index) => given[index] ?? []);\n const keptStops = (cuts: readonly number[]): boolean => stops(cuts.map((index) => kept[index] ?? -1));\n const keptSets = sets?.map((set) => set.map((index) => kept.indexOf(index)));\n const upper = upperStop(curves, keptSets);\n const independent = independentStop(curves, keptSets);\n return { event: eventStop(curves, keptStops), independent: independent ?? upper, upper, coarse: keptSets === undefined, independentUpper: independent === undefined };\n}\n\n/**\n * This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.\n *\n * - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.\n * - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.\n * - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.\n * - With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core), so the count of cuts has no limit of `MINIMAL_STOP_CUTS`.\n * When that search passes its budget, `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.\n * - A cut with no `duration` gives no curve when it is in a minimal set, or when the query has no minimal sets.\n * - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.\n * - With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` is true.\n * - When the minimal sets have more than `MINIMAL_STOP_CUTS` cuts, `independent` is `upper`, and `independentUpper` is true.\n */\nexport function stopCurves(caseCuts: CaseCuts, draw: Draw, options: Pick<CaseOptions, \"stack\" | \"down\"> = {}): StopCurves | undefined {\n return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));\n}\n\n/** The shortfall of each level, in user-days, and the draws that the query cannot read. */\nexport interface Shortfall {\n /**\n * The user-days of each level of the layer, when one event makes each cut longer together. The query does not add two levels.\n * This value is not a limit. The true value can be more or less. `upper` is the limit.\n */\n readonly levels: Readonly<Record<string, number>>;\n /** The user-days of each level when the cuts are independent (`StopCurves.independent`). This value is not more than `upper`. */\n readonly independent: Readonly<Record<string, number>>;\n /** The upper limit of the user-days of each level, for each dependence of the cuts. A gate of a high level can use it. */\n readonly upper: Readonly<Record<string, number>>;\n /**\n * The needs of the draws whose stop has no curve (`stopCurves`).\n * The query has no curve of their duration, so their shortfall is not in `levels`. A gate shows them as no read.\n */\n readonly unread: readonly string[];\n /** The needs of the draws whose `upper` is coarse (`StopCurves.coarse`). A gate on `upper` shows them. */\n readonly coarse: readonly string[];\n /** The needs of the draws whose `independent` is `upper` (`StopCurves.independentUpper`). A gate on `independent` shows them. */\n readonly independentUpper: readonly string[];\n}\n\nfunction zeroLevels(layer: EnduranceLayer): Record<string, number> {\n return Object.fromEntries(layer.levels.map((level) => [level, 0]));\n}\n\n/**\n * This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.\n * `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param endurance - The endurance of the case, from `enduranceOf`\n * @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon\n * @throws RangeError when the horizon is not a number more than 0\n */\nexport function caseShortfall(layer: EnduranceLayer, caseCuts: CaseCuts, endurance: Endurance, options: ShortfallOptions = {}): Shortfall {\n const horizon = horizonOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const stoppedOf = stoppedMemo(caseCuts, options);\n for (const draw of caseDraws(layer, caseCuts, caseStopped(caseCuts, options))) {\n const held = endurance.needs[draw.need];\n const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);\n if (held === undefined || curves === undefined) {\n unread.push(draw.need);\n continue;\n }\n if (curves.coarse) coarse.push(draw.need);\n if (curves.independentUpper) independentUpper.push(draw.need);\n const users = draw.users ?? 1;\n levels[draw.level] = (levels[draw.level] ?? 0) + tailDays(curves.event, held.days, horizon) * users;\n independent[draw.level] = (independent[draw.level] ?? 0) + tailDays(curves.independent, held.days, horizon) * users;\n upper[draw.level] = (upper[draw.level] ?? 0) + tailDays(curves.upper, held.days, horizon) * users;\n }\n return { levels, independent, upper, unread, coarse, independentUpper };\n}\n\n/** The shortfall of one year at one place, with the part of each case. */\nexport interface YearShortfall extends Shortfall {\n readonly place: string;\n /** The part of each case. `rate` is the expected count of its events in one year. */\n readonly cases: readonly { readonly case: string; readonly rate: number; readonly endurance: Endurance; readonly shortfall: Shortfall }[];\n}\n\n/**\n * This function gives the shortfall of one year at one place.\n * It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.\n *\n * - The expected count of a case is `perYear * reach`, from the first prior of the case at the place. Thus the result is the expected user-days of one year.\n * - A case with no prior at the place is not in the sum.\n * - `unread` is the union of the needs that a case cannot read, in the order of the cases. `coarse` and `independentUpper` are unions too.\n *\n * @param layer - The endurance layer, with its cases and priors\n * @param place - The place of the priors\n * @param options - The date, the stack or the parts that are also down, and the horizon\n * @throws RangeError when the date is not `YYYY-MM-DD`, or when the horizon is not a number more than 0\n */\nexport function yearShortfall(layer: EnduranceLayer, place: string, options: CaseOptions & ShortfallOptions): YearShortfall {\n horizonOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const cases: YearShortfall[\"cases\"][number][] = [];\n for (const caseCuts of layer.cases ?? []) {\n const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);\n if (prior === undefined) continue;\n const rate = yearRate(prior);\n const endurance = enduranceOf(layer, caseCuts, options);\n const shortfall = caseShortfall(layer, caseCuts, endurance, options);\n for (const [level, days] of Object.entries(shortfall.levels)) levels[level] = (levels[level] ?? 0) + rate * days;\n for (const [level, days] of Object.entries(shortfall.independent)) independent[level] = (independent[level] ?? 0) + rate * days;\n for (const [level, days] of Object.entries(shortfall.upper)) upper[level] = (upper[level] ?? 0) + rate * days;\n for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);\n for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);\n for (const need of shortfall.independentUpper) if (!independentUpper.includes(need)) independentUpper.push(need);\n cases.push({ case: caseCuts.case, rate, endurance, shortfall });\n }\n return { place, levels, independent, upper, unread, coarse, independentUpper, cases };\n}\n","import { STACK_SCHEMA, type Stack } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// A sample: a building with 3 users, and a storm that cuts the grid, the road and the water main.\n// Each name and each value is an example, except the grid curve (NREL, technical report 83092). The tests, the README files and the site use it.\n\n/** The base stack of the sample: the supplies of the building and a camp stove. */\nexport const SAMPLE_ENDURANCE_STACK: Stack = {\n schema: STACK_SCHEMA,\n parts: [\n { id: \"grid\", kind: \"power\", name: \"The power grid\" },\n { id: \"water-main\", kind: \"water\", name: \"The water main\" },\n { id: \"road\", kind: \"road\", name: \"The local road to the shops\" },\n { id: \"stove\", kind: \"device\", name: \"The camp stove\" },\n ],\n};\n\n/**\n * The endurance layer of the sample.\n *\n * - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.\n * - The food holds 4800 / 5400 = 0.889 days. The rice needs 2 L of water for each kg, and the drinking water keeps back all the water.\n * - The power holds 1000 Wh / 150 Wh a day = 6.667 days.\n * - The filled bottles are past their due date, so they give nothing.\n */\nexport const SAMPLE_ENDURANCE: EnduranceLayer = {\n schema: ENDURANCE_SCHEMA,\n levels: [\"life\", \"health\", \"comfort\"],\n resources: [\n { code: \"water.stored\", unit: \"L\" },\n { code: \"food.ready\", unit: \"kcal\" },\n { code: \"food.grain-dry\", unit: \"kg\" },\n { code: \"fuel.propane\", unit: \"kg\" },\n { code: \"energy.battery\", unit: \"Wh\" },\n ],\n stores: [\n { id: \"jugs\", resource: \"water.stored\", amount: 75.7, due: \"2028-06-01\" },\n { id: \"bottles\", resource: \"water.stored\", amount: 20, due: \"2026-09-30\" },\n { id: \"cans\", resource: \"food.ready\", amount: 4800, due: \"2028-10-01\" },\n { id: \"rice\", resource: \"food.grain-dry\", amount: 9, due: \"2036-09-28\" },\n { id: \"propane\", resource: \"fuel.propane\", amount: 0.908, due: \"2036-10-01\" },\n { id: \"battery\", resource: \"energy.battery\", amount: 1000, due: \"2031-10-01\" },\n ],\n draws: [\n { need: \"hydration.drink\", level: \"life\", perDay: 11.355, users: 3, supply: \"water-main\" },\n { need: \"food.energy\", level: \"health\", perDay: 5400, users: 3, supply: \"road\" },\n { need: \"power.electric\", level: \"comfort\", perDay: 150, users: 3, supply: \"grid\" },\n ],\n direct: [\n { resource: \"water.stored\", need: \"hydration.drink\", amount: 1 },\n { resource: \"food.ready\", need: \"food.energy\", amount: 1 },\n { resource: \"energy.battery\", need: \"power.electric\", amount: 1 },\n ],\n converters: [\n {\n id: \"cook-rice\",\n device: \"stove\",\n takes: [\n { resource: \"food.grain-dry\", amount: 1 },\n { resource: \"water.stored\", amount: 2 },\n { resource: \"fuel.propane\", amount: 0.05 },\n ],\n gives: { need: \"food.energy\", amount: 3600 },\n },\n ],\n cases: [\n {\n case: \"storm\",\n title: \"Winter storm\",\n cuts: [\n { part: \"grid\", title: \"Power outage\", duration: [[0, 1], [0.5, 0.5], [1, 0.36], [7, 0.013], [30, 0]], source: \"nrel-83092\" },\n { part: \"road\", title: \"Closed local road\", duration: [[0, 1], [1, 0.6], [3, 0.2], [10, 0]], source: \"sample\" },\n { part: \"water-main\", title: \"No water from the main\", duration: [[0, 1], [2, 0.3], [7, 0]], source: \"sample\" },\n ],\n leadSeconds: 86_400,\n },\n { case: \"fire\", title: \"Fire\", cuts: [] },\n ],\n priors: [\n { case: \"storm\", place: \"home\", perYear: 0.8, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n { case: \"fire\", place: \"home\", perYear: 0.003, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n ],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,WAAW,OAAc,QAAgB,OAA0B,OAA0B,CAAC,GAA2B;CACvI,MAAM,yBAAS,IAAI,IAAsB;CACzC,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GAAG,OAAO,IAAI,MAAM,CAAC,GAAI,OAAO,IAAI,IAAI,KAAK,CAAC,GAAI,KAAK,CAAC;CAClG,MAAM,OAAO,OAAO,IAAI,MAAM,KAAK,CAAC,EAAA,CAAG,KAAK,UAAU,CAAC,KAAK,CAAC;CAC7D,MAAM,QAAQ,CAAC,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,SAAS,SAAS,MAAM;CACjE,MAAM,QAAQ,SAAS,OAAO,QAAQ;EAAE;EAAM;EAAO,MAAM,MAAM;CAAO,CAAC;CACzE,IAAI,MAAM,SAAS,UAAU,OAAO,KAAA;CAGpC,IAAI,MAAM,KAAK,MAAM,QAAQ,IAAI,WAAW,CAAC,GAAG,OAAO;CACvD,MAAM,MAAM,CAAC,GAAG,GAAG;CACnB,KAAK,MAAM,OAAO,MAAM,MAAM;EAE5B,IAAI,UAAsB,CAAC,CAAC,CAAC;EAC7B,KAAK,MAAM,QAAQ,KAAK;GACtB,MAAM,OAAO,OAAO,IAAI,IAAI,KAAK,CAAC;GAClC,IAAI,QAAQ,SAAS,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,UAAU;IAAgB,QAAQ;GAAK;EAC3C;EACA,OAAO;GAAE,MAAM;GAAe,QAAQ;EAAK;CAC7C,CACF;CACA,OAAO,CACL;EACE,MAAM;EACN,OAAO;EACP,MAAM;GACJ;IAAE,MAAM;IAAQ,OAAO;IAAgB,UAAU;KAAC,CAAC,GAAG,CAAC;KAAG,CAAC,IAAK,EAAG;KAAG,CAAC,GAAG,GAAI;KAAG,CAAC,GAAG,IAAK;KAAG,CAAC,IAAI,CAAC;IAAC;IAAG,QAAQ;GAAa;GAC5H;IAAE,MAAM;IAAQ,OAAO;IAAqB,UAAU;KAAC,CAAC,GAAG,CAAC;KAAG,CAAC,GAAG,EAAG;KAAG,CAAC,GAAG,EAAG;KAAG,CAAC,IAAI,CAAC;IAAC;IAAG,QAAQ;GAAS;GAC9G;IAAE,MAAM;IAAc,OAAO;IAA0B,UAAU;KAAC,CAAC,GAAG,CAAC;KAAG,CAAC,GAAG,EAAG;KAAG,CAAC,GAAG,CAAC;IAAC;IAAG,QAAQ;GAAS;EAChH;EACA,aAAa;CACf,GACA;EAAE,MAAM;EAAQ,OAAO;EAAQ,MAAM,CAAC;CAAE,CAC1C;CACA,QAAQ,CACN;EAAE,MAAM;EAAS,OAAO;EAAQ,SAAS;EAAK,OAAO;EAAG,QAAQ;EAAU,MAAM;CAAa,GAC7F;EAAE,MAAM;EAAQ,OAAO;EAAQ,SAAS;EAAO,OAAO;EAAG,QAAQ;EAAU,MAAM;CAAa,CAChG;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/stops.ts","../src/shortfall.ts","../src/sample.ts"],"sourcesContent":["import { DEFAULT_MAX_SETS, stopSets, type Stack } from \"@mark1russell7/system-stack\";\n\n// The minimal stop sets of a supply from the structure of the needs. The index does not give this entry: `stopCurves` uses it.\n\n/**\n * This function gives the minimal sets of cuts that stop a supply, from the paths of the needs of the stack (`stopSets` of the core).\n * A set is a list of indexes of `parts`, from the smallest set. Two sets of one size are in the order of `minimalStops`.\n *\n * - `parts` has the part of each cut that counts. Two cuts of one part are two cuts: each one stops what the part stops.\n * - A cut of the supply stops it alone. The other sets come from `stopSets` with the cut parts as `among`, so no other part can fail.\n * - The parts of `down` are down for the full event. The caller makes sure that they do not stop the supply with no cut.\n * - The result is `undefined` when the search passes its budget, or when the sets of cuts are more than `maxSets`.\n *\n * @param stack - The base stack\n * @param supply - The part of the supply of a draw\n * @param parts - The part of each cut that counts\n * @param down - The parts that are down for the full event\n * @param maxSets - The largest count of sets in one step of the search, and of the sets of cuts (`maxSets` of `stopSets`)\n */\nexport function stackStops(stack: Stack, supply: string, parts: readonly string[], down: readonly string[] = [], maxSets: number = DEFAULT_MAX_SETS): number[][] | undefined {\n const cutsOf = new Map<string, number[]>();\n for (const [index, part] of parts.entries()) cutsOf.set(part, [...(cutsOf.get(part) ?? []), index]);\n const own = (cutsOf.get(supply) ?? []).map((index) => [index]);\n const among = [...cutsOf.keys()].filter((part) => part !== supply);\n const found = stopSets(stack, supply, { down, among, size: among.length, maxSets });\n if (found.kind === \"budget\") return undefined;\n // The empty set: the supply is not in the stack, or it does not work in the base stack.\n // In both, `stopped` of the core does not count it as stopped, so only a cut of the supply stops it.\n if (found.sets.some((set) => set.length === 0)) return own;\n const out = [...own];\n for (const set of found.sets) {\n // Each choice of one cut for each part of the set is a minimal set of cuts.\n let choices: number[][] = [[]];\n for (const part of set) {\n const cuts = cutsOf.get(part) ?? [];\n if (choices.length * cuts.length + out.length > maxSets) return undefined;\n choices = choices.flatMap((choice) => cuts.map((cut) => [...choice, cut]));\n }\n out.push(...choices.map((choice) => choice.sort((x, y) => x - y)));\n }\n return out.sort(byMask);\n}\n\n/** The order of `minimalStops`: the smaller set first, then the set whose largest different index is smaller. */\nfunction byMask(a: readonly number[], b: readonly number[]): number {\n if (a.length !== b.length) return a.length - b.length;\n for (let index = a.length - 1; index >= 0; index -= 1) {\n const difference = (a[index] ?? 0) - (b[index] ?? 0);\n if (difference !== 0) return difference;\n }\n return 0;\n}\n","import { type OrderedRing, pathSetReliability, stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { DEFAULT_MAX_SETS, neededParts, type PathOptions } from \"@mark1russell7/system-stack\";\nimport { caseDraws, caseStopped, enduranceOf, type CaseOptions } from \"./endurance.ts\";\nimport type { CaseCuts, Draw, Endurance, EnduranceLayer, Prior, Survival } from \"./layer.ts\";\nimport { stackStops } from \"./stops.ts\";\n\n// The shortfall: the user-days in which a draw does not get its need, for one case and for one year.\n\n/** This function gives the chance that a cut lasts more than `days`, linear between the points of the curve. After the last point it is 0. */\nexport function survivalAt(curve: Survival, days: number): number {\n if (days <= 0) return curve[0]?.[1] ?? 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (days < t1) {\n // The chance stays between the chances of the two points, so a rounding does not go below the lower one.\n const chance = p0 + (p1 - p0) * ((days - t0) / (t1 - t0));\n return Math.min(Math.max(p0, p1), Math.max(Math.min(p0, p1), chance));\n }\n if (days === t1) return p1;\n }\n return 0;\n}\n\n/**\n * This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.\n * It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.\n * With no horizon, the area goes to the end of the curve.\n */\nexport function tailDays(curve: Survival, from: number, to: number = Infinity): number {\n let area = 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0] = curve[index - 1] ?? [0, 1];\n const [t1] = curve[index] ?? [0, 0];\n const start = Math.max(t0, from);\n const end = Math.min(t1, to);\n if (start < end) area += ((survivalAt(curve, start) + survivalAt(curve, end)) / 2) * (end - start);\n }\n return area;\n}\n\n/**\n * The options of a shortfall: the stack or the parts that are also down, as for `enduranceOf`, and a horizon.\n * With a horizon of `h` days, the shortfall counts only the first `h` days of each cut. A draw that holds `h` days has no shortfall.\n * Thus a plan can aim at a target, for example 14 days and then 90 days.\n */\n/**\n * The options of `stopCurves`. With a stack, `maxSets` is the budget of the search of the needs (`stopSets` of the core).\n * When the search passes it, `minimalStops` gives the sets.\n */\nexport interface StopCurveOptions extends Pick<CaseOptions, \"stack\" | \"down\">, Pick<PathOptions, \"maxSets\"> {\n /** The budget of `independentStop` for the curve of each draw, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`. */\n readonly maxWork?: number | undefined;\n}\n\nexport interface ShortfallOptions extends StopCurveOptions {\n /** The horizon in days, more than 0. The default is no horizon. */\n readonly horizon?: number | undefined;\n}\n\nfunction horizonOf(options: ShortfallOptions): number {\n const horizon = options.horizon ?? Infinity;\n if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);\n return horizon;\n}\n\nfunction budgetsOf(options: StopCurveOptions): { readonly maxSets: number; readonly maxWork: number } {\n const maxSets = options.maxSets ?? DEFAULT_MAX_SETS;\n if (!Number.isInteger(maxSets) || maxSets < 1) throw new RangeError(`The option maxSets is ${String(options.maxSets)}: it is not a whole number from 1.`);\n const maxWork = options.maxWork ?? INDEPENDENT_MAX_WORK;\n if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The option maxWork is ${String(options.maxWork)}: it is not a whole number from 1.`);\n return { maxSets, maxWork };\n}\n\n/**\n * This function gives the days at which the chance of the curve falls to `chance`. With `0.1`, it is the 90th percentile of the duration.\n * When the curve does not fall to `chance`, the result is `Infinity`.\n */\nexport function survivalQuantile(curve: Survival, chance: number): number {\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (p0 <= chance) return t0;\n if (p1 <= chance) return t0 + ((p0 - chance) * (t1 - t0)) / (p0 - p1);\n }\n return Infinity;\n}\n\n/** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */\nexport function yearChance(prior: Prior): number {\n return 1 - Math.exp(-prior.perYear * prior.reach);\n}\n\n/** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */\nexport function yearRate(prior: Prior): number {\n return prior.perYear * prior.reach;\n}\n\n/** This function gives the times at which a curve of the result can bend: each point of each curve, and each crossing of two curves. */\nfunction bendTimes(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const out = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n for (const [i, a] of curves.entries()) {\n for (const b of curves.slice(i + 1)) {\n const d0 = survivalAt(a, t0) - survivalAt(b, t0);\n const d1 = survivalAt(a, t1) - survivalAt(b, t1);\n if (d0 * d1 < 0) out.add(t0 + ((t1 - t0) * d0) / (d0 - d1));\n }\n }\n }\n return [...out].sort((x, y) => x - y);\n}\n\n/**\n * This function makes a survival curve from a chance at each time. It stops at the first chance of 0, and it removes an increase of rounding.\n *\n * @throws RangeError when the chance at the last time is more than 0, as for curves that do not end at a chance of 0\n */\nfunction curveFrom(times: readonly number[], chanceAt: (days: number) => number): Survival {\n const out: [number, number][] = [];\n for (const days of times) {\n const chance = Math.min(out[out.length - 1]?.[1] ?? 1, chanceAt(days));\n out.push([days, chance]);\n if (chance === 0) return out;\n }\n throw new RangeError(\"The curves do not fall to a chance of 0 at their last point.\");\n}\n\n/**\n * This function gives the curve of a stop of some cuts when one event makes each cut longer together.\n * At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.\n *\n * - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).\n * - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.\n * - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.\n * - When no set of cuts stops the supply, the result is `[[0, 0]]`. This curve does not start at `[0, 1]`, so `checkEndurance` refuses it.\n *\n * The result is not a limit. When the cuts are independent, a stop of two cuts in series can be longer. A stop through a need of `any` can be shorter.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param stops - This function tells if the cuts of a list of indexes stop the supply. A larger list stops it when a smaller list does.\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function eventStop(curves: readonly Survival[], stops: (cuts: readonly number[]) => boolean): Survival {\n return curveFrom(bendTimes(curves), (days) => {\n const chances = curves.map((curve) => survivalAt(curve, days));\n for (const level of [...new Set(chances)].sort((x, y) => y - x)) {\n if (stops(chances.flatMap((chance, index) => (chance >= level ? [index] : [])))) return level;\n }\n return 0;\n });\n}\n\n/**\n * This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.\n * It is `eventStop` when any one cut stops the supply.\n *\n * @param curves - The curves, each one good for `checkEndurance`\n * @throws RangeError when there is no curve, or when a curve does not end at a chance of 0\n */\nexport function longestStop(curves: readonly Survival[]): Survival {\n const first = curves[0];\n if (first === undefined) throw new RangeError(\"longestStop needs one or more curves.\");\n return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);\n}\n\n/**\n * The largest count of cuts for which `minimalStops` examines each set, and for which `independentStop` adds the chance of each state.\n * With a stack, `stopCurves` finds the minimal sets from the needs, so a larger count of cuts can have exact sets.\n */\nexport const MINIMAL_STOP_CUTS = 12;\n\n/**\n * This function gives the minimal sets of cuts that stop the supply: each set stops it, and no smaller part of a set stops it.\n * With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.\n */\nexport function minimalStops(count: number, stops: (cuts: readonly number[]) => boolean): number[][] | undefined {\n if (count > MINIMAL_STOP_CUTS) return undefined;\n const found: number[][] = [];\n const masks: number[] = [];\n const all = Array.from({ length: 1 << count }, (_, mask) => mask).sort((x, y) => popCount(x) - popCount(y) || x - y);\n for (const mask of all) {\n if (mask === 0 || masks.some((other) => (other & mask) === other)) continue;\n const cuts = Array.from({ length: count }, (_, index) => index).filter((index) => (mask >> index) & 1);\n if (!stops(cuts)) continue;\n masks.push(mask);\n found.push(cuts);\n }\n return found;\n}\n\nfunction popCount(mask: number): number {\n let total = 0;\n for (let rest = mask; rest > 0; rest &= rest - 1) total += 1;\n return total;\n}\n\n/**\n * This function gives an upper limit of the curve of a stop for each dependence of the cuts.\n * At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.\n * With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.\n *\n * @param curves - The curves of the cuts\n * @param sets - The minimal sets of `minimalStops`, or `undefined`\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function upperStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival {\n const groups = sets ?? curves.map((_, index) => [index]);\n const sum = (days: number): number => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);\n // The sum is linear between two times of bendTimes. A point where it falls through 1 is a bend of min(1, sum).\n const times = bendTimes(curves);\n const bends = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n const s0 = sum(t0) - 1;\n const s1 = sum(t1) - 1;\n if (s0 * s1 < 0) bends.add(t0 + ((t1 - t0) * s0) / (s0 - s1));\n }\n return curveFrom([...bends].sort((x, y) => x - y), (days) => Math.min(1, sum(days)));\n}\n\n/** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */\nexport const INDEPENDENT_TOLERANCE = 1e-6;\n\n/**\n * The default budget of `independentStop` for its groups of more than `MINIMAL_STOP_CUTS` cuts.\n * The budget counts the steps of the expansion times the count of points of the curve.\n * It is near the work of the sum over the states of 12 cuts.\n */\nexport const INDEPENDENT_MAX_WORK: number = 2 ** 26;\n\n/**\n * This function gives the curve of a stop of some cuts when the cuts are independent.\n * At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.\n * Its chance is a sum over each set of cuts that stops the supply.\n * Each term is the product of `s(t)` for the cuts that are on, and of `1 - s(t)` for the other cuts.\n *\n * - When any one cut stops the supply, the result is `1 - prod(1 - s)`. It is not less than the longest cut (`eventStop`).\n * - When the supply needs `any` of two parts, the stop of the two is `s1 * s2`. It is not more than the shorter cut.\n * - The result is not more than `upperStop` of the same sets, because `upperStop` is a limit for each dependence.\n * - Between two points of the curves the chance is a polynomial, not a line. The function splits each such segment into equal pieces.\n * The chance is linear in each `s`, and each mixed second derivative is between -1 and 1.\n * Thus `|f''| <= (sum |s'|)^2 - sum s'^2`, and the line of a piece of length `h` is within `h^2 |f''| / 8` of the chance.\n * The count of pieces keeps each line within `INDEPENDENT_TOLERANCE`. With a margin of 10 %, the count of points is less than `n / sqrt(7.2 * INDEPENDENT_TOLERANCE)` plus the segments, for `n` cuts.\n *\n * - Up to `MINIMAL_STOP_CUTS` cuts in the sets, the function adds the chance of each of the 2 to the power of that count of states.\n * - Two groups of cuts that share no set are independent, so the chance that the supply works is the product over the groups.\n * For example, 20 stages of 2 feeds give 20 groups of 2 cuts.\n * - In a group of more than `MINIMAL_STOP_CUTS` cuts, it uses the Shannon expansion of `pathSetReliability` of collections.\n * The expansion merges two states with the same sets left, and it drops a set that holds another set.\n * - The expansion is exponential in the worst case. The groups share one budget, `maxWork`.\n * When the steps of the expansions times the count of points of the curve pass it, the result is `undefined`.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @param sets - The minimal sets of the cuts. With `undefined`, as for no minimal sets, the result is `undefined`. With no sets, it is `[[0, 0]]`\n * @param maxWork - The budget of the expansions of the groups of more than `MINIMAL_STOP_CUTS` cuts, a whole number from 1. The default is `INDEPENDENT_MAX_WORK`\n * @throws RangeError when a curve does not end at a chance of 0, or for a bad `maxWork`\n */\nexport function independentStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined, maxWork: number = INDEPENDENT_MAX_WORK): Survival | undefined {\n if (!Number.isInteger(maxWork) || maxWork < 1) throw new RangeError(`The budget maxWork is ${String(maxWork)}: it is not a whole number from 1.`);\n if (sets === undefined) return undefined;\n // With no set, no cuts stop the supply, as for `eventStop` and `upperStop`.\n if (sets.length === 0) return [[0, 0]];\n // Only the cuts of a set change the chance. Their place in `used` is their index in the sets of the cuts that count.\n const used = [...new Set(sets.flat())].sort((x, y) => x - y);\n const usedCurves = used.map((index) => curves[index] ?? []);\n const usedSets = sets.map((set) => set.map((index) => used.indexOf(index)));\n const points = independentPoints(usedCurves);\n // Two groups of cuts that share no set are independent: the supply works when it works in each group.\n const groupChances: ((days: number) => number)[] = [];\n // The expansions of all groups share one budget.\n let work = maxWork;\n for (const group of cutGroups(used.length, usedSets)) {\n const curvesOf = group.map((index) => usedCurves[index] ?? []);\n const setsOf = usedSets.filter((set) => group.includes(set[0] ?? -1)).map((set) => set.map((index) => group.indexOf(index)));\n // Up to MINIMAL_STOP_CUTS cuts, the sum over the states is exact with a fixed cost. Past them, the expansion is exact within its budget.\n if (group.length <= MINIMAL_STOP_CUTS) {\n groupChances.push(stateChance(curvesOf, setsOf));\n continue;\n }\n const expanded = expandedChances(curvesOf, setsOf, points, work);\n if (expanded === undefined) return undefined;\n work -= expanded.steps * points.length;\n const chanceOf = new Map(points.map((days, index) => [days, expanded.chances[index] ?? 0]));\n groupChances.push((days) => {\n const chance = chanceOf.get(days);\n if (chance === undefined) throw new Error(`The expansion has no chance at ${String(days)} days.`);\n return chance;\n });\n }\n // With one group, the chance of the group is the result, with no rounding of 1 - (1 - chance).\n const [only] = groupChances;\n if (groupChances.length === 1 && only !== undefined) return curveFrom(points, only);\n return curveFrom(points, (days) => Math.min(1, Math.max(0, 1 - groupChances.reduce((works, chanceAt) => works * (1 - chanceAt(days)), 1))));\n}\n\n/** The groups of the cuts `0` to `count - 1`: two cuts are in one group when a chain of sets joins them. Each set has its cuts in one group. */\nfunction cutGroups(count: number, sets: readonly (readonly number[])[]): number[][] {\n const next = Array.from({ length: count }, () => new Set<number>());\n // A cycle through the cuts of each set joins them both ways, so the strongly connected components are the groups.\n for (const set of sets) for (const [at, index] of set.entries()) next[index]?.add(set[(at + 1) % set.length] ?? index);\n return stronglyConnectedComponents(\n Array.from({ length: count }, (_, index) => index),\n (index) => next[index] ?? [],\n );\n}\n\n/** The times of `independentStop`: the points of the curves, and the pieces that keep each line within `INDEPENDENT_TOLERANCE`. */\nfunction independentPoints(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const points: number[] = [];\n for (const [index, t1] of times.entries()) {\n const t0 = times[index - 1];\n if (t0 !== undefined) {\n const h = t1 - t0;\n const slopes = curves.map((curve) => Math.abs(survivalAt(curve, t1) - survivalAt(curve, t0)) / h);\n const sum = slopes.reduce((total, slope) => total + slope, 0);\n const bound = Math.max(0, sum * sum - slopes.reduce((total, slope) => total + slope * slope, 0));\n // A margin of 10 % keeps the rounding of the chance under the tolerance.\n const pieces = Math.ceil(h * Math.sqrt(bound / (8 * 0.9 * INDEPENDENT_TOLERANCE)));\n for (let piece = 1; piece < pieces; piece += 1) {\n const days = t0 + (h * piece) / pieces;\n // Two times that are next to each other as floats have no time between them.\n if (days > (points[points.length - 1] ?? t0) && days < t1) points.push(days);\n }\n }\n points.push(t1);\n }\n return points;\n}\n\n/** The chance of a stop at a time, as the sum over each state of `MINIMAL_STOP_CUTS` cuts or fewer. Bit k of a state is 1 when cut k is on. */\nfunction stateChance(curves: readonly Survival[], sets: readonly (readonly number[])[]): (days: number) => number {\n const setMasks = sets.map((set) => set.reduce((mask, index) => mask | (1 << index), 0));\n const stopping = Array.from({ length: 1 << curves.length }, (_, mask) => setMasks.some((set) => (set & mask) === set));\n const states = new Float64Array(1 << curves.length);\n return (days) => {\n // The chance of each state of the cuts, one cut at a time.\n states[0] = 1;\n let length = 1;\n for (const curve of curves) {\n const on = survivalAt(curve, days);\n for (let mask = 0; mask < length; mask += 1) {\n const chance = states[mask] ?? 0;\n states[mask + length] = chance * on;\n states[mask] = chance * (1 - on);\n }\n length *= 2;\n }\n let total = 0;\n for (let mask = 0; mask < length; mask += 1) if (stopping[mask]) total += states[mask] ?? 0;\n return Math.min(1, Math.max(0, total));\n };\n}\n\n/** The count of times in one expansion of `expandedChances`: the length of the vectors of its ring. */\nconst EXPANSION_WIDTH = 64;\n\n/**\n * The ring of the vectors of `width` chances, one for each time, for `pathSetReliability` of collections.\n * Each operation is on each time alone. In the order, `a` is less than `b` when it is less or equal at each time, and not equal.\n */\nfunction vectorRing(width: number): OrderedRing<Float64Array> {\n const zip = (a: Float64Array, b: Float64Array, op: (x: number, y: number) => number): Float64Array => {\n const out = new Float64Array(width);\n for (let index = 0; index < width; index += 1) out[index] = op(a[index] ?? 0, b[index] ?? 0);\n return out;\n };\n return {\n zero: new Float64Array(width),\n one: new Float64Array(width).fill(1),\n add: (a, b) => zip(a, b, (x, y) => x + y),\n sub: (a, b) => zip(a, b, (x, y) => x - y),\n mul: (a, b) => zip(a, b, (x, y) => x * y),\n compare: (a, b) => {\n let less = false;\n let more = false;\n for (let index = 0; index < width; index += 1) {\n const [x, y] = [a[index] ?? 0, b[index] ?? 0];\n if (x < y) less = true;\n else if (x > y) more = true;\n else if (x !== y) return Number.NaN;\n }\n return less ? (more ? Number.NaN : -1) : more ? 1 : 0;\n },\n };\n}\n\n/**\n * The chance of a stop at each point, from the Shannon expansion of `pathSetReliability`. A set works when each of its cuts is on.\n * One call gives `EXPANSION_WIDTH` points. When the steps of one expansion times the count of points pass `maxWork`, the result is `undefined`.\n * Else `steps` is the count of steps of one expansion.\n */\nfunction expandedChances(\n curves: readonly Survival[],\n sets: readonly (readonly number[])[],\n points: readonly number[],\n maxWork: number,\n): { readonly chances: number[]; readonly steps: number } | undefined {\n const maxSteps = Math.floor(maxWork / points.length);\n if (maxSteps < 1) return undefined;\n const out: number[] = [];\n let steps = 0;\n for (let start = 0; start < points.length; start += EXPANSION_WIDTH) {\n const times = points.slice(start, start + EXPANSION_WIDTH);\n const chances = curves.map((curve) => Float64Array.from(times, (days) => survivalAt(curve, days)));\n const result = pathSetReliability(sets, chances, vectorRing(times.length), { maxSteps });\n // Each call has the same sets, so the first call tells if the expansion is in the budget.\n if (result.kind === \"budget\") return undefined;\n steps = result.steps;\n for (const chance of result.value) out.push(Math.min(1, Math.max(0, chance)));\n }\n return { chances: out, steps };\n}\n\n/**\n * The curves of the stop of a draw. `event` is for one event that makes each cut longer together, and `independent` is for independent cuts.\n * `upper` is an upper limit for each dependence.\n */\nexport interface StopCurves {\n readonly event: Survival;\n /** The stop when the cuts are independent (`independentStop`). When `independentUpper` is true, it is `upper`. */\n readonly independent: Survival;\n readonly upper: Survival;\n /**\n * This is true when `upper` is the sum of the curves of the cuts that count, because the query has no minimal sets.\n * With a stack, the search of the needs passed its budget. With no stack, more than `MINIMAL_STOP_CUTS` cuts count.\n */\n readonly coarse: boolean;\n /** This is true when `independent` is `upper`: `coarse` is true, or the expansion of `independentStop` passed its budget. */\n readonly independentUpper: boolean;\n}\n\n/** This function gives the parts of the stack that are down for a list of cut indexes. A case uses one memo for each of its draws. */\ntype StoppedOf = (cuts: readonly number[]) => ReadonlySet<string>;\n\nfunction stoppedMemo(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): StoppedOf {\n const memo = new Map<string, ReadonlySet<string>>();\n return (cuts) => {\n const key = cuts.join(\",\");\n let found = memo.get(key);\n if (found === undefined) {\n found = caseStopped({ ...caseCuts, cuts: cuts.flatMap((index) => caseCuts.cuts[index] ?? []) }, options);\n memo.set(key, found);\n }\n return found;\n };\n}\n\n/** This function gives the parts whose cut can stop a supply: the supply, and each part that it needs through the stack. */\nfunction supplyReach(supply: string, options: Pick<CaseOptions, \"stack\">): Set<string> {\n const reach = options.stack === undefined ? new Set<string>() : neededParts(options.stack, supply);\n reach.add(supply);\n return reach;\n}\n\nfunction stopCurvesWith(caseCuts: CaseCuts, draw: Draw, options: StopCurveOptions, stoppedOf: StoppedOf): StopCurves | undefined {\n const reach = supplyReach(draw.supply, options);\n const relevant = caseCuts.cuts.flatMap((cut, index) => (reach.has(cut.part) ? [index] : []));\n const stops = (cuts: readonly number[]): boolean => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);\n if (stops([])) return undefined;\n if (!stops(relevant.map((_, index) => index))) return undefined;\n const given = relevant.map((index) => caseCuts.cuts[index]?.duration);\n // With a stack, the needs give the minimal sets. When their search passes its budget, the sets of each list of cuts are the check.\n const parts = relevant.map((index) => caseCuts.cuts[index]?.part ?? \"\");\n const structural = options.stack === undefined ? undefined : stackStops(options.stack, draw.supply, parts, options.down, budgetsOf(options).maxSets);\n const sets = structural ?? minimalStops(given.length, stops);\n // The stop has no curve when a cut with no curve can be part of it. With no minimal sets, the query cannot tell.\n const unsourced = given.flatMap((curve, index) => (curve === undefined ? [index] : []));\n if (unsourced.length > 0 && (sets === undefined || sets.some((set) => set.some((index) => unsourced.includes(index))))) return undefined;\n // A cut with no curve is in no minimal set here, so it does not change a stop. The curves do not include it.\n const kept = given.flatMap((curve, index) => (curve === undefined ? [] : [index]));\n const curves = kept.map((index) => given[index] ?? []);\n const keptStops = (cuts: readonly number[]): boolean => stops(cuts.map((index) => kept[index] ?? -1));\n const keptSets = sets?.map((set) => set.map((index) => kept.indexOf(index)));\n const upper = upperStop(curves, keptSets);\n const independent = independentStop(curves, keptSets, budgetsOf(options).maxWork);\n return { event: eventStop(curves, keptStops), independent: independent ?? upper, upper, coarse: keptSets === undefined, independentUpper: independent === undefined };\n}\n\n/**\n * This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.\n *\n * - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.\n * - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.\n * - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.\n * - With a stack, the minimal sets come from the paths of the needs (`stopSets` of the core), so the count of cuts has no limit of `MINIMAL_STOP_CUTS`.\n * When that search passes its budget (the option `maxSets`), `minimalStops` examines each set of up to `MINIMAL_STOP_CUTS` cuts.\n * - A cut with no `duration` gives no curve when it is in a minimal set, or when the query has no minimal sets.\n * - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.\n * - With no minimal sets, `upper` is the sum of the curves, `independent` is `upper`, and `coarse` is true.\n * - When the expansion of `independentStop` passes its budget, `independent` is `upper`, and `independentUpper` is true.\n */\nexport function stopCurves(caseCuts: CaseCuts, draw: Draw, options: StopCurveOptions = {}): StopCurves | undefined {\n budgetsOf(options);\n return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));\n}\n\n/** The shortfall of each level, in user-days, and the draws that the query cannot read. */\nexport interface Shortfall {\n /**\n * The user-days of each level of the layer, when one event makes each cut longer together. The query does not add two levels.\n * This value is not a limit. The true value can be more or less. `upper` is the limit.\n */\n readonly levels: Readonly<Record<string, number>>;\n /** The user-days of each level when the cuts are independent (`StopCurves.independent`). This value is not more than `upper`. */\n readonly independent: Readonly<Record<string, number>>;\n /** The upper limit of the user-days of each level, for each dependence of the cuts. A gate of a high level can use it. */\n readonly upper: Readonly<Record<string, number>>;\n /**\n * The needs of the draws whose stop has no curve (`stopCurves`).\n * The query has no curve of their duration, so their shortfall is not in `levels`. A gate shows them as no read.\n */\n readonly unread: readonly string[];\n /** The needs of the draws whose `upper` is coarse (`StopCurves.coarse`). A gate on `upper` shows them. */\n readonly coarse: readonly string[];\n /** The needs of the draws whose `independent` is `upper` (`StopCurves.independentUpper`). A gate on `independent` shows them. */\n readonly independentUpper: readonly string[];\n}\n\nfunction zeroLevels(layer: EnduranceLayer): Record<string, number> {\n return Object.fromEntries(layer.levels.map((level) => [level, 0]));\n}\n\n/**\n * This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.\n * `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param endurance - The endurance of the case, from `enduranceOf`\n * @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon\n * @throws RangeError when the horizon is not a number more than 0, or `maxSets` is not a whole number from 1\n */\nexport function caseShortfall(layer: EnduranceLayer, caseCuts: CaseCuts, endurance: Endurance, options: ShortfallOptions = {}): Shortfall {\n const horizon = horizonOf(options);\n budgetsOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const stoppedOf = stoppedMemo(caseCuts, options);\n for (const draw of caseDraws(layer, caseCuts, caseStopped(caseCuts, options))) {\n const held = endurance.needs[draw.need];\n const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);\n if (held === undefined || curves === undefined) {\n unread.push(draw.need);\n continue;\n }\n if (curves.coarse) coarse.push(draw.need);\n if (curves.independentUpper) independentUpper.push(draw.need);\n const users = draw.users ?? 1;\n levels[draw.level] = (levels[draw.level] ?? 0) + tailDays(curves.event, held.days, horizon) * users;\n independent[draw.level] = (independent[draw.level] ?? 0) + tailDays(curves.independent, held.days, horizon) * users;\n upper[draw.level] = (upper[draw.level] ?? 0) + tailDays(curves.upper, held.days, horizon) * users;\n }\n return { levels, independent, upper, unread, coarse, independentUpper };\n}\n\n/** The shortfall of one year at one place, with the part of each case. */\nexport interface YearShortfall extends Shortfall {\n readonly place: string;\n /** The part of each case. `rate` is the expected count of its events in one year. */\n readonly cases: readonly { readonly case: string; readonly rate: number; readonly endurance: Endurance; readonly shortfall: Shortfall }[];\n}\n\n/**\n * This function gives the shortfall of one year at one place.\n * It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.\n *\n * - The expected count of a case is `perYear * reach`, from the first prior of the case at the place. Thus the result is the expected user-days of one year.\n * - A case with no prior at the place is not in the sum.\n * - `unread` is the union of the needs that a case cannot read, in the order of the cases. `coarse` and `independentUpper` are unions too.\n *\n * @param layer - The endurance layer, with its cases and priors\n * @param place - The place of the priors\n * @param options - The date, the stack or the parts that are also down, and the horizon\n * @throws RangeError for a bad date, horizon or `maxSets`: refer to `caseShortfall` and `enduranceOf`\n */\nexport function yearShortfall(layer: EnduranceLayer, place: string, options: CaseOptions & ShortfallOptions): YearShortfall {\n horizonOf(options);\n budgetsOf(options);\n const levels = zeroLevels(layer);\n const independent = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const independentUpper: string[] = [];\n const cases: YearShortfall[\"cases\"][number][] = [];\n for (const caseCuts of layer.cases ?? []) {\n const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);\n if (prior === undefined) continue;\n const rate = yearRate(prior);\n const endurance = enduranceOf(layer, caseCuts, options);\n const shortfall = caseShortfall(layer, caseCuts, endurance, options);\n for (const [level, days] of Object.entries(shortfall.levels)) levels[level] = (levels[level] ?? 0) + rate * days;\n for (const [level, days] of Object.entries(shortfall.independent)) independent[level] = (independent[level] ?? 0) + rate * days;\n for (const [level, days] of Object.entries(shortfall.upper)) upper[level] = (upper[level] ?? 0) + rate * days;\n for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);\n for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);\n for (const need of shortfall.independentUpper) if (!independentUpper.includes(need)) independentUpper.push(need);\n cases.push({ case: caseCuts.case, rate, endurance, shortfall });\n }\n return { place, levels, independent, upper, unread, coarse, independentUpper, cases };\n}\n","import { STACK_SCHEMA, type Stack } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// A sample: a building with 3 users, and a storm that cuts the grid, the road and the water main.\n// Each name and each value is an example, except the grid curve (NREL, technical report 83092). The tests, the README files and the site use it.\n\n/** The base stack of the sample: the supplies of the building and a camp stove. */\nexport const SAMPLE_ENDURANCE_STACK: Stack = {\n schema: STACK_SCHEMA,\n parts: [\n { id: \"grid\", kind: \"power\", name: \"The power grid\" },\n { id: \"water-main\", kind: \"water\", name: \"The water main\" },\n { id: \"road\", kind: \"road\", name: \"The local road to the shops\" },\n { id: \"stove\", kind: \"device\", name: \"The camp stove\" },\n ],\n};\n\n/**\n * The endurance layer of the sample.\n *\n * - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.\n * - The food holds 4800 / 5400 = 0.889 days. The rice needs 2 L of water for each kg, and the drinking water keeps back all the water.\n * - The power holds 1000 Wh / 150 Wh a day = 6.667 days.\n * - The filled bottles are past their due date, so they give nothing.\n */\nexport const SAMPLE_ENDURANCE: EnduranceLayer = {\n schema: ENDURANCE_SCHEMA,\n levels: [\"life\", \"health\", \"comfort\"],\n resources: [\n { code: \"water.stored\", unit: \"L\" },\n { code: \"food.ready\", unit: \"kcal\" },\n { code: \"food.grain-dry\", unit: \"kg\" },\n { code: \"fuel.propane\", unit: \"kg\" },\n { code: \"energy.battery\", unit: \"Wh\" },\n ],\n stores: [\n { id: \"jugs\", resource: \"water.stored\", amount: 75.7, due: \"2028-06-01\" },\n { id: \"bottles\", resource: \"water.stored\", amount: 20, due: \"2026-09-30\" },\n { id: \"cans\", resource: \"food.ready\", amount: 4800, due: \"2028-10-01\" },\n { id: \"rice\", resource: \"food.grain-dry\", amount: 9, due: \"2036-09-28\" },\n { id: \"propane\", resource: \"fuel.propane\", amount: 0.908, due: \"2036-10-01\" },\n { id: \"battery\", resource: \"energy.battery\", amount: 1000, due: \"2031-10-01\" },\n ],\n draws: [\n { need: \"hydration.drink\", level: \"life\", perDay: 11.355, users: 3, supply: \"water-main\" },\n { need: \"food.energy\", level: \"health\", perDay: 5400, users: 3, supply: \"road\" },\n { need: \"power.electric\", level: \"comfort\", perDay: 150, users: 3, supply: \"grid\" },\n ],\n direct: [\n { resource: \"water.stored\", need: \"hydration.drink\", amount: 1 },\n { resource: \"food.ready\", need: \"food.energy\", amount: 1 },\n { resource: \"energy.battery\", need: \"power.electric\", amount: 1 },\n ],\n converters: [\n {\n id: \"cook-rice\",\n device: \"stove\",\n takes: [\n { resource: \"food.grain-dry\", amount: 1 },\n { resource: \"water.stored\", amount: 2 },\n { resource: \"fuel.propane\", amount: 0.05 },\n ],\n gives: { need: \"food.energy\", amount: 3600 },\n },\n ],\n cases: [\n {\n case: \"storm\",\n title: \"Winter storm\",\n cuts: [\n { part: \"grid\", title: \"Power outage\", duration: [[0, 1], [0.5, 0.5], [1, 0.36], [7, 0.013], [30, 0]], source: \"nrel-83092\" },\n { part: \"road\", title: \"Closed local road\", duration: [[0, 1], [1, 0.6], [3, 0.2], [10, 0]], source: \"sample\" },\n { part: \"water-main\", title: \"No water from the main\", duration: [[0, 1], [2, 0.3], [7, 0]], source: \"sample\" },\n ],\n leadSeconds: 86_400,\n },\n { case: \"fire\", title: \"Fire\", cuts: [] },\n ],\n priors: [\n { case: \"storm\", place: \"home\", perYear: 0.8, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n { case: \"fire\", place: \"home\", perYear: 0.003, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n ],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,WAAW,OAAc,QAAgB,OAA0B,OAA0B,CAAC,GAAG,UAAkB,kBAA0C;CAC3K,MAAM,yBAAS,IAAI,IAAsB;CACzC,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GAAG,OAAO,IAAI,MAAM,CAAC,GAAI,OAAO,IAAI,IAAI,KAAK,CAAC,GAAI,KAAK,CAAC;CAClG,MAAM,OAAO,OAAO,IAAI,MAAM,KAAK,CAAC,EAAA,CAAG,KAAK,UAAU,CAAC,KAAK,CAAC;CAC7D,MAAM,QAAQ,CAAC,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,SAAS,SAAS,MAAM;CACjE,MAAM,QAAQ,SAAS,OAAO,QAAQ;EAAE;EAAM;EAAO,MAAM,MAAM;EAAQ;CAAQ,CAAC;CAClF,IAAI,MAAM,SAAS,UAAU,OAAO,KAAA;CAGpC,IAAI,MAAM,KAAK,MAAM,QAAQ,IAAI,WAAW,CAAC,GAAG,OAAO;CACvD,MAAM,MAAM,CAAC,GAAG,GAAG;CACnB,KAAK,MAAM,OAAO,MAAM,MAAM;EAE5B,IAAI,UAAsB,CAAC,CAAC,CAAC;EAC7B,KAAK,MAAM,QAAQ,KAAK;GACtB,MAAM,OAAO,OAAO,IAAI,IAAI,KAAK,CAAC;GAClC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AE;GACxC;IAAE,UAAU;IAAgB,QAAQ;GAAE;GACtC;IAAE,UAAU;IAAgB,QAAQ;GAAK;EAC3C;EACA,OAAO;GAAE,MAAM;GAAe,QAAQ;EAAK;CAC7C,CACF;CACA,OAAO,CACL;EACE,MAAM;EACN,OAAO;EACP,MAAM;GACJ;IAAE,MAAM;IAAQ,OAAO;IAAgB,UAAU;KAAC,CAAC,GAAG,CAAC;KAAG,CAAC,IAAK,EAAG;KAAG,CAAC,GAAG,GAAI;KAAG,CAAC,GAAG,IAAK;KAAG,CAAC,IAAI,CAAC;IAAC;IAAG,QAAQ;GAAa;GAC5H;IAAE,MAAM;IAAQ,OAAO;IAAqB,UAAU;KAAC,CAAC,GAAG,CAAC;KAAG,CAAC,GAAG,EAAG;KAAG,CAAC,GAAG,EAAG;KAAG,CAAC,IAAI,CAAC;IAAC;IAAG,QAAQ;GAAS;GAC9G;IAAE,MAAM;IAAc,OAAO;IAA0B,UAAU;KAAC,CAAC,GAAG,CAAC;KAAG,CAAC,GAAG,EAAG;KAAG,CAAC,GAAG,CAAC;IAAC;IAAG,QAAQ;GAAS;EAChH;EACA,aAAa;CACf,GACA;EAAE,MAAM;EAAQ,OAAO;EAAQ,MAAM,CAAC;CAAE,CAC1C;CACA,QAAQ,CACN;EAAE,MAAM;EAAS,OAAO;EAAQ,SAAS;EAAK,OAAO;EAAG,QAAQ;EAAU,MAAM;CAAa,GAC7F;EAAE,MAAM;EAAQ,OAAO;EAAQ,SAAS;EAAO,OAAO;EAAG,QAAQ;EAAU,MAAM;CAAa,CAChG;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/stack-endurance",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
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": {
|