@mark1russell7/stack-endurance 0.8.14 → 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 +15 -1
- package/build/add-on.d.ts +1 -1
- package/build/add-on.js +1 -1
- package/build/index.d.ts +96 -11
- package/build/index.d.ts.map +1 -1
- package/build/index.js +117 -16
- package/build/index.js.map +1 -1
- package/build/{join-Cc6JzE5G.js → join-D-KCebAf.js} +241 -39
- 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 +13 -2
- package/build/schema.js.map +1 -1
- package/package.json +2 -2
- package/build/join-Cc6JzE5G.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.
|
|
@@ -50,6 +62,8 @@ With the option `horizon` of `h` days, the shortfall counts only the first `h` d
|
|
|
50
62
|
|
|
51
63
|
The option `share` of `yearShortfall` sets the share of the stores in each case. The default `take` uses `enduranceOf`. With `best`, the query uses `bestEndurance`, and the horizon of the shortfall is the horizon of the share. Thus a draw at the horizon keeps back only `h` times its demand, and the lower levels get the rest.
|
|
52
64
|
|
|
65
|
+
Since 0.8.15, a prior can have an `interval` of its `perYear` at a level (`RateInterval` of the core). Then `yearShortfall` gives a `range`. It is the same sum with the rate of each case at the low end of its interval, and at the high end. Each end holds only for each case alone, so the range shows the sampling error of the rates. It is not a joint interval. A case with no interval is in `range.without`, and its rate is at the two ends.
|
|
66
|
+
|
|
53
67
|
A draw that only the parts of `down` stop has no curve of its duration. The query puts it in `unread`, and its shortfall is not in the sum. A gate shows it as no read, not as a pass.
|
|
54
68
|
|
|
55
69
|
A cut can have no `duration`, as before a source gives its curve. Then each draw whose stop the cut can be part of goes in `unread`. A draw whose minimal stop sets do not have the cut keeps its curves. When the query has no minimal sets, it cannot tell, so the draw goes in `unread`. The gate gives the warning `endurance-cut-no-curve` for each such cut.
|
|
@@ -213,4 +227,4 @@ In the sample, the rice needs 2 L of water for each kg. The drinking water holds
|
|
|
213
227
|
|
|
214
228
|
## The gate
|
|
215
229
|
|
|
216
|
-
`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,17 +411,58 @@ 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;
|
|
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;
|
|
424
|
+
/** The user-days of each level for each curve of the stop: the three sums of a shortfall. Since 0.8.15. */
|
|
425
|
+
export type ShortfallDays = Pick<Shortfall, "levels" | "independent" | "upper">;
|
|
426
|
+
/**
|
|
427
|
+
* The range of the shortfall of one year from the intervals of the rates of its cases (`Prior.interval`). Since 0.8.15.
|
|
428
|
+
* `low` puts the rate of each case at the low end of its interval, and `high` puts it at the high end.
|
|
429
|
+
* Each end holds only for each case alone, so the two values are a range of the sampling error, not a joint interval.
|
|
430
|
+
* The mean of a skewed law can be above the high end, so the expected value can be above `high`.
|
|
431
|
+
*/
|
|
432
|
+
export interface RateRange {
|
|
433
|
+
/** The least level of the intervals of the cases in the sum. */
|
|
434
|
+
readonly level: number;
|
|
435
|
+
readonly low: ShortfallDays;
|
|
436
|
+
readonly high: ShortfallDays;
|
|
437
|
+
/** The cases in the sum with no interval of their rate. Their rate is at the two ends. */
|
|
438
|
+
readonly without: readonly string[];
|
|
439
|
+
}
|
|
440
|
+
/** The part of one case in the shortfall of one year. */
|
|
441
|
+
export interface YearCase {
|
|
442
|
+
readonly case: string;
|
|
443
|
+
/** The expected count of the events of the case at the place in one year (`yearRate`). */
|
|
444
|
+
readonly rate: number;
|
|
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. */
|
|
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`. */
|
|
448
|
+
readonly endurance: Endurance;
|
|
449
|
+
/** The shortfall of the case. With a season, it is the mean of the shortfalls at the start dates. */
|
|
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;
|
|
374
458
|
}
|
|
375
459
|
/** The shortfall of one year at one place, with the part of each case. */
|
|
376
460
|
export interface YearShortfall extends Shortfall {
|
|
377
461
|
readonly place: string;
|
|
378
462
|
/** The part of each case. `rate` is the expected count of its events in one year. */
|
|
379
|
-
readonly cases: readonly
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
readonly endurance: Endurance;
|
|
383
|
-
readonly shortfall: Shortfall;
|
|
384
|
-
}[];
|
|
463
|
+
readonly cases: readonly YearCase[];
|
|
464
|
+
/** The range from the intervals of the rates. A year with no case with an interval has no range. Since 0.8.15. */
|
|
465
|
+
readonly range?: RateRange | undefined;
|
|
385
466
|
}
|
|
386
467
|
/**
|
|
387
468
|
* This function gives the shortfall of one year at one place.
|
|
@@ -393,6 +474,7 @@ export interface YearShortfall extends Shortfall {
|
|
|
393
474
|
* - `bound` is the weakest bound of the cases in the sum. A case with no prior, or with an expected count of 0, adds 0, so it does not change the bound.
|
|
394
475
|
*
|
|
395
476
|
* - With `share: "best"`, the endurance of each case comes from `bestEndurance` with the horizon of the shortfall.
|
|
477
|
+
* - `range` is the same sum with the rate of each case at each end of its interval (`RateRange`).
|
|
396
478
|
*
|
|
397
479
|
* @param layer - The endurance layer, with its cases and priors
|
|
398
480
|
* @param place - The place of the priors
|
|
@@ -506,8 +588,11 @@ export declare function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, o
|
|
|
506
588
|
* converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.
|
|
507
589
|
* - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.
|
|
508
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).
|
|
509
594
|
*/
|
|
510
|
-
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"];
|
|
511
596
|
/** A code of `ENDURANCE_CODES`. */
|
|
512
597
|
export type EnduranceCode = (typeof ENDURANCE_CODES)[number];
|
|
513
598
|
/** A fault of the gate of an endurance layer. */
|
|
@@ -554,5 +639,5 @@ export declare const SAMPLE_ENDURANCE_STACK: Stack;
|
|
|
554
639
|
* - The filled bottles are past their due date, so they give nothing.
|
|
555
640
|
*/
|
|
556
641
|
export declare const SAMPLE_ENDURANCE: EnduranceLayer;
|
|
557
|
-
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 };
|
|
558
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":";;;iBAUiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;WAKA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IA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qBCzzBpF;;YAqCD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBA4KtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBC7OnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
|
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.
|
|
@@ -918,6 +935,7 @@ function shareEndurance(layer, caseCuts, options, share) {
|
|
|
918
935
|
* - `bound` is the weakest bound of the cases in the sum. A case with no prior, or with an expected count of 0, adds 0, so it does not change the bound.
|
|
919
936
|
*
|
|
920
937
|
* - With `share: "best"`, the endurance of each case comes from `bestEndurance` with the horizon of the shortfall.
|
|
938
|
+
* - `range` is the same sum with the rate of each case at each end of its interval (`RateRange`).
|
|
921
939
|
*
|
|
922
940
|
* @param layer - The endurance layer, with its cases and priors
|
|
923
941
|
* @param place - The place of the priors
|
|
@@ -928,6 +946,7 @@ function yearShortfall(layer, place, options) {
|
|
|
928
946
|
horizonOf(options);
|
|
929
947
|
budgetsOf(options);
|
|
930
948
|
const share = shareOf(options);
|
|
949
|
+
const dates = startDates(layer, options);
|
|
931
950
|
const levels = zeroLevels(layer);
|
|
932
951
|
const independent = zeroLevels(layer);
|
|
933
952
|
const upper = zeroLevels(layer);
|
|
@@ -936,15 +955,53 @@ function yearShortfall(layer, place, options) {
|
|
|
936
955
|
const independentUpper = [];
|
|
937
956
|
const cases = [];
|
|
938
957
|
const bounds = [];
|
|
958
|
+
const low = {
|
|
959
|
+
levels: zeroLevels(layer),
|
|
960
|
+
independent: zeroLevels(layer),
|
|
961
|
+
upper: zeroLevels(layer)
|
|
962
|
+
};
|
|
963
|
+
const high = {
|
|
964
|
+
levels: zeroLevels(layer),
|
|
965
|
+
independent: zeroLevels(layer),
|
|
966
|
+
upper: zeroLevels(layer)
|
|
967
|
+
};
|
|
968
|
+
const without = [];
|
|
969
|
+
let level = 1e400;
|
|
939
970
|
for (const caseCuts of layer.cases ?? []) {
|
|
940
971
|
const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);
|
|
941
972
|
if (prior === void 0) continue;
|
|
942
973
|
const rate = yearRate(prior);
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
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
|
+
})) };
|
|
995
|
+
addDays({
|
|
996
|
+
levels,
|
|
997
|
+
independent,
|
|
998
|
+
upper
|
|
999
|
+
}, shortfall, rate);
|
|
1000
|
+
const rateInterval = prior.interval === void 0 ? void 0 : [prior.interval.low * prior.reach, prior.interval.high * prior.reach];
|
|
1001
|
+
if (rateInterval === void 0) without.push(caseCuts.case);
|
|
1002
|
+
else level = Math.min(level, prior.interval?.level ?? level);
|
|
1003
|
+
addDays(low, shortfall, rateInterval?.[0] ?? rate);
|
|
1004
|
+
addDays(high, shortfall, rateInterval?.[1] ?? rate);
|
|
948
1005
|
for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);
|
|
949
1006
|
for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);
|
|
950
1007
|
for (const need of shortfall.independentUpper) if (!independentUpper.includes(need)) independentUpper.push(need);
|
|
@@ -952,10 +1009,18 @@ function yearShortfall(layer, place, options) {
|
|
|
952
1009
|
cases.push({
|
|
953
1010
|
case: caseCuts.case,
|
|
954
1011
|
rate,
|
|
1012
|
+
...rateInterval === void 0 ? {} : { rateInterval },
|
|
955
1013
|
endurance,
|
|
956
|
-
shortfall
|
|
1014
|
+
shortfall,
|
|
1015
|
+
...starts
|
|
957
1016
|
});
|
|
958
1017
|
}
|
|
1018
|
+
const range = Number.isFinite(level) ? { range: {
|
|
1019
|
+
level,
|
|
1020
|
+
low,
|
|
1021
|
+
high,
|
|
1022
|
+
without
|
|
1023
|
+
} } : {};
|
|
959
1024
|
return {
|
|
960
1025
|
place,
|
|
961
1026
|
levels,
|
|
@@ -965,10 +1030,46 @@ function yearShortfall(layer, place, options) {
|
|
|
965
1030
|
coarse,
|
|
966
1031
|
independentUpper,
|
|
967
1032
|
bound: weakestBound(bounds),
|
|
968
|
-
cases
|
|
1033
|
+
cases,
|
|
1034
|
+
...range
|
|
969
1035
|
};
|
|
970
1036
|
}
|
|
971
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
|
+
}
|
|
1066
|
+
/** This function adds the user-days of a shortfall times a count of events to each sum of the days. */
|
|
1067
|
+
function addDays(days, shortfall, count) {
|
|
1068
|
+
for (const [level, value] of Object.entries(shortfall.levels)) days.levels[level] = (days.levels[level] ?? 0) + count * value;
|
|
1069
|
+
for (const [level, value] of Object.entries(shortfall.independent)) days.independent[level] = (days.independent[level] ?? 0) + count * value;
|
|
1070
|
+
for (const [level, value] of Object.entries(shortfall.upper)) days.upper[level] = (days.upper[level] ?? 0) + count * value;
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
972
1073
|
* This function gives the outlook of one event of a case. For each draw, it gives the days, the chance that the
|
|
973
1074
|
* stores last through the stop, and the shortfall. A page of a place can show it for each case of its region.
|
|
974
1075
|
*
|
|
@@ -1015,7 +1116,7 @@ function caseOutlook(layer, caseCuts, options) {
|
|
|
1015
1116
|
}
|
|
1016
1117
|
const users = draw.users ?? 1;
|
|
1017
1118
|
const lasts = (curve) => held.days >= horizon ? 1 : 1 - survivalAt(curve, held.days);
|
|
1018
|
-
const short = (curve) =>
|
|
1119
|
+
const short = (curve) => heldTail(curve, held, horizon) * users;
|
|
1019
1120
|
const values = (stop) => ({
|
|
1020
1121
|
lasts: {
|
|
1021
1122
|
event: lasts(stop.event),
|
|
@@ -1285,6 +1386,6 @@ const SAMPLE_ENDURANCE = {
|
|
|
1285
1386
|
asOf: "2025-12-01"
|
|
1286
1387
|
}]
|
|
1287
1388
|
};
|
|
1288
|
-
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 };
|
|
1289
1390
|
|
|
1290
1391
|
//# sourceMappingURL=index.js.map
|