@mark1russell7/stack-endurance 0.8.15 → 0.8.16
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 +13 -1
- package/build/add-on.d.ts +1 -1
- package/build/add-on.js +1 -1
- package/build/index.d.ts +66 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +79 -12
- package/build/index.js.map +1 -1
- package/build/{join-C9nJDe7B.js → join-D-KCebAf.js} +238 -38
- package/build/join-D-KCebAf.js.map +1 -0
- package/build/{layer-BdgJSBND.d.ts → layer-CNAZnao7.d.ts} +62 -2
- package/build/layer-CNAZnao7.d.ts.map +1 -0
- package/build/layer-a3Fr70Uh.js.map +1 -1
- package/build/schema.d.ts +1 -1
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +7 -1
- package/build/schema.js.map +1 -1
- package/package.json +2 -2
- package/build/join-C9nJDe7B.js.map +0 -1
- package/build/layer-BdgJSBND.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -38,6 +38,18 @@ Each function is a plain function with no clock, no network and no file. The uni
|
|
|
38
38
|
|
|
39
39
|
With a base stack, a cut also stops each part that cannot work without the cut part. Thus a pump that needs the grid stops with the grid.
|
|
40
40
|
|
|
41
|
+
## Food that grows: a converter with a season
|
|
42
|
+
|
|
43
|
+
A converter can have a `season`. It has a window of sow days in each year (`from` and `to` as `MM-DD`). It also has a delay to the harvest (`delayDays`) and the runs of each sowing (`runs`). For example, a bed of potatoes takes seed, and gives potatoes 100 days after its sow day. Since 0.8.16.
|
|
44
|
+
|
|
45
|
+
- The sow day of a year is the first day of its window on the start of the event or after it. A window can go across the end of the year.
|
|
46
|
+
- Each sowing takes the inputs of its runs from the stores before the first draw. When the seed is short, the sowing has fewer runs.
|
|
47
|
+
- The harvest adds the runs times the gift to the stock of its resource on its day. A converter with a season is not a maker of a take, and it has no `perDay` or `devices`.
|
|
48
|
+
- The query reads the sowings up to the horizon (`horizon` of `enduranceOf`, default `SEASON_HORIZON_DAYS` = 730). `start` moves the event in the year, and the stores stay the stores at `at`.
|
|
49
|
+
- `days` is the first stop of a draw. `again` gives the spans after it in which a harvest feeds the draw. `harvests` lists each sowing with its runs and its amount.
|
|
50
|
+
- The shortfall leaves out the fed spans (`heldTail`). For a layer with a season, `yearShortfall` gives the mean over `starts` start dates in the year (default `YEAR_STARTS` = 12). An event can start on any day.
|
|
51
|
+
- `bestEndurance` and `jointDays` refuse a layer with a season. A draw with a shared device and a season gets the same refusal. The seed of a sowing does not come from an earlier harvest, and a harvest does not spoil.
|
|
52
|
+
|
|
41
53
|
## The rule of shortfall
|
|
42
54
|
|
|
43
55
|
- For one draw in one case, the shortfall is `E[max(0, D - T)] * users`. `T` is the endurance of the draw. `D` is the duration of the stop of its supply.
|
|
@@ -215,4 +227,4 @@ In the sample, the rice needs 2 L of water for each kg. The drinking water holds
|
|
|
215
227
|
|
|
216
228
|
## The gate
|
|
217
229
|
|
|
218
|
-
`checkEndurance(layer, stack)` gives the faults of a layer. `ENDURANCE_CODES` lists the codes. The gate finds two records with one key, and an unknown level, resource or part. It also finds a value out of range, a bad date, an empty converter and a bad survival curve. Converters that make a resource from itself are a cycle, and the gate refuses them. Two counts of devices for one device are a fault (`endurance-devices`). A device with a limited converter and a converter with no limit is a warning (`endurance-device-mix`), because the converter with no limit uses no device-days. A draw with no way to get its need is a warning, and a cut with no curve is a warning.
|
|
230
|
+
`checkEndurance(layer, stack)` gives the faults of a layer. `ENDURANCE_CODES` lists the codes. The gate finds two records with one key, and an unknown level, resource or part. It also finds a value out of range, a bad date, an empty converter and a bad survival curve. Converters that make a resource from itself are a cycle, and the gate refuses them. Two counts of devices for one device are a fault (`endurance-devices`). A device with a limited converter and a converter with no limit is a warning (`endurance-device-mix`), because the converter with no limit uses no device-days. A draw with no way to get its need is a warning, and a cut with no curve is a warning. A bad season is a fault (`endurance-season`). A converter with a season is not part of a cycle, because its harvest comes after its sowing.
|
package/build/add-on.d.ts
CHANGED
package/build/add-on.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as checkEndurance, t as joinEndurance } from "./join-
|
|
1
|
+
import { r as checkEndurance, t as joinEndurance } from "./join-D-KCebAf.js";
|
|
2
2
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
3
3
|
import { parseEndurance } from "./schema.js";
|
|
4
4
|
// src/add-on.ts
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as DirectUse, c as ENDURANCE_SCHEMA, d as Gift, f as
|
|
1
|
+
import { _ as Season, a as DirectUse, c as ENDURANCE_SCHEMA, d as Gift, f as Harvest, g as Resource, h as Prior, i as CutBound, l as Endurance, m as MonthDay, n as Converter, o as Draw, p as IsoDate, r as Cut, s as DrawEndurance, t as CaseCuts, u as EnduranceLayer, v as Store, y as Survival } from "./layer-CNAZnao7.js";
|
|
2
2
|
import { CutBound as CutBound$1, Fault, LayerParse, LayerPiece, PathOptions, Stack, curveFault, survivalAt } from "@mark1russell7/system-stack";
|
|
3
3
|
/** The options of the queries of a case. */
|
|
4
4
|
export interface CaseOptions {
|
|
@@ -8,7 +8,20 @@ export interface CaseOptions {
|
|
|
8
8
|
readonly stack?: Stack | undefined;
|
|
9
9
|
/** The `id` of more parts that are down, with the cuts of the case. */
|
|
10
10
|
readonly down?: readonly string[] | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The first day of the event, for the sow days of each converter with a season (M2-grow). The default is `at`. The
|
|
13
|
+
* stores are the stores at `at`. Thus a query can move the event in the year and keep the stores.
|
|
14
|
+
*/
|
|
15
|
+
readonly start?: IsoDate | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The horizon in days, more than 0. A layer with no converter with a season does not use it in `enduranceOf`. With
|
|
18
|
+
* such a converter, the query reads the sowings up to the horizon, and a draw holds the horizon at most. The default
|
|
19
|
+
* is `SEASON_HORIZON_DAYS`.
|
|
20
|
+
*/
|
|
21
|
+
readonly horizon?: number | undefined;
|
|
11
22
|
}
|
|
23
|
+
/** The default horizon of a layer with a converter with a season: 730 days, thus two seasons of each year. */
|
|
24
|
+
export declare const SEASON_HORIZON_DAYS = 730;
|
|
12
25
|
/**
|
|
13
26
|
* This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.
|
|
14
27
|
* With a stack, it also gives each part that stops.
|
|
@@ -32,6 +45,16 @@ export declare function caseDraws(layer: EnduranceLayer, caseCuts: CaseCuts, sto
|
|
|
32
45
|
export declare function giftNeed(converter: Converter): string | undefined;
|
|
33
46
|
/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */
|
|
34
47
|
export declare function giftResource(converter: Converter): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* This function gives the sow days of a season, in days from the start of the event, before the horizon, in increasing
|
|
50
|
+
* order (M2-grow). The sow day of a year is the first day of its window on the start or after it. A window with `from`
|
|
51
|
+
* after `to` goes across the end of the year. A year that does not have a day of the window (`02-29`) has no sowing.
|
|
52
|
+
*
|
|
53
|
+
* @throws RangeError when the start is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
54
|
+
*/
|
|
55
|
+
export declare function sowDays(season: Pick<Season, "from" | "to">, start: IsoDate, horizon: number): number[];
|
|
56
|
+
/** This function tells if a layer has a converter with a season that can run in a case. */
|
|
57
|
+
export declare function hasSeason(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): boolean;
|
|
35
58
|
/**
|
|
36
59
|
* This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.
|
|
37
60
|
*
|
|
@@ -51,6 +74,14 @@ export declare function giftResource(converter: Converter): string | undefined;
|
|
|
51
74
|
* Thus a draw whose ways reach two converters of one device, each with a limit `perDay` more than 0, does not use the take order.
|
|
52
75
|
* A linear program with exact rationals gives its days: the largest `T` with the best share of its stocks and of the device-days.
|
|
53
76
|
* At this `T`, the draw takes the smallest sum of its takes of the stocks, each over its stock, then the fewest device-days.
|
|
77
|
+
|
|
78
|
+
* - A converter with a season (M2-grow) is not a maker of a take. Its sowings take their inputs from the stores before
|
|
79
|
+
* the first draw, and each harvest adds to the stocks on its day. Refer to `Season`. The query reads the sowings
|
|
80
|
+
* and the harvests up to the horizon (`horizon`, default `SEASON_HORIZON_DAYS`), and a draw holds the horizon at most.
|
|
81
|
+
* - With a season, each draw takes its stocks over spans from harvest to harvest. `days` is the first stop of the
|
|
82
|
+
* draw. A later harvest can feed the draw again: `again` gives these spans, and `takes` is the sum to the horizon.
|
|
83
|
+
* A lower draw gets the stocks that the higher draws leave, the earliest stocks first taken. This is the safe side.
|
|
84
|
+
* - A draw with a shared device and a season gets a `RangeError` (M2-grow-share).
|
|
54
85
|
*
|
|
55
86
|
* The function is pure, but for an internal count of the tries of its fits for the tests. It throws a `RangeError` for a date that is not `YYYY-MM-DD`. The gate `checkEndurance` examines the layer before.
|
|
56
87
|
*
|
|
@@ -119,7 +150,7 @@ export interface JointDays {
|
|
|
119
150
|
* @param options - The date, and the stack or the parts that are also down
|
|
120
151
|
* @param needs - The codes of the needs of the draws of the set
|
|
121
152
|
* @returns The joint days, the takes of each draw, the binding resources and the runs of each converter
|
|
122
|
-
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`.
|
|
153
|
+
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`. Or a converter with a season can run in the case (M2-grow-share).
|
|
123
154
|
*/
|
|
124
155
|
export declare function jointDays(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions, needs: readonly string[]): JointDays;
|
|
125
156
|
/** The options of `bestEndurance`: the options of a case, and a horizon. */
|
|
@@ -162,7 +193,7 @@ export interface BestOptions extends CaseOptions {
|
|
|
162
193
|
* @param caseCuts - The case
|
|
163
194
|
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
164
195
|
* @returns The endurance of each draw whose supply stops
|
|
165
|
-
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
196
|
+
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0. Or a converter with a season can run in the case (M2-grow-share).
|
|
166
197
|
*/
|
|
167
198
|
export declare function bestEndurance(layer: EnduranceLayer, caseCuts: CaseCuts, options: BestOptions): Endurance;
|
|
168
199
|
/**
|
|
@@ -171,6 +202,15 @@ export declare function bestEndurance(layer: EnduranceLayer, caseCuts: CaseCuts,
|
|
|
171
202
|
* With no horizon, the area goes to the end of the curve.
|
|
172
203
|
*/
|
|
173
204
|
export declare function tailDays(curve: Survival, from: number, to?: number): number;
|
|
205
|
+
/**
|
|
206
|
+
* This function gives the days of a cut with the survival `curve` that a draw does not hold, up to the horizon (M2-grow).
|
|
207
|
+
* It is `tailDays` from the days of the draw, less `tailDays` over each span in which a harvest feeds the draw again.
|
|
208
|
+
*
|
|
209
|
+
* @param curve - The survival of the stop of the draw
|
|
210
|
+
* @param held - The days and the fed spans of the draw, from `enduranceOf`
|
|
211
|
+
* @param horizon - The horizon in days. The default is no horizon.
|
|
212
|
+
*/
|
|
213
|
+
export declare function heldTail(curve: Survival, held: Pick<DrawEndurance, "days" | "again">, horizon?: number): number;
|
|
174
214
|
/**
|
|
175
215
|
* The options of a shortfall: the stack or the parts that are also down, as for `enduranceOf`, and a horizon.
|
|
176
216
|
* 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.
|
|
@@ -371,7 +411,16 @@ export interface YearShortfallOptions extends CaseOptions, ShortfallOptions {
|
|
|
371
411
|
* draw at the horizon keeps back only the horizon times its demand, and the lower levels get the rest.
|
|
372
412
|
*/
|
|
373
413
|
readonly share?: Share | undefined;
|
|
414
|
+
/**
|
|
415
|
+
* The count of the start dates of the events of each case, for a layer with a converter with a season (M2-grow). A
|
|
416
|
+
* whole number from 1. The default is `YEAR_STARTS`. The start dates are at equal steps over one year from `at`. The
|
|
417
|
+
* shortfall of a case is the mean of its shortfalls at these dates, because an event can start on each day of the
|
|
418
|
+
* year. A layer with no season does not use it.
|
|
419
|
+
*/
|
|
420
|
+
readonly starts?: number | undefined;
|
|
374
421
|
}
|
|
422
|
+
/** The default count of the start dates of the events of a year, for a layer with a season: one in each month. */
|
|
423
|
+
export declare const YEAR_STARTS = 12;
|
|
375
424
|
/** The user-days of each level for each curve of the stop: the three sums of a shortfall. Since 0.8.15. */
|
|
376
425
|
export type ShortfallDays = Pick<Shortfall, "levels" | "independent" | "upper">;
|
|
377
426
|
/**
|
|
@@ -395,8 +444,17 @@ export interface YearCase {
|
|
|
395
444
|
readonly rate: number;
|
|
396
445
|
/** The interval of `rate` from the interval of the prior, times its reach. A prior with no interval gives none. Since 0.8.15. */
|
|
397
446
|
readonly rateInterval?: readonly [low: number, high: number] | undefined;
|
|
447
|
+
/** The endurance of the case. With a season, it is the endurance at the first start date, `at`. */
|
|
398
448
|
readonly endurance: Endurance;
|
|
449
|
+
/** The shortfall of the case. With a season, it is the mean of the shortfalls at the start dates. */
|
|
399
450
|
readonly shortfall: Shortfall;
|
|
451
|
+
/** The shortfall at each start date, for a layer with a converter with a season (M2-grow). */
|
|
452
|
+
readonly starts?: readonly YearStart[] | undefined;
|
|
453
|
+
}
|
|
454
|
+
/** The shortfall of a case for one start date of its event (M2-grow). */
|
|
455
|
+
export interface YearStart {
|
|
456
|
+
readonly start: IsoDate;
|
|
457
|
+
readonly shortfall: ShortfallDays;
|
|
400
458
|
}
|
|
401
459
|
/** The shortfall of one year at one place, with the part of each case. */
|
|
402
460
|
export interface YearShortfall extends Shortfall {
|
|
@@ -530,8 +588,11 @@ export declare function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, o
|
|
|
530
588
|
* converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.
|
|
531
589
|
* - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.
|
|
532
590
|
* - `endurance-cut-no-curve` (warning): a cut has no curve of its duration. The draws whose stop it can be part of are no read in the shortfall.
|
|
591
|
+
* - `endurance-season`: the season of a converter has a day that is not `MM-DD`, or a delay that is not more than 0.
|
|
592
|
+
* Or its count of sowings is not a finite number of 0 or more. Or the converter with a season gives a need, or it has
|
|
593
|
+
* `perDay` or `devices`. Since 0.8.16 (M2-grow).
|
|
533
594
|
*/
|
|
534
|
-
export declare const ENDURANCE_CODES: readonly ["endurance-twice", "endurance-level-unknown", "endurance-resource-unknown", "endurance-part-unknown", "endurance-range", "endurance-date", "endurance-converter-empty", "endurance-curve", "endurance-bound", "endurance-prior-case", "endurance-cycle", "endurance-devices", "endurance-device-mix", "endurance-no-way", "endurance-cut-no-curve"];
|
|
595
|
+
export declare const ENDURANCE_CODES: readonly ["endurance-twice", "endurance-level-unknown", "endurance-resource-unknown", "endurance-part-unknown", "endurance-range", "endurance-date", "endurance-converter-empty", "endurance-curve", "endurance-bound", "endurance-prior-case", "endurance-cycle", "endurance-devices", "endurance-device-mix", "endurance-no-way", "endurance-cut-no-curve", "endurance-season"];
|
|
535
596
|
/** A code of `ENDURANCE_CODES`. */
|
|
536
597
|
export type EnduranceCode = (typeof ENDURANCE_CODES)[number];
|
|
537
598
|
/** A fault of the gate of an endurance layer. */
|
|
@@ -578,5 +639,5 @@ export declare const SAMPLE_ENDURANCE_STACK: Stack;
|
|
|
578
639
|
* - The filled bottles are past their due date, so they give nothing.
|
|
579
640
|
*/
|
|
580
641
|
export declare const SAMPLE_ENDURANCE: EnduranceLayer;
|
|
581
|
-
export { type CaseCuts, Converter, type Cut, type CutBound, DirectUse, Draw, DrawEndurance, ENDURANCE_SCHEMA, Endurance, EnduranceLayer, Gift, IsoDate, type Prior, Resource, Store, type Survival, curveFault, survivalAt };
|
|
642
|
+
export { type CaseCuts, Converter, type Cut, type CutBound, DirectUse, Draw, DrawEndurance, ENDURANCE_SCHEMA, Endurance, EnduranceLayer, Gift, Harvest, IsoDate, MonthDay, type Prior, Resource, Season, Store, type Survival, curveFault, survivalAt };
|
|
582
643
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAUiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":"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"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
-
import { S as exact, _ as
|
|
3
|
-
import { DEFAULT_MAX_SETS, STACK_SCHEMA, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
|
|
2
|
+
import { C as addTo, S as valueAt, T as exact, _ as caseParts, a as hasEnduranceError, b as fewestRow, c as caseStopped, d as giftNeed, f as giftResource, g as Program, h as storeAmounts, i as curveFault, l as drawDemand, m as sowDays, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as deviceUse, w as dense, x as reachOf, y as drawBlock } from "./join-D-KCebAf.js";
|
|
3
|
+
import { DEFAULT_MAX_SETS, STACK_SCHEMA, dateOfDay, dayNumber, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
|
|
4
4
|
import { ONE, ZERO, add, div, equals, mul, neg, sign, sub, toNumber } from "@mark1russell7/rational";
|
|
5
5
|
import { solveLexicographic } from "@mark1russell7/linear";
|
|
6
6
|
import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
@@ -31,13 +31,14 @@ import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/
|
|
|
31
31
|
* @param options - The date, and the stack or the parts that are also down
|
|
32
32
|
* @param needs - The codes of the needs of the draws of the set
|
|
33
33
|
* @returns The joint days, the takes of each draw, the binding resources and the runs of each converter
|
|
34
|
-
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`.
|
|
34
|
+
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`. Or a converter with a season can run in the case (M2-grow-share).
|
|
35
35
|
*/
|
|
36
36
|
function jointDays(layer, caseCuts, options, needs) {
|
|
37
37
|
const known = new Set(layer.draws.map((draw) => draw.need));
|
|
38
38
|
const unknown = needs.filter((need) => !known.has(need));
|
|
39
39
|
if (unknown.length > 0) throw new RangeError(`The needs ${unknown.map((need) => `"${need}"`).join(", ")} are not the needs of draws of the layer.`);
|
|
40
40
|
const stoppedParts = caseStopped(caseCuts, options);
|
|
41
|
+
if (hasSeason(layer, stoppedParts)) throw new RangeError(`The layer has a converter with a season. jointDays does not read harvests yet (M2-grow-share): use enduranceOf.`);
|
|
41
42
|
const stock = storeAmounts(layer, options.at, stoppedParts);
|
|
42
43
|
const wanted = new Set(needs);
|
|
43
44
|
const plan = caseDraws(layer, caseCuts, stoppedParts).filter((draw) => wanted.has(draw.need));
|
|
@@ -171,11 +172,12 @@ function horizonOf$1(horizon) {
|
|
|
171
172
|
* @param caseCuts - The case
|
|
172
173
|
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
173
174
|
* @returns The endurance of each draw whose supply stops
|
|
174
|
-
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
175
|
+
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0. Or a converter with a season can run in the case (M2-grow-share).
|
|
175
176
|
*/
|
|
176
177
|
function bestEndurance(layer, caseCuts, options) {
|
|
177
178
|
const horizon = horizonOf$1(options.horizon);
|
|
178
179
|
const stoppedParts = caseStopped(caseCuts, options);
|
|
180
|
+
if (hasSeason(layer, stoppedParts)) throw new RangeError(`The layer has a converter with a season. bestEndurance does not read harvests yet (M2-grow-share): use enduranceOf.`);
|
|
179
181
|
const stock = storeAmounts(layer, options.at, stoppedParts);
|
|
180
182
|
const draws = caseDraws(layer, caseCuts, stoppedParts);
|
|
181
183
|
const parts = caseParts(layer, stoppedParts, stock, new Set(draws.map((draw) => draw.need)));
|
|
@@ -461,6 +463,19 @@ function tailDays(curve, from, to = 1e400) {
|
|
|
461
463
|
}
|
|
462
464
|
return area;
|
|
463
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* This function gives the days of a cut with the survival `curve` that a draw does not hold, up to the horizon (M2-grow).
|
|
468
|
+
* It is `tailDays` from the days of the draw, less `tailDays` over each span in which a harvest feeds the draw again.
|
|
469
|
+
*
|
|
470
|
+
* @param curve - The survival of the stop of the draw
|
|
471
|
+
* @param held - The days and the fed spans of the draw, from `enduranceOf`
|
|
472
|
+
* @param horizon - The horizon in days. The default is no horizon.
|
|
473
|
+
*/
|
|
474
|
+
function heldTail(curve, held, horizon = 1e400) {
|
|
475
|
+
let short = tailDays(curve, held.days, horizon);
|
|
476
|
+
for (const span of held.again ?? []) short -= tailDays(curve, span.from, Math.min(span.to, horizon));
|
|
477
|
+
return Math.max(0, short);
|
|
478
|
+
}
|
|
464
479
|
function horizonOf(options) {
|
|
465
480
|
const horizon = options.horizon ?? 1e400;
|
|
466
481
|
if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);
|
|
@@ -882,9 +897,9 @@ function caseShortfall(layer, caseCuts, endurance, options = {}) {
|
|
|
882
897
|
if (curves.independentUpper) independentUpper.push(draw.need);
|
|
883
898
|
bounds.push(curves.bound);
|
|
884
899
|
const users = draw.users ?? 1;
|
|
885
|
-
levels[draw.level] = (levels[draw.level] ?? 0) +
|
|
886
|
-
independent[draw.level] = (independent[draw.level] ?? 0) +
|
|
887
|
-
upper[draw.level] = (upper[draw.level] ?? 0) +
|
|
900
|
+
levels[draw.level] = (levels[draw.level] ?? 0) + heldTail(curves.event, held, horizon) * users;
|
|
901
|
+
independent[draw.level] = (independent[draw.level] ?? 0) + heldTail(curves.independent, held, horizon) * users;
|
|
902
|
+
upper[draw.level] = (upper[draw.level] ?? 0) + heldTail(curves.upper, held, horizon) * users;
|
|
888
903
|
}
|
|
889
904
|
return {
|
|
890
905
|
levels,
|
|
@@ -908,6 +923,8 @@ function shareOf(options) {
|
|
|
908
923
|
function shareEndurance(layer, caseCuts, options, share) {
|
|
909
924
|
return share === "best" ? bestEndurance(layer, caseCuts, options) : enduranceOf(layer, caseCuts, options);
|
|
910
925
|
}
|
|
926
|
+
/** The default count of the start dates of the events of a year, for a layer with a season: one in each month. */
|
|
927
|
+
const YEAR_STARTS = 12;
|
|
911
928
|
/**
|
|
912
929
|
* This function gives the shortfall of one year at one place.
|
|
913
930
|
* It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.
|
|
@@ -929,6 +946,7 @@ function yearShortfall(layer, place, options) {
|
|
|
929
946
|
horizonOf(options);
|
|
930
947
|
budgetsOf(options);
|
|
931
948
|
const share = shareOf(options);
|
|
949
|
+
const dates = startDates(layer, options);
|
|
932
950
|
const levels = zeroLevels(layer);
|
|
933
951
|
const independent = zeroLevels(layer);
|
|
934
952
|
const upper = zeroLevels(layer);
|
|
@@ -953,8 +971,27 @@ function yearShortfall(layer, place, options) {
|
|
|
953
971
|
const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);
|
|
954
972
|
if (prior === void 0) continue;
|
|
955
973
|
const rate = yearRate(prior);
|
|
956
|
-
const
|
|
957
|
-
|
|
974
|
+
const each = dates.map((start) => {
|
|
975
|
+
const endurance = shareEndurance(layer, caseCuts, dates.length === 1 ? options : {
|
|
976
|
+
...options,
|
|
977
|
+
start
|
|
978
|
+
}, share);
|
|
979
|
+
return {
|
|
980
|
+
start,
|
|
981
|
+
endurance,
|
|
982
|
+
shortfall: caseShortfall(layer, caseCuts, endurance, options)
|
|
983
|
+
};
|
|
984
|
+
});
|
|
985
|
+
const endurance = each[0].endurance;
|
|
986
|
+
const shortfall = each.length === 1 ? each[0].shortfall : meanShortfall(layer, each.map((item) => item.shortfall));
|
|
987
|
+
const starts = each.length === 1 ? {} : { starts: each.map((item) => ({
|
|
988
|
+
start: item.start,
|
|
989
|
+
shortfall: {
|
|
990
|
+
levels: item.shortfall.levels,
|
|
991
|
+
independent: item.shortfall.independent,
|
|
992
|
+
upper: item.shortfall.upper
|
|
993
|
+
}
|
|
994
|
+
})) };
|
|
958
995
|
addDays({
|
|
959
996
|
levels,
|
|
960
997
|
independent,
|
|
@@ -974,7 +1011,8 @@ function yearShortfall(layer, place, options) {
|
|
|
974
1011
|
rate,
|
|
975
1012
|
...rateInterval === void 0 ? {} : { rateInterval },
|
|
976
1013
|
endurance,
|
|
977
|
-
shortfall
|
|
1014
|
+
shortfall,
|
|
1015
|
+
...starts
|
|
978
1016
|
});
|
|
979
1017
|
}
|
|
980
1018
|
const range = Number.isFinite(level) ? { range: {
|
|
@@ -996,6 +1034,35 @@ function yearShortfall(layer, place, options) {
|
|
|
996
1034
|
...range
|
|
997
1035
|
};
|
|
998
1036
|
}
|
|
1037
|
+
/**
|
|
1038
|
+
* This function gives the start dates of the events of a year: `at` alone for a layer with no converter with a season.
|
|
1039
|
+
* Otherwise `starts` dates at equal steps over 365 days from `at`.
|
|
1040
|
+
*/
|
|
1041
|
+
function startDates(layer, options) {
|
|
1042
|
+
if (!(layer.converters ?? []).some((converter) => converter.season !== void 0)) return [options.at];
|
|
1043
|
+
const count = options.starts ?? 12;
|
|
1044
|
+
if (!Number.isSafeInteger(count) || count < 1) throw new RangeError(`The option starts is ${String(options.starts)}: it is not a whole number from 1.`);
|
|
1045
|
+
const first = dayNumber(options.at);
|
|
1046
|
+
if (first === void 0) throw new RangeError(`The date "${options.at}" is not a date YYYY-MM-DD.`);
|
|
1047
|
+
return Array.from({ length: count }, (_, index) => dateOfDay(first + Math.floor(index * 365 / count)));
|
|
1048
|
+
}
|
|
1049
|
+
/** This function gives the mean of the shortfalls of one case at its start dates. The lists are unions, and the bound is the weakest. */
|
|
1050
|
+
function meanShortfall(layer, list) {
|
|
1051
|
+
const days = {
|
|
1052
|
+
levels: zeroLevels(layer),
|
|
1053
|
+
independent: zeroLevels(layer),
|
|
1054
|
+
upper: zeroLevels(layer)
|
|
1055
|
+
};
|
|
1056
|
+
for (const shortfall of list) addDays(days, shortfall, 1 / list.length);
|
|
1057
|
+
const union = (pick) => [...new Set(list.flatMap(pick))];
|
|
1058
|
+
return {
|
|
1059
|
+
...days,
|
|
1060
|
+
unread: union((item) => item.unread),
|
|
1061
|
+
coarse: union((item) => item.coarse),
|
|
1062
|
+
independentUpper: union((item) => item.independentUpper),
|
|
1063
|
+
bound: weakestBound(list.map((item) => item.bound))
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
999
1066
|
/** This function adds the user-days of a shortfall times a count of events to each sum of the days. */
|
|
1000
1067
|
function addDays(days, shortfall, count) {
|
|
1001
1068
|
for (const [level, value] of Object.entries(shortfall.levels)) days.levels[level] = (days.levels[level] ?? 0) + count * value;
|
|
@@ -1049,7 +1116,7 @@ function caseOutlook(layer, caseCuts, options) {
|
|
|
1049
1116
|
}
|
|
1050
1117
|
const users = draw.users ?? 1;
|
|
1051
1118
|
const lasts = (curve) => held.days >= horizon ? 1 : 1 - survivalAt(curve, held.days);
|
|
1052
|
-
const short = (curve) =>
|
|
1119
|
+
const short = (curve) => heldTail(curve, held, horizon) * users;
|
|
1053
1120
|
const values = (stop) => ({
|
|
1054
1121
|
lasts: {
|
|
1055
1122
|
event: lasts(stop.event),
|
|
@@ -1319,6 +1386,6 @@ const SAMPLE_ENDURANCE = {
|
|
|
1319
1386
|
asOf: "2025-12-01"
|
|
1320
1387
|
}]
|
|
1321
1388
|
};
|
|
1322
|
-
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SHARES, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, independentStop, joinEndurance, jointDays, longestStop, minimalStops, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
1389
|
+
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, joinEndurance, jointDays, longestStop, minimalStops, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
1323
1390
|
|
|
1324
1391
|
//# sourceMappingURL=index.js.map
|