@mark1russell7/stack-endurance 0.8.21 → 0.8.23
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 +30 -2
- package/build/add-on.d.ts +1 -1
- package/build/add-on.js +1 -1
- package/build/index.d.ts +104 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +232 -2
- package/build/index.js.map +1 -1
- package/build/{join-CM_zwI78.js → join-BXx4xoUc.js} +161 -27
- package/build/join-BXx4xoUc.js.map +1 -0
- package/build/{layer-DuGjz7Cl.d.ts → layer-CZZWJtM8.d.ts} +3 -3
- package/build/{layer-DuGjz7Cl.d.ts.map → layer-CZZWJtM8.d.ts.map} +1 -1
- package/build/layer-a3Fr70Uh.js.map +1 -1
- package/build/schema.d.ts +1 -1
- package/package.json +1 -1
- package/build/join-CM_zwI78.js.map +0 -1
package/README.md
CHANGED
|
@@ -71,7 +71,10 @@ A converter with a limit `perDay` more than 0 can take nothing. It is a source,
|
|
|
71
71
|
A store can have a `capacity`: the most amount that it holds. A source that gives the resource of the store charges it with the runs that no draw takes on their day. Example: a battery of 6000 Wh takes the energy of a sunny day, and gives it back on a dark day. Since 0.8.21 (M2-solar-charge).
|
|
72
72
|
|
|
73
73
|
- `bestEndurance` and `jointDays` give the charge in each segment of the days. In a segment, the takes are not more than the level at the start of the segment. Also the level at the start plus the charge is not more than the capacity. Thus each order of the takes and the charges in the segment is a plan. This is the safe side.
|
|
74
|
-
-
|
|
74
|
+
- Since 0.8.23, the sweep of `enduranceOf` gives the charge too (M2-solar-charge-sweep). Each draw that can take the store gets the programs of `bestEndurance` for itself alone, in the order of the levels. Thus one draw gets the days of `bestEndurance`.
|
|
75
|
+
- In the sweep, a draw charges the store as much as it can, the earliest first. Its takes and its charge in each segment then stay as they are.
|
|
76
|
+
- A lower draw takes only the level that the higher draws leave. Its takes keep the takes and the charges of the higher draws possible in each segment. It adds a charge only with the device-days that the higher draws leave.
|
|
77
|
+
- The device-days of a charge count as device-days of its draw for each lower draw. This is the safe side.
|
|
75
78
|
- Only a source charges a store. A maker with inputs gives no charge, because its inputs keep to the day of the take.
|
|
76
79
|
- The stores of one resource all have a capacity, or none has one. A store with a capacity has no due date, and its capacity is not less than its amount. The gate refuses the other cases (`endurance-capacity`).
|
|
77
80
|
|
|
@@ -126,6 +129,31 @@ Two groups of cuts that share no minimal set are independent, so the independent
|
|
|
126
129
|
- `holds` names the draws whose supply the case does not stop. `unread` names the draws whose stop has no curve.
|
|
127
130
|
- `band` gives the same values with each cut at the low end of its band (`shorter`) and at the high end (`longer`). The days do not change. Each end holds only at each day, so the two values are a range of the sampling error, not a joint interval. A draw has no `band` when a cut of its stop has a curve and no band. Since 0.8.14.
|
|
128
131
|
|
|
132
|
+
## The sensitivity of a layer
|
|
133
|
+
|
|
134
|
+
`enduranceSensitivity(layer, caseCuts, options)` tells which input moves the days most. For each input, it gives the change in the days of each draw for one step of the input. Then it ranks the inputs. Since 0.8.22 (M2-endurance-sensitivity).
|
|
135
|
+
|
|
136
|
+
- The inputs are the amount of each store and the rate `perDay` of each draw. Each converter gives its gift, each take, its limit `perDay` and its count of devices.
|
|
137
|
+
- The key of an input tells what it is, for example `store:jugs`, `draw:hydration.drink`, `converter:cook-rice.takes.water.stored` or `device:stove.devices`.
|
|
138
|
+
- The step adds to a store, a gift, a limit and a count of devices. It takes off a draw and a take, because less of them gives more days. Thus a lower draw is an input that costs nothing.
|
|
139
|
+
- The option `step` sets the step, in the unit of each input. The default is `SENSITIVITY_STEP`, 1 unit. A count of devices always takes 1 more device. When a draw or a take is not more than the step, the step takes off half of it.
|
|
140
|
+
- The change of a draw is a finite difference of `enduranceOf`: the days after the step minus the days before it. `perUnit` gives the change for each unit of the input.
|
|
141
|
+
- An input that no draw of the case uses has a change of 0.
|
|
142
|
+
- The rank is by level, as the take order. It compares the sum of the changes of the first level, then of the next level, and so on. The largest sum comes first. Two equal inputs go in the order of their keys.
|
|
143
|
+
- `chance` gives the chance that the draw gets its need through the event (`lasts` of `caseOutlook`), before and after the step. It also gives the values at the two ends of the sampling bands of the cuts, before and after the step. The change of the chance is the change of the point values, with no interval.
|
|
144
|
+
|
|
145
|
+
An example on the sample:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import { enduranceSensitivity, SAMPLE_ENDURANCE } from "@mark1russell7/stack-endurance";
|
|
149
|
+
|
|
150
|
+
const storm = SAMPLE_ENDURANCE.cases?.find((item) => item.case === "storm");
|
|
151
|
+
if (storm !== undefined) {
|
|
152
|
+
const rank = enduranceSensitivity(SAMPLE_ENDURANCE, storm, { at: "2026-12-01" });
|
|
153
|
+
// rank.inputs[0].id is "draw:hydration.drink": 1 L less of drink each day gives 0.644 more days of water.
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
129
157
|
## The joint days
|
|
130
158
|
|
|
131
159
|
`jointDays(layer, caseCuts, options, needs)` gives the joint days of a set of draws. These are the largest count of days `d` at which each draw of the set holds `d` days together.
|
|
@@ -211,7 +239,7 @@ With no horizon, the drink takes all the water for 10 days, and the food gets 0
|
|
|
211
239
|
|
|
212
240
|
| Entry | What it has |
|
|
213
241
|
| --- | --- |
|
|
214
|
-
| `@mark1russell7/stack-endurance` | The records of a layer, the endurance, joint days, best endurance and
|
|
242
|
+
| `@mark1russell7/stack-endurance` | The records of a layer, the endurance, joint days, best endurance, shortfall and sensitivity queries, the gate, the join and a sample. |
|
|
215
243
|
| `@mark1russell7/stack-endurance/schema` | `enduranceSchema`, the zod schema of a layer, with `parseEndurance`. |
|
|
216
244
|
| `@mark1russell7/stack-endurance/add-on` | `enduranceAddOn`, the add-on in the form of the layer contract of the core. |
|
|
217
245
|
|
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-BXx4xoUc.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 { _ 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-
|
|
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-CZZWJtM8.js";
|
|
2
2
|
import { CutBound as CutBound$1, Fault, LayerParse, LayerPiece, PathOptions, Stack, curveFault, survivalAt } from "@mark1russell7/system-stack";
|
|
3
3
|
/**
|
|
4
4
|
* This function tells if a converter is a source (M2-solar): it takes nothing, and it has a limit `perDay` more than 0.
|
|
@@ -131,6 +131,9 @@ export declare function hasSeason(layer: EnduranceLayer, stoppedParts: ReadonlyS
|
|
|
131
131
|
* - A source (M2-solar) takes nothing and has a limit `perDay`. A take uses it first: its runs of a day are lost when no
|
|
132
132
|
* draw uses them. With shares `monthly`, the device-days of a day are the devices times the share of its month. Each
|
|
133
133
|
* span also ends at the start of a month, and a draw can hold again from the start of a month.
|
|
134
|
+
* - A store with a capacity that a source charges (M2-solar-charge-sweep) takes a charge. Each draw that can take it gets the
|
|
135
|
+
* programs of `bestEndurance` for itself alone, in the order of the levels. Thus one draw gets the days of `bestEndurance`.
|
|
136
|
+
* A lower draw takes only the level that the higher draws leave. It charges the store only with the device-days that they leave.
|
|
134
137
|
*
|
|
135
138
|
* 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.
|
|
136
139
|
*
|
|
@@ -708,5 +711,105 @@ export declare const SAMPLE_ENDURANCE_STACK: Stack;
|
|
|
708
711
|
* - The filled bottles are past their due date, so they give nothing.
|
|
709
712
|
*/
|
|
710
713
|
export declare const SAMPLE_ENDURANCE: EnduranceLayer;
|
|
714
|
+
/** The default step of `enduranceSensitivity`: 1 unit of each input. */
|
|
715
|
+
export declare const SENSITIVITY_STEP = 1;
|
|
716
|
+
/** The options of `enduranceSensitivity`: the options of a case, the horizon of the chance, and the step. */
|
|
717
|
+
export interface SensitivityOptions extends CaseOptions, ShortfallOptions {
|
|
718
|
+
/** The step of each input, a number more than 0, in the unit of the input. The default is `SENSITIVITY_STEP`. */
|
|
719
|
+
readonly step?: number | undefined;
|
|
720
|
+
}
|
|
721
|
+
/** The kind of an input: the amount of a store, the rate of a draw, or a parameter of a converter. */
|
|
722
|
+
export type SensitivityKind = "store" | "draw" | "converter";
|
|
723
|
+
/**
|
|
724
|
+
* The change in the chance that a draw gets its need through the event (`DrawOutlook.lasts`), for one input.
|
|
725
|
+
* The chance comes from the curves of the stop. Only the days change, so the curves are the same before and after.
|
|
726
|
+
*/
|
|
727
|
+
export interface SensitivityChance {
|
|
728
|
+
/** The chance before the step, for each curve of the stop. */
|
|
729
|
+
readonly before: CurveValues;
|
|
730
|
+
/** The chance after the step, for each curve of the stop. */
|
|
731
|
+
readonly after: CurveValues;
|
|
732
|
+
/** The chance after the step minus the chance before it, for each curve. It is the change of the point values, not an interval. */
|
|
733
|
+
readonly change: CurveValues;
|
|
734
|
+
/** The values before the step at the two ends of the sampling bands of the cuts (`DrawOutlook.band`). */
|
|
735
|
+
readonly beforeBand?: DrawBand | undefined;
|
|
736
|
+
/** The values after the step at the two ends of the sampling bands of the cuts. */
|
|
737
|
+
readonly afterBand?: DrawBand | undefined;
|
|
738
|
+
}
|
|
739
|
+
/** The change in the days of one draw for one input. */
|
|
740
|
+
export interface SensitivityNeed {
|
|
741
|
+
readonly need: string;
|
|
742
|
+
readonly level: string;
|
|
743
|
+
/** The days of the draw before the step (`DrawEndurance.days`). */
|
|
744
|
+
readonly before: number;
|
|
745
|
+
/** The days of the draw after the step. */
|
|
746
|
+
readonly after: number;
|
|
747
|
+
/** The days after the step minus the days before it. */
|
|
748
|
+
readonly change: number;
|
|
749
|
+
/** The change for each unit of the input: `change` divided by the size of `delta`. */
|
|
750
|
+
readonly perUnit: number;
|
|
751
|
+
/** The change in the chance. It is missing when the stop of the draw has no curve (`CaseOutlook.unread`). */
|
|
752
|
+
readonly chance?: SensitivityChance | undefined;
|
|
753
|
+
}
|
|
754
|
+
/** One input of a layer, and the change in the days of each draw for its step. */
|
|
755
|
+
export interface SensitivityInput {
|
|
756
|
+
/**
|
|
757
|
+
* The key of the input: `store:<id>`, `draw:<need>`, `converter:<id>.gives`, `converter:<id>.takes.<resource>` or
|
|
758
|
+
* `converter:<id>.perDay`. The count of devices has the key of the device and `.devices`, for example `device:stove.devices`.
|
|
759
|
+
*/
|
|
760
|
+
readonly id: string;
|
|
761
|
+
readonly kind: SensitivityKind;
|
|
762
|
+
/** The `id` of the store, the need of the draw, the `id` of the converter, or the device of a count of devices. */
|
|
763
|
+
readonly target: string;
|
|
764
|
+
/** The field that the step changes: `amount`, `perDay`, `gives`, `takes.<resource>` or `devices`. */
|
|
765
|
+
readonly field: string;
|
|
766
|
+
/** The value of the field before the step. */
|
|
767
|
+
readonly value: number;
|
|
768
|
+
/** The change of the value: more than 0 for more of the input, less than 0 for a lower draw or a lower take. */
|
|
769
|
+
readonly delta: number;
|
|
770
|
+
/** The change of each draw whose supply the case stops, in the order of `enduranceOf`. */
|
|
771
|
+
readonly needs: readonly SensitivityNeed[];
|
|
772
|
+
/** The sum of the changes of the draws of each level, by the level. The rank compares these sums. */
|
|
773
|
+
readonly levels: Readonly<Record<string, number>>;
|
|
774
|
+
}
|
|
775
|
+
/** The sensitivity of a layer in a case: each input with its change, the largest change first. */
|
|
776
|
+
export interface Sensitivity {
|
|
777
|
+
readonly case: string;
|
|
778
|
+
readonly at: IsoDate;
|
|
779
|
+
/** The step of the query. */
|
|
780
|
+
readonly step: number;
|
|
781
|
+
/** The endurance before each step. */
|
|
782
|
+
readonly base: Endurance;
|
|
783
|
+
/** The rank of the inputs. Refer to `enduranceSensitivity`. */
|
|
784
|
+
readonly inputs: readonly SensitivityInput[];
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* This function gives the change in the days of each draw for one step of each input of a layer, ranked.
|
|
788
|
+
* The rank names the input that moves the days most. A lower draw costs nothing, so the rank also shows such inputs.
|
|
789
|
+
*
|
|
790
|
+
* - The inputs are the amount of each store and the rate `perDay` of each draw. Each converter gives the amount of its
|
|
791
|
+
* gift, the amount of each take, its limit `perDay` and its count of devices.
|
|
792
|
+
* - The step adds to a store, to a gift, to a limit `perDay` and to a count of devices. It takes off a draw and a take,
|
|
793
|
+
* because less of them gives more days. A count of devices takes 1 more device.
|
|
794
|
+
* - When the rate of a draw or a take is not more than the step, the step takes off half the value. Thus the value stays more than 0.
|
|
795
|
+
* - A store with a capacity gets a capacity that is not less than its new amount.
|
|
796
|
+
* - The change of a draw is a finite difference: the days of `enduranceOf` after the step minus the days before it.
|
|
797
|
+
* `perUnit` divides it by the size of the change of the value.
|
|
798
|
+
* - An input that no draw of the case uses has a change of 0, for example a store past its due date.
|
|
799
|
+
* - The rank is by level. It compares the sum of the changes of the draws of the first level, then of the next level, and so on.
|
|
800
|
+
* The largest sum comes first. Two equal inputs go in the order of their keys. Thus the order is stable.
|
|
801
|
+
* - The days are exact for the inputs. `chance` is the chance that a draw gets its need through the event. It comes
|
|
802
|
+
* from `caseOutlook` with the share `take`, before and after the step, with the bands of the cuts. The change of the
|
|
803
|
+
* chance is the change of the point values. It has no interval.
|
|
804
|
+
*
|
|
805
|
+
* The cost is one `enduranceOf` and one `caseOutlook` for each input. The function is pure.
|
|
806
|
+
*
|
|
807
|
+
* @param layer - The endurance layer
|
|
808
|
+
* @param caseCuts - The case
|
|
809
|
+
* @param options - The date, the stack or the parts that are also down, the horizon and the step
|
|
810
|
+
* @returns The endurance before the steps, and the inputs in the order of the rank
|
|
811
|
+
* @throws RangeError for a step that is not a finite number more than 0, and for the errors of `enduranceOf` and `caseOutlook`
|
|
812
|
+
*/
|
|
813
|
+
export declare function enduranceSensitivity(layer: EnduranceLayer, caseCuts: CaseCuts, options: SensitivityOptions): Sensitivity;
|
|
711
814
|
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 };
|
|
712
815
|
//# 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/converter.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;wBAmMxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,OAAO;;;;;;wBAOF,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;;;;;wBAkB9F,UAAU,OAAO,gBAAgB,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts","../src/sensitivity.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;wBAmMxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,OAAO;;;;;;wBAOF,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;;;;;wBAkB9F,UAAU,OAAO,gBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8C/C,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBCxf7E;WACN;WACA,IAAI;;;;;WAKJ;;WA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AEb,YAAY;;;iBAIN;WACN;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,SAAS;;;iBAIH;;;;;WAKN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,gBAAgB;;WAEhB,QAAQ,SAAS;;;iBAIX;WACN;WACA,IAAI;;WAEJ;;WAEA,MAAM;;WAEN,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2GZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
-
import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as
|
|
2
|
+
import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as deviceKey, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as drawBlock, k as caseParts, l as drawDemand, m as monthEdges, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as shareOf, w as seasonBest, x as fewestOpen, y as sowDays, z as isSource } from "./join-BXx4xoUc.js";
|
|
3
3
|
import { DEFAULT_MAX_SETS, STACK_SCHEMA, dateOfDay, dayNumber, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
|
|
4
4
|
import { ONE, ZERO, add, div, equals, mul, neg, sign, sub, toNumber } from "@mark1russell7/rational";
|
|
5
5
|
import { solveLexicographic } from "@mark1russell7/linear";
|
|
@@ -1442,6 +1442,236 @@ const SAMPLE_ENDURANCE = {
|
|
|
1442
1442
|
asOf: "2025-12-01"
|
|
1443
1443
|
}]
|
|
1444
1444
|
};
|
|
1445
|
-
|
|
1445
|
+
// src/sensitivity.ts
|
|
1446
|
+
/** The default step of `enduranceSensitivity`: 1 unit of each input. */
|
|
1447
|
+
const SENSITIVITY_STEP = 1;
|
|
1448
|
+
/** This function gives the size of a step down from a value. It is the step, or half the value when the value is not more than the step. */
|
|
1449
|
+
function stepDown(value, step) {
|
|
1450
|
+
return value > step ? step : value / 2;
|
|
1451
|
+
}
|
|
1452
|
+
/** This function gives each input of a layer and the layer after its step. */
|
|
1453
|
+
function variantsOf(layer, step) {
|
|
1454
|
+
const out = [];
|
|
1455
|
+
for (const store of layer.stores) {
|
|
1456
|
+
const amount = store.amount + step;
|
|
1457
|
+
const changed = {
|
|
1458
|
+
...store,
|
|
1459
|
+
amount,
|
|
1460
|
+
...store.capacity !== void 0 && amount > store.capacity ? { capacity: amount } : {}
|
|
1461
|
+
};
|
|
1462
|
+
out.push({
|
|
1463
|
+
id: `store:${store.id}`,
|
|
1464
|
+
kind: "store",
|
|
1465
|
+
target: store.id,
|
|
1466
|
+
field: "amount",
|
|
1467
|
+
value: store.amount,
|
|
1468
|
+
delta: step,
|
|
1469
|
+
layer: {
|
|
1470
|
+
...layer,
|
|
1471
|
+
stores: layer.stores.map((item) => item === store ? changed : item)
|
|
1472
|
+
}
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
for (const draw of layer.draws) {
|
|
1476
|
+
if (!(draw.perDay > 0)) continue;
|
|
1477
|
+
const delta = -stepDown(draw.perDay, step);
|
|
1478
|
+
const changed = {
|
|
1479
|
+
...draw,
|
|
1480
|
+
perDay: draw.perDay + delta
|
|
1481
|
+
};
|
|
1482
|
+
out.push({
|
|
1483
|
+
id: `draw:${draw.need}`,
|
|
1484
|
+
kind: "draw",
|
|
1485
|
+
target: draw.need,
|
|
1486
|
+
field: "perDay",
|
|
1487
|
+
value: draw.perDay,
|
|
1488
|
+
delta,
|
|
1489
|
+
layer: {
|
|
1490
|
+
...layer,
|
|
1491
|
+
draws: layer.draws.map((item) => item === draw ? changed : item)
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
const converters = layer.converters ?? [];
|
|
1496
|
+
const withConverters = (change) => ({
|
|
1497
|
+
...layer,
|
|
1498
|
+
converters: converters.map(change)
|
|
1499
|
+
});
|
|
1500
|
+
const devicesSeen = /* @__PURE__ */ new Set();
|
|
1501
|
+
for (const converter of converters) {
|
|
1502
|
+
const key = `converter:${converter.id}`;
|
|
1503
|
+
if (converter.gives.amount > 0) {
|
|
1504
|
+
const gives = {
|
|
1505
|
+
...converter.gives,
|
|
1506
|
+
amount: converter.gives.amount + step
|
|
1507
|
+
};
|
|
1508
|
+
out.push({
|
|
1509
|
+
id: `${key}.gives`,
|
|
1510
|
+
kind: "converter",
|
|
1511
|
+
target: converter.id,
|
|
1512
|
+
field: "gives",
|
|
1513
|
+
value: converter.gives.amount,
|
|
1514
|
+
delta: step,
|
|
1515
|
+
layer: withConverters((item) => item === converter ? {
|
|
1516
|
+
...item,
|
|
1517
|
+
gives
|
|
1518
|
+
} : item)
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
for (const input of converter.takes) {
|
|
1522
|
+
if (!(input.amount > 0)) continue;
|
|
1523
|
+
const delta = -stepDown(input.amount, step);
|
|
1524
|
+
const takes = converter.takes.map((item) => item === input ? {
|
|
1525
|
+
...item,
|
|
1526
|
+
amount: item.amount + delta
|
|
1527
|
+
} : item);
|
|
1528
|
+
out.push({
|
|
1529
|
+
id: `${key}.takes.${input.resource}`,
|
|
1530
|
+
kind: "converter",
|
|
1531
|
+
target: converter.id,
|
|
1532
|
+
field: `takes.${input.resource}`,
|
|
1533
|
+
value: input.amount,
|
|
1534
|
+
delta,
|
|
1535
|
+
layer: withConverters((item) => item === converter ? {
|
|
1536
|
+
...item,
|
|
1537
|
+
takes
|
|
1538
|
+
} : item)
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
if (converter.perDay === void 0) continue;
|
|
1542
|
+
const perDay = converter.perDay + step;
|
|
1543
|
+
out.push({
|
|
1544
|
+
id: `${key}.perDay`,
|
|
1545
|
+
kind: "converter",
|
|
1546
|
+
target: converter.id,
|
|
1547
|
+
field: "perDay",
|
|
1548
|
+
value: converter.perDay,
|
|
1549
|
+
delta: step,
|
|
1550
|
+
layer: withConverters((item) => item === converter ? {
|
|
1551
|
+
...item,
|
|
1552
|
+
perDay
|
|
1553
|
+
} : item)
|
|
1554
|
+
});
|
|
1555
|
+
const device = deviceKey(converter);
|
|
1556
|
+
if (devicesSeen.has(device)) continue;
|
|
1557
|
+
devicesSeen.add(device);
|
|
1558
|
+
const count = converter.devices ?? 1;
|
|
1559
|
+
out.push({
|
|
1560
|
+
id: `${device}.devices`,
|
|
1561
|
+
kind: "converter",
|
|
1562
|
+
target: converter.device ?? converter.id,
|
|
1563
|
+
field: "devices",
|
|
1564
|
+
value: count,
|
|
1565
|
+
delta: 1,
|
|
1566
|
+
layer: withConverters((item) => deviceKey(item) === device ? {
|
|
1567
|
+
...item,
|
|
1568
|
+
devices: count + 1
|
|
1569
|
+
} : item)
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
return out;
|
|
1573
|
+
}
|
|
1574
|
+
/** This function gives `a` minus `b` for each curve. */
|
|
1575
|
+
function minus(a, b) {
|
|
1576
|
+
return {
|
|
1577
|
+
event: a.event - b.event,
|
|
1578
|
+
independent: a.independent - b.independent,
|
|
1579
|
+
upper: a.upper - b.upper
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
/** This function compares two inputs for the rank: the sums of the levels in the order of the levels, the largest first, then the key. */
|
|
1583
|
+
function rankOrder(levels) {
|
|
1584
|
+
return (a, b) => {
|
|
1585
|
+
for (const level of levels) {
|
|
1586
|
+
const diff = (b.levels[level] ?? 0) - (a.levels[level] ?? 0);
|
|
1587
|
+
if (diff > 0) return 1;
|
|
1588
|
+
if (diff < 0) return -1;
|
|
1589
|
+
}
|
|
1590
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* This function gives the change in the days of each draw for one step of each input of a layer, ranked.
|
|
1595
|
+
* The rank names the input that moves the days most. A lower draw costs nothing, so the rank also shows such inputs.
|
|
1596
|
+
*
|
|
1597
|
+
* - The inputs are the amount of each store and the rate `perDay` of each draw. Each converter gives the amount of its
|
|
1598
|
+
* gift, the amount of each take, its limit `perDay` and its count of devices.
|
|
1599
|
+
* - The step adds to a store, to a gift, to a limit `perDay` and to a count of devices. It takes off a draw and a take,
|
|
1600
|
+
* because less of them gives more days. A count of devices takes 1 more device.
|
|
1601
|
+
* - When the rate of a draw or a take is not more than the step, the step takes off half the value. Thus the value stays more than 0.
|
|
1602
|
+
* - A store with a capacity gets a capacity that is not less than its new amount.
|
|
1603
|
+
* - The change of a draw is a finite difference: the days of `enduranceOf` after the step minus the days before it.
|
|
1604
|
+
* `perUnit` divides it by the size of the change of the value.
|
|
1605
|
+
* - An input that no draw of the case uses has a change of 0, for example a store past its due date.
|
|
1606
|
+
* - The rank is by level. It compares the sum of the changes of the draws of the first level, then of the next level, and so on.
|
|
1607
|
+
* The largest sum comes first. Two equal inputs go in the order of their keys. Thus the order is stable.
|
|
1608
|
+
* - The days are exact for the inputs. `chance` is the chance that a draw gets its need through the event. It comes
|
|
1609
|
+
* from `caseOutlook` with the share `take`, before and after the step, with the bands of the cuts. The change of the
|
|
1610
|
+
* chance is the change of the point values. It has no interval.
|
|
1611
|
+
*
|
|
1612
|
+
* The cost is one `enduranceOf` and one `caseOutlook` for each input. The function is pure.
|
|
1613
|
+
*
|
|
1614
|
+
* @param layer - The endurance layer
|
|
1615
|
+
* @param caseCuts - The case
|
|
1616
|
+
* @param options - The date, the stack or the parts that are also down, the horizon and the step
|
|
1617
|
+
* @returns The endurance before the steps, and the inputs in the order of the rank
|
|
1618
|
+
* @throws RangeError for a step that is not a finite number more than 0, and for the errors of `enduranceOf` and `caseOutlook`
|
|
1619
|
+
*/
|
|
1620
|
+
function enduranceSensitivity(layer, caseCuts, options) {
|
|
1621
|
+
const { step: given, ...caseOptions } = options;
|
|
1622
|
+
const step = given ?? 1;
|
|
1623
|
+
if (!(step > 0) || !Number.isFinite(step)) throw new RangeError(`The step ${String(given)} is not a finite number more than 0.`);
|
|
1624
|
+
const base = enduranceOf(layer, caseCuts, caseOptions);
|
|
1625
|
+
const outlookOf = (changed) => new Map(caseOutlook(changed, caseCuts, {
|
|
1626
|
+
...caseOptions,
|
|
1627
|
+
share: "take"
|
|
1628
|
+
}).draws.map((draw) => [draw.need, draw]));
|
|
1629
|
+
const baseOutlook = outlookOf(layer);
|
|
1630
|
+
const levelOf = new Map(layer.draws.map((draw) => [draw.need, draw.level]));
|
|
1631
|
+
const inputs = variantsOf(layer, step).map(({ layer: changed, ...variant }) => {
|
|
1632
|
+
const after = enduranceOf(changed, caseCuts, caseOptions);
|
|
1633
|
+
const outlook = baseOutlook.size === 0 ? void 0 : outlookOf(changed);
|
|
1634
|
+
const sums = new Map(layer.levels.map((level) => [level, 0]));
|
|
1635
|
+
const needs = Object.entries(base.needs).map(([need, held]) => {
|
|
1636
|
+
const days = after.needs[need]?.days ?? held.days;
|
|
1637
|
+
const change = days === held.days ? 0 : days - held.days;
|
|
1638
|
+
const level = levelOf.get(need) ?? "";
|
|
1639
|
+
const sum = sums.get(level);
|
|
1640
|
+
if (sum !== void 0) sums.set(level, sum + change);
|
|
1641
|
+
const from = baseOutlook.get(need);
|
|
1642
|
+
const to = outlook?.get(need);
|
|
1643
|
+
const chance = from === void 0 || to === void 0 ? {} : { chance: {
|
|
1644
|
+
before: from.lasts,
|
|
1645
|
+
after: to.lasts,
|
|
1646
|
+
change: minus(to.lasts, from.lasts),
|
|
1647
|
+
...from.band === void 0 ? {} : { beforeBand: from.band },
|
|
1648
|
+
...to.band === void 0 ? {} : { afterBand: to.band }
|
|
1649
|
+
} };
|
|
1650
|
+
return {
|
|
1651
|
+
need,
|
|
1652
|
+
level,
|
|
1653
|
+
before: held.days,
|
|
1654
|
+
after: days,
|
|
1655
|
+
change,
|
|
1656
|
+
perUnit: change / Math.abs(variant.delta),
|
|
1657
|
+
...chance
|
|
1658
|
+
};
|
|
1659
|
+
});
|
|
1660
|
+
return {
|
|
1661
|
+
...variant,
|
|
1662
|
+
needs,
|
|
1663
|
+
levels: Object.fromEntries(sums)
|
|
1664
|
+
};
|
|
1665
|
+
});
|
|
1666
|
+
inputs.sort(rankOrder(layer.levels));
|
|
1667
|
+
return {
|
|
1668
|
+
case: caseCuts.case,
|
|
1669
|
+
at: options.at,
|
|
1670
|
+
step,
|
|
1671
|
+
base,
|
|
1672
|
+
inputs
|
|
1673
|
+
};
|
|
1674
|
+
}
|
|
1675
|
+
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SENSITIVITY_STEP, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, enduranceSensitivity, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, isSource, joinEndurance, jointDays, longestStop, minimalStops, monthEdges, monthOf, monthlyShares, seasonSupply, shareOf, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
1446
1676
|
|
|
1447
1677
|
//# sourceMappingURL=index.js.map
|