@mark1russell7/stack-endurance 0.8.5 → 0.8.7
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 +31 -2
- package/build/index.d.ts +33 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +435 -138
- package/build/index.js.map +1 -1
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +14 -1
- package/build/schema.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Each function is a plain function with no clock, no network and no file. The uni
|
|
|
29
29
|
- The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.
|
|
30
30
|
- Each higher draw keeps back its own days times its demand. Thus the takes of all the draws are not more than the stores at any time.
|
|
31
31
|
- The take order is a rule, not the best share. The days are the days of this order. A draw with a shared device is different (refer to the limit `perDay` below). `takes` gives the amount of each resource that a draw takes.
|
|
32
|
-
- `jointDays` gives the best share for a set of draws. Refer to the
|
|
32
|
+
- `jointDays` gives the best share for a set of draws. `bestEndurance` gives the best share for all the draws, level by level. Refer to the sections on the joint days and on the best endurance.
|
|
33
33
|
- A store gives nothing on its due date and after it. A store or a converter whose part stops gives nothing.
|
|
34
34
|
- A converter can have a limit `perDay`, the most runs of one device in a day, and a count `devices` (default 1). Over `T` days, the converters of one device use `devices` times `T` days of the device or less. One run uses `1 / perDay` of a day of the device. A maker and its taker on one device share these days.
|
|
35
35
|
- The higher draws use the days of a device first. Each higher draw keeps back its part of each day for all the days of a lower draw. This is the safe side.
|
|
@@ -107,11 +107,40 @@ The take order gives the drink 6.667 days. The drink keeps back all the water fo
|
|
|
107
107
|
|
|
108
108
|
The joint days are not more than the days of each draw alone. The take order tells the days of a rule of priority. The joint days tell the days of the best share.
|
|
109
109
|
|
|
110
|
+
## The best endurance
|
|
111
|
+
|
|
112
|
+
`bestEndurance(layer, caseCuts, options)` gives the days of each draw with the best share of the stores and of the devices. Its result has the form of `enduranceOf`, so `caseShortfall` takes it.
|
|
113
|
+
|
|
114
|
+
- The share is lexicographic by level. The draws of the first level get their best days. Then the draws of the next level get their best days, and so on.
|
|
115
|
+
- In one level, the share is the best for the draw with the fewest days, then for the next draw, and so on. This is the leximin share.
|
|
116
|
+
- Thus a draw cannot take a store that another draw of its level needs more. A higher draw does not take a store that a lower draw needs, when the higher draw has a second way.
|
|
117
|
+
- Each step is a linear program with exact rationals. It takes the largest common floor of the open draws.
|
|
118
|
+
- A draw whose floor row has a dual value that is not 0 cannot get more days. The step fixes its days. Each step fixes one draw or more.
|
|
119
|
+
- A fixed draw keeps its days. Its share of the stocks can change in a later step.
|
|
120
|
+
- A fixed draw keeps the device-days of each day that it uses, for all the days of the later draws. This is the safe side, as in `enduranceOf`.
|
|
121
|
+
- A draw with no end gets `Infinity` days. It takes no stock.
|
|
122
|
+
- The stores, the uses, the converters and the devices follow the rules of `jointDays`.
|
|
123
|
+
- The fewest days of the first level are the joint days of the draws of that level.
|
|
124
|
+
|
|
125
|
+
An example: the draw `a` drinks water or juice, and the draw `b` drinks only water. Each draw takes 1 L each day, and the stores have 10 L of each. The two draws are at one level.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { bestEndurance, enduranceOf } from "@mark1russell7/stack-endurance";
|
|
129
|
+
|
|
130
|
+
const ordered = enduranceOf(layer, dry, { at: "2026-12-01" });
|
|
131
|
+
// ordered.needs.a.days is 20, and ordered.needs.b.days is 0.
|
|
132
|
+
const best = bestEndurance(layer, dry, { at: "2026-12-01" });
|
|
133
|
+
// best.needs.a is { days: 10, binding: ["juice", "water"], takes: { juice: 10 } }.
|
|
134
|
+
// best.needs.b is { days: 10, binding: ["water"], takes: { water: 10 } }.
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The take order gives the water to `a` first, so `b` gets 0 days. The best share gives the juice to `a` and the water to `b`.
|
|
138
|
+
|
|
110
139
|
## The entries
|
|
111
140
|
|
|
112
141
|
| Entry | What it has |
|
|
113
142
|
| --- | --- |
|
|
114
|
-
| `@mark1russell7/stack-endurance` | The records of a layer, the endurance, joint days and shortfall queries, the gate, the join and a sample. |
|
|
143
|
+
| `@mark1russell7/stack-endurance` | The records of a layer, the endurance, joint days, best endurance and shortfall queries, the gate, the join and a sample. |
|
|
115
144
|
| `@mark1russell7/stack-endurance/schema` | `enduranceSchema`, the zod schema of a layer, with `parseEndurance`. |
|
|
116
145
|
| `@mark1russell7/stack-endurance/add-on` | `enduranceAddOn`, the add-on in the form of the layer contract of the core. |
|
|
117
146
|
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as DirectUse, c as ENDURANCE_SCHEMA, d as Gift, f as IsoDate, g as Survival, h as Store, i as CutBound, l as Endurance, m as Resource, n as Converter, o as Draw, p as Prior, r as Cut, s as DrawEndurance, t as CaseCuts, u as EnduranceLayer } from "./layer-BwbOgVFi.js";
|
|
2
|
-
import { CutBound as CutBound$1, Fault, LayerParse, LayerPiece, PathOptions, Stack, curveFault } from "@mark1russell7/system-stack";
|
|
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 {
|
|
5
5
|
/** The date of the query. A store whose due date is on this date or before it gives nothing. */
|
|
@@ -122,8 +122,37 @@ export interface JointDays {
|
|
|
122
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`.
|
|
123
123
|
*/
|
|
124
124
|
export declare function jointDays(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions, needs: readonly string[]): JointDays;
|
|
125
|
-
/**
|
|
126
|
-
|
|
125
|
+
/**
|
|
126
|
+
* This function gives the days that each draw holds when a case stops its supply. The stores and the devices have their best share.
|
|
127
|
+
* The result has the form of `enduranceOf`, so `caseShortfall` takes it.
|
|
128
|
+
*
|
|
129
|
+
* The share is lexicographic. The draws of the first level get their best days, then the draws of the next level get theirs, and so on.
|
|
130
|
+
* In one level, the share is the best for the draw with the fewest days, then for the next draw, and so on (the leximin share).
|
|
131
|
+
* Thus a draw of a level cannot take a store that another draw of the level needs more.
|
|
132
|
+
*
|
|
133
|
+
* - The function solves a sequence of linear programs over the totals of the spans. Each program has the days of the open draws
|
|
134
|
+
* and their common floor. For each draw, it has the take of each direct use, the runs of each converter and the share of each stock.
|
|
135
|
+
* - Each step takes the largest floor. A draw whose floor row has a dual value that is not 0 cannot get more days. The step fixes its days.
|
|
136
|
+
* The dual values of the floor rows add to 1, so each step fixes one draw or more.
|
|
137
|
+
* - A fixed draw keeps its days in each later step. Its share of the stocks can change, so a later draw can get a store that it does not need.
|
|
138
|
+
* - The stores, the direct uses, the converters and the devices follow the rules of `jointDays`. A store counts with all of its amount when its due date is after `at`.
|
|
139
|
+
* - A fixed draw keeps the device-days of each day that it uses at its step, for all the days of the later draws. This is the safe side, as in `enduranceOf`.
|
|
140
|
+
* The exact share of a device between two spans is not a linear program: the device-days of a day are the runs over the span.
|
|
141
|
+
* - A step with no largest floor gives the open draws no end. Each of them takes no stock, and keeps the fewest device-days of each day.
|
|
142
|
+
* - At the end, a program takes the smallest sum of the shares of the stocks, each over its stock, then the fewest device-days.
|
|
143
|
+
* These are the takes of the result. A resource in `binding` has no stock left at this point.
|
|
144
|
+
* - A draw in `capped` used a device with no device-days left at the step that fixed it.
|
|
145
|
+
*
|
|
146
|
+
* The programs use exact rationals, so the result has no error of the method. Only the change back to a number rounds.
|
|
147
|
+
* The fewest days of the first level are the joint days (`jointDays`) of the draws of that level.
|
|
148
|
+
*
|
|
149
|
+
* @param layer - The endurance layer
|
|
150
|
+
* @param caseCuts - The case
|
|
151
|
+
* @param options - The date, and the stack or the parts that are also down
|
|
152
|
+
* @returns The endurance of each draw whose supply stops
|
|
153
|
+
* @throws {RangeError} A date is not `YYYY-MM-DD`.
|
|
154
|
+
*/
|
|
155
|
+
export declare function bestEndurance(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions): Endurance;
|
|
127
156
|
/**
|
|
128
157
|
* This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.
|
|
129
158
|
* It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.
|
|
@@ -410,5 +439,5 @@ export declare const SAMPLE_ENDURANCE_STACK: Stack;
|
|
|
410
439
|
* - The filled bottles are past their due date, so they give nothing.
|
|
411
440
|
*/
|
|
412
441
|
export declare const SAMPLE_ENDURANCE: EnduranceLayer;
|
|
413
|
-
export { type CaseCuts, Converter, type Cut, type CutBound, DirectUse, Draw, DrawEndurance, ENDURANCE_SCHEMA, Endurance, EnduranceLayer, Gift, IsoDate, type Prior, Resource, Store, type Survival, curveFault };
|
|
442
|
+
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 };
|
|
414
443
|
//# 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/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBASiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0LxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBC7P7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+BK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B
|
|
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":";;;iBASiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0LxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBC7P7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+BK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCNtG,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBClDhF,SAAS,OAAO,UAAU,cAAc;;;;;;;;;;iBAqBvC,yBAAyB,KAAK,gCAAgC,KAAK;;WAEzE;;iBAGM,yBAAyB;;WAE/B;;;;;;wBAqBK,iBAAiB,OAAO,UAAU;;wBAWlC,WAAW,OAAO;;wBAKlB,SAAS,OAA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