@mark1russell7/stack-endurance 0.6.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/build/add-on.d.ts +1 -1
- package/build/add-on.js +1 -1
- package/build/index.d.ts +11 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{join-BRnPkac5.js → join-Cglucg6Q.js} +81 -7
- package/build/join-Cglucg6Q.js.map +1 -0
- package/build/{layer-DhGakJvy.d.ts → layer-CF0r-9ww.d.ts} +27 -1
- package/build/layer-CF0r-9ww.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 +3 -1
- package/build/schema.js.map +1 -1
- package/package.json +1 -1
- package/build/join-BRnPkac5.js.map +0 -1
- package/build/layer-DhGakJvy.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -30,6 +30,9 @@ Each function is a plain function with no clock, no network and no file. The uni
|
|
|
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. `takes` gives the amount of each resource that a draw takes.
|
|
32
32
|
- A store gives nothing on its due date and after it. A store or a converter whose part stops gives nothing.
|
|
33
|
+
- 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.
|
|
34
|
+
- 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.
|
|
35
|
+
- `capped` names the converters whose limit stops a draw while their inputs have more. After `days`, the shortfall counts each day as a full shortfall.
|
|
33
36
|
|
|
34
37
|
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.
|
|
35
38
|
|
|
@@ -102,4 +105,4 @@ In the sample, the rice needs 2 L of water for each kg. The drinking water holds
|
|
|
102
105
|
|
|
103
106
|
## The gate
|
|
104
107
|
|
|
105
|
-
`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. A draw with no way to get its need is a warning, and a cut with no curve is a warning.
|
|
108
|
+
`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.
|
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-Cglucg6Q.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 Draw, c as Endurance, d as IsoDate, f as Prior, h as Survival, i as DirectUse, l as EnduranceLayer, m as Store, n as Converter, o as DrawEndurance, p as Resource, r as Cut, s as ENDURANCE_SCHEMA, t as CaseCuts, u as Gift } from "./layer-
|
|
1
|
+
import { a as Draw, c as Endurance, d as IsoDate, f as Prior, h as Survival, i as DirectUse, l as EnduranceLayer, m as Store, n as Converter, o as DrawEndurance, p as Resource, r as Cut, s as ENDURANCE_SCHEMA, t as CaseCuts, u as Gift } from "./layer-CF0r-9ww.js";
|
|
2
2
|
import { Fault, LayerParse, LayerPiece, PathOptions, Stack, curveFault } from "@mark1russell7/system-stack";
|
|
3
3
|
/** The options of the queries of a case. */
|
|
4
4
|
export interface CaseOptions {
|
|
@@ -43,6 +43,11 @@ export declare function giftResource(converter: Converter): string | undefined;
|
|
|
43
43
|
* - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.
|
|
44
44
|
* - A converter whose device stops gives nothing. A store whose part stops gives nothing.
|
|
45
45
|
* - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.
|
|
46
|
+
* - A converter with a limit `perDay` runs `perDay` times `devices` times `T` times or less in `T` days. The converters of one device share it.
|
|
47
|
+
* - The higher draws use the runs of a limit first.
|
|
48
|
+
* - A higher draw keeps back its runs of each day for all the days of a lower draw, also when its own days are fewer. This is the safe side.
|
|
49
|
+
* - Two limited converters of one device can make the shortfall of a try decrease when the days increase. Then the fit can stop below the largest fit.
|
|
50
|
+
* Each result is a real fit, so the days are on the safe side. A small change of a store can change the days by a large step.
|
|
46
51
|
*
|
|
47
52
|
* 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.
|
|
48
53
|
*
|
|
@@ -255,7 +260,7 @@ export interface YearShortfall extends Shortfall {
|
|
|
255
260
|
*/
|
|
256
261
|
export declare function yearShortfall(layer: EnduranceLayer, place: string, options: CaseOptions & ShortfallOptions): YearShortfall;
|
|
257
262
|
/**
|
|
258
|
-
* These are the codes of the gate. Each code is an error, except `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.
|
|
263
|
+
* These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.
|
|
259
264
|
*
|
|
260
265
|
* - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.
|
|
261
266
|
* The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.
|
|
@@ -269,10 +274,13 @@ export declare function yearShortfall(layer: EnduranceLayer, place: string, opti
|
|
|
269
274
|
* Or its days do not increase, or its chance increases.
|
|
270
275
|
* - `endurance-prior-case`: a prior names a case that the layer does not have.
|
|
271
276
|
* - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.
|
|
277
|
+
* - `endurance-devices`: two converters of one device give two different counts of devices.
|
|
278
|
+
* - `endurance-device-mix` (warning): a device has a converter with a limit `perDay` and a converter with no limit. The
|
|
279
|
+
* converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.
|
|
272
280
|
* - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.
|
|
273
281
|
* - `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.
|
|
274
282
|
*/
|
|
275
|
-
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-prior-case", "endurance-cycle", "endurance-no-way", "endurance-cut-no-curve"];
|
|
283
|
+
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-prior-case", "endurance-cycle", "endurance-devices", "endurance-device-mix", "endurance-no-way", "endurance-cut-no-curve"];
|
|
276
284
|
/** A code of `ENDURANCE_CODES`. */
|
|
277
285
|
export type EnduranceCode = (typeof ENDURANCE_CODES)[number];
|
|
278
286
|
/** A fault of the gate of an endurance layer. */
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/endurance.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAOiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,YAAY,UAAU,UAAU,SAA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AAyC;;;;;iBAiKvI;WACN,OAAO;;WAEP,aAAa;WACb,OAAO;;;;;WAKP;;WAEA;;;;;;;;;;;;;;;wBA+DK,WAAW,UAAU,UAAU,MAAM,MAAM,UAAS,mBAAwB;;iBAM3E;;;;;WAKN,QAAQ,SAAS;;WAEjB,aAAa,SAAS;;WAEtB,OAAO,SAAS;;;;;WAKhB;;WAEA;;WAEA;;;;;;;;;;;;wBAiBK,cAAc,OAAO,gBAAgB,UAAU,UAAU,WAAW,WAAW,UAAS,mBAAwB;;iBA4B/G,sBAAsB;WAC5B;;WAEA;aAA2B;aAAuB;aAAuB,WAAW;aAAoB,WAAW;;;;;;;;;;;;;;;;wBAgB9G,cAAc,OAAO,gBAAgB,eAAe,SAAS,cAAc,mBAAmB;;;;;;;;;;;;;;;;;;;;;;qBC7iBjG;;YAiCD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBA+ItD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBCxMnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
-
import { a as hasEnduranceError, c as drawDemand, d as giftResource, f as storeAmounts, i as curveFault, l as enduranceOf, n as ENDURANCE_CODES, o as caseDraws, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed } from "./join-
|
|
2
|
+
import { a as hasEnduranceError, c as drawDemand, d as giftResource, f as storeAmounts, i as curveFault, l as enduranceOf, n as ENDURANCE_CODES, o as caseDraws, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed } from "./join-Cglucg6Q.js";
|
|
3
3
|
import { DEFAULT_MAX_SETS, STACK_SCHEMA, neededParts, stopSets } from "@mark1russell7/system-stack";
|
|
4
4
|
import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
5
5
|
// src/stops.ts
|
|
@@ -157,6 +157,18 @@ function waysOf(layer, need, stoppedParts, makers) {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
const NO_PATH = /* @__PURE__ */ new Set();
|
|
160
|
+
const RUNS = "\0runs:";
|
|
161
|
+
function runsKey(converter) {
|
|
162
|
+
return converter.device === void 0 ? `${RUNS}converter:${converter.id}` : `${RUNS}device:${converter.device}`;
|
|
163
|
+
}
|
|
164
|
+
/** This function gives the device-days that a converter has left in `left`, or undefined with no limit. */
|
|
165
|
+
function daysLeft(left, converter) {
|
|
166
|
+
return converter.perDay === void 0 ? void 0 : left.get(runsKey(converter));
|
|
167
|
+
}
|
|
168
|
+
/** This function gives the map with no runs left of the converters: a map of the resources only. */
|
|
169
|
+
function resourcesOnly(left) {
|
|
170
|
+
return new Map([...left].filter(([key]) => !key.startsWith(RUNS)));
|
|
171
|
+
}
|
|
160
172
|
/**
|
|
161
173
|
* This function gives the most of a resource that `left` gives: its stock, and the runs of each maker.
|
|
162
174
|
* It is an upper limit. When two inputs come from one resource, the true amount can be less.
|
|
@@ -170,7 +182,8 @@ function mostResource(left, makers, resource, path) {
|
|
|
170
182
|
}
|
|
171
183
|
/** This function gives the most runs of a converter that `left` gives. It is an upper limit, as for `mostResource`. */
|
|
172
184
|
function mostRuns(left, makers, converter, path) {
|
|
173
|
-
|
|
185
|
+
const limit = daysLeft(left, converter);
|
|
186
|
+
let runs = limit === void 0 ? 1e400 : limit * (converter.perDay ?? 0);
|
|
174
187
|
for (const [resource, each] of inputsOf(converter)) runs = Math.min(runs, mostResource(left, makers, resource, path) / each);
|
|
175
188
|
return Number.isFinite(runs) ? runs : 0;
|
|
176
189
|
}
|
|
@@ -203,6 +216,14 @@ function run(left, makers, converter, wanted, path) {
|
|
|
203
216
|
const copy = new Map(left);
|
|
204
217
|
let need = 0;
|
|
205
218
|
let short = 0;
|
|
219
|
+
const limit = daysLeft(copy, converter);
|
|
220
|
+
if (limit !== void 0 && converter.perDay !== void 0 && converter.perDay > 0) {
|
|
221
|
+
const wanted = runs / converter.perDay;
|
|
222
|
+
const got = Math.min(wanted, limit);
|
|
223
|
+
copy.set(runsKey(converter), limit - got);
|
|
224
|
+
need += runs;
|
|
225
|
+
short += (wanted - got) * converter.perDay;
|
|
226
|
+
}
|
|
206
227
|
for (const [resource, each] of inputs) {
|
|
207
228
|
need += runs * each;
|
|
208
229
|
short += takeResource(copy, makers, resource, runs * each, path);
|
|
@@ -260,6 +281,11 @@ const USED_UP = 1e-9;
|
|
|
260
281
|
* - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.
|
|
261
282
|
* - A converter whose device stops gives nothing. A store whose part stops gives nothing.
|
|
262
283
|
* - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.
|
|
284
|
+
* - A converter with a limit `perDay` runs `perDay` times `devices` times `T` times or less in `T` days. The converters of one device share it.
|
|
285
|
+
* - The higher draws use the runs of a limit first.
|
|
286
|
+
* - A higher draw keeps back its runs of each day for all the days of a lower draw, also when its own days are fewer. This is the safe side.
|
|
287
|
+
* - Two limited converters of one device can make the shortfall of a try decrease when the days increase. Then the fit can stop below the largest fit.
|
|
288
|
+
* Each result is a real fit, so the days are on the safe side. A small change of a store can change the days by a large step.
|
|
263
289
|
*
|
|
264
290
|
* 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.
|
|
265
291
|
*
|
|
@@ -273,15 +299,29 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
273
299
|
const start = storeAmounts(layer, options.at, stoppedParts);
|
|
274
300
|
const makers = makersOf(layer, stoppedParts);
|
|
275
301
|
const stocked = new Set(layer.stores.map((store) => store.resource));
|
|
302
|
+
const limited = (layer.converters ?? []).filter((converter) => converter.perDay !== void 0 && canRun(converter, stoppedParts));
|
|
303
|
+
const devices = new Map(limited.map((converter) => [runsKey(converter), converter.devices ?? 1]));
|
|
304
|
+
const giveRuns = (left, used, days) => {
|
|
305
|
+
for (const [key, count] of devices) left.set(key, Math.max(0, count - (used.get(key) ?? 0)) * days);
|
|
306
|
+
};
|
|
276
307
|
const done = [];
|
|
277
308
|
const needs = {};
|
|
278
309
|
for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {
|
|
279
310
|
const ways = waysOf(layer, draw.need, stoppedParts, makers);
|
|
280
311
|
const demand = drawDemand(draw, caseCuts);
|
|
281
|
-
|
|
282
|
-
|
|
312
|
+
let before = new Map(start);
|
|
313
|
+
const used = /* @__PURE__ */ new Map();
|
|
314
|
+
for (const higher of done) {
|
|
315
|
+
giveRuns(before, used, higher.days);
|
|
316
|
+
const given = new Map(before);
|
|
317
|
+
take(before, higher.ways, higher.days * higher.demand);
|
|
318
|
+
if (!(higher.days > 0)) continue;
|
|
319
|
+
for (const key of devices.keys()) used.set(key, (used.get(key) ?? 0) + ((given.get(key) ?? 0) - (before.get(key) ?? 0)) / higher.days);
|
|
320
|
+
}
|
|
321
|
+
before = resourcesOnly(before);
|
|
283
322
|
const after = (days) => {
|
|
284
323
|
const left = new Map(before);
|
|
324
|
+
giveRuns(left, used, days);
|
|
285
325
|
return {
|
|
286
326
|
left,
|
|
287
327
|
short: take(left, ways, days * demand)
|
|
@@ -297,16 +337,26 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
297
337
|
});
|
|
298
338
|
const low = fit.x;
|
|
299
339
|
const left = fit.value ?? after(low).left;
|
|
300
|
-
const
|
|
340
|
+
const stores = resourcesOnly(left);
|
|
341
|
+
const binding = [...inputClosure(ways)].filter((resource) => !makers.has(resource) || stocked.has(resource)).filter((resource) => mostResource(stores, makers, resource, NO_PATH) <= USED_UP * Math.max(1, start.get(resource) ?? 0)).sort();
|
|
301
342
|
const takes = {};
|
|
302
343
|
for (const [resource, amount] of before) {
|
|
303
344
|
const taken = amount - (left.get(resource) ?? 0);
|
|
304
345
|
if (taken > 0) takes[resource] = taken;
|
|
305
346
|
}
|
|
306
|
-
|
|
347
|
+
const reach = /* @__PURE__ */ new Set([...ways.converters, ...[...inputClosure(ways)].flatMap((resource) => makers.get(resource) ?? [])]);
|
|
348
|
+
const runsLeft = (converter) => (daysLeft(left, converter) ?? 0) * (converter.perDay ?? 0);
|
|
349
|
+
const runsGiven = (converter) => (devices.get(runsKey(converter)) ?? 1) * (converter.perDay ?? 0) * low;
|
|
350
|
+
const capped = limited.filter((converter) => reach.has(converter)).filter((converter) => runsLeft(converter) <= USED_UP * Math.max(1, runsGiven(converter))).filter((converter) => mostRuns(stores, makers, converter, NO_PATH) > USED_UP).map((converter) => converter.id).sort();
|
|
351
|
+
needs[draw.need] = capped.length === 0 ? {
|
|
307
352
|
days: low,
|
|
308
353
|
binding,
|
|
309
354
|
takes
|
|
355
|
+
} : {
|
|
356
|
+
days: low,
|
|
357
|
+
binding,
|
|
358
|
+
takes,
|
|
359
|
+
capped
|
|
310
360
|
};
|
|
311
361
|
done.push({
|
|
312
362
|
ways,
|
|
@@ -332,7 +382,7 @@ function capacity(start, ways) {
|
|
|
332
382
|
}
|
|
333
383
|
// src/check.ts
|
|
334
384
|
/**
|
|
335
|
-
* These are the codes of the gate. Each code is an error, except `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.
|
|
385
|
+
* These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.
|
|
336
386
|
*
|
|
337
387
|
* - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.
|
|
338
388
|
* The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.
|
|
@@ -346,6 +396,9 @@ function capacity(start, ways) {
|
|
|
346
396
|
* Or its days do not increase, or its chance increases.
|
|
347
397
|
* - `endurance-prior-case`: a prior names a case that the layer does not have.
|
|
348
398
|
* - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.
|
|
399
|
+
* - `endurance-devices`: two converters of one device give two different counts of devices.
|
|
400
|
+
* - `endurance-device-mix` (warning): a device has a converter with a limit `perDay` and a converter with no limit. The
|
|
401
|
+
* converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.
|
|
349
402
|
* - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.
|
|
350
403
|
* - `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.
|
|
351
404
|
*/
|
|
@@ -360,6 +413,8 @@ const ENDURANCE_CODES = [
|
|
|
360
413
|
"endurance-curve",
|
|
361
414
|
"endurance-prior-case",
|
|
362
415
|
"endurance-cycle",
|
|
416
|
+
"endurance-devices",
|
|
417
|
+
"endurance-device-mix",
|
|
363
418
|
"endurance-no-way",
|
|
364
419
|
"endurance-cut-no-curve"
|
|
365
420
|
];
|
|
@@ -444,6 +499,25 @@ function checkEndurance(layer, stack) {
|
|
|
444
499
|
if (made !== void 0) resource(converter.id, made);
|
|
445
500
|
if (!converter.takes.some((input) => input.amount > 0) || converter.gives.amount === 0) add("error", "endurance-converter-empty", converter.id, `The converter "${converter.id}" takes nothing, or it gives nothing.`);
|
|
446
501
|
part(converter.id, "device", converter.device);
|
|
502
|
+
if (converter.perDay !== void 0) range(converter.id, "rate perDay", converter.perDay);
|
|
503
|
+
if (converter.devices !== void 0 && !(Number.isSafeInteger(converter.devices) && converter.devices >= 1)) add("error", "endurance-range", converter.id, `The count of devices of "${converter.id}" is ${String(converter.devices)}. It must be a whole number of 1 or more.`);
|
|
504
|
+
}
|
|
505
|
+
const counts = /* @__PURE__ */ new Map();
|
|
506
|
+
for (const converter of converters) {
|
|
507
|
+
if (converter.device === void 0) continue;
|
|
508
|
+
const count = converter.devices ?? 1;
|
|
509
|
+
const seen = counts.get(converter.device);
|
|
510
|
+
if (seen !== void 0 && seen !== count) add("error", "endurance-devices", converter.id, `The converter "${converter.id}" gives the count ${String(count)} for the device "${converter.device}". An other converter gives the count ${String(seen)}.`);
|
|
511
|
+
if (seen === void 0) counts.set(converter.device, count);
|
|
512
|
+
}
|
|
513
|
+
const mixed = /* @__PURE__ */ new Set();
|
|
514
|
+
for (const converter of converters) {
|
|
515
|
+
const device = converter.device;
|
|
516
|
+
if (device === void 0 || converter.perDay !== void 0 || mixed.has(device)) continue;
|
|
517
|
+
const limited = converters.find((other) => other.device === device && other.perDay !== void 0);
|
|
518
|
+
if (limited === void 0) continue;
|
|
519
|
+
mixed.add(device);
|
|
520
|
+
add("warning", "endurance-device-mix", converter.id, `The device "${device}" has the limited converter "${limited.id}" and the converter "${converter.id}" with no limit. "${converter.id}" uses no device-days.`);
|
|
447
521
|
}
|
|
448
522
|
const caseCodes = new Set(cases.map((item) => item.case));
|
|
449
523
|
for (const item of cases) {
|
|
@@ -556,4 +630,4 @@ function joinEndurance(pieces) {
|
|
|
556
630
|
}
|
|
557
631
|
export { hasEnduranceError as a, drawDemand as c, giftResource as d, storeAmounts as f, curveFault as i, enduranceOf as l, ENDURANCE_CODES as n, caseDraws as o, checkEndurance as r, caseStopped as s, joinEndurance as t, giftNeed as u };
|
|
558
632
|
|
|
559
|
-
//# sourceMappingURL=join-
|
|
633
|
+
//# sourceMappingURL=join-Cglucg6Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-Cglucg6Q.js","names":["curveFault"],"sources":["../src/fit.ts","../src/endurance.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["/** The relative tolerance of a take and of a fit. */\nexport const TOLERANCE = 1e-13;\n\n/** One try of a fit: the amount that the stores could not give, out of the amount wanted, and the value of the try. */\nexport interface Try<T> {\n readonly short: number;\n readonly need: number;\n readonly value: T;\n}\n\n/** The result of a fit: the largest amount with no shortfall, and the value of its try. The value is `undefined` when only 0 fits. */\nexport interface Fit<T> {\n readonly x: number;\n readonly value: T | undefined;\n}\n\n/**\n * The count of the tries of `largestFit`, for the tests of the cost. It is not in the public API, and it does not change a result.\n * It is the one side effect of `largestFit` and of the queries that use it.\n */\nexport const fitTries = { count: 0 };\n\n/**\n * This function gives the largest `x` in `[0, most]` at which `attempt` has no shortfall, to the relative tolerance `TOLERANCE`.\n *\n * - A try fits when its shortfall is not more than `TOLERANCE` times its need.\n * - The shortfall must not decrease when `x` increases. A take of a chain of converters gives a shortfall that is linear in parts.\n * - The first try is `most`. After it, each step tries the zero of the line through the last two tries that do not fit.\n * With one try that does not fit, the step tries `x` times the part of the need that the stores gave.\n * - When a step does not halve the interval, the next step is a bisection. Thus a fit takes at most approximately twice the steps of a bisection.\n * - A step on the lower end tries a point just above it, so a correct estimate ends the fit in one more try.\n * - An estimate that fits with a shortfall above 0 is in the band of the tolerance above the zero, so the fit ends there.\n * A bisection step or a probe at the lower end can fit with a shortfall of rounding below the zero. The fit does not end there.\n *\n * @param most - The upper limit of `x`\n * @param attempt - The try at an amount. It must not change its input\n * @returns The largest amount that fits, and the value of its try\n */\nexport function largestFit<T>(most: number, attempt: (x: number) => Try<T>): Fit<T> {\n const fits = (tried: Try<T>): boolean => tried.short <= TOLERANCE * tried.need;\n fitTries.count += 1;\n const first = attempt(most);\n if (fits(first)) return { x: most, value: first.value };\n let low = 0;\n let best: T | undefined;\n let high = most;\n let highShort = first.short;\n let highNeed = first.need;\n let before: { readonly x: number; readonly short: number } | undefined;\n let bisect = false;\n for (let step = 0; step < 400 && high - low > 4 * TOLERANCE * high; step += 1) {\n const width = high - low;\n let x: number;\n if (bisect) x = (low + high) / 2;\n else if (before !== undefined && before.short > highShort) x = high - (highShort * (before.x - high)) / (before.short - highShort);\n else x = high * (1 - highShort / highNeed);\n // Only a secant or ratio estimate through tries that do not fit lands at or above the zero of a convex shortfall.\n const estimate = !bisect && x < high;\n if (!(x < high)) x = (low + high) / 2;\n const floor = low + 2 * TOLERANCE * high;\n const clamped = !(x > floor);\n if (clamped) x = floor;\n fitTries.count += 1;\n const tried = attempt(x);\n if (fits(tried)) {\n low = x;\n best = tried.value;\n // An estimate that fits with a shortfall is in the band of the tolerance above the zero, so the fit ends.\n if (tried.short > 0 && estimate && !clamped) break;\n } else {\n before = { x: high, short: highShort };\n high = x;\n highShort = tried.short;\n highNeed = tried.need;\n }\n bisect = !bisect && high - low > width / 2;\n }\n return { x: low, value: best };\n}\n","import { dayNumber, stopped, type Stack } from \"@mark1russell7/system-stack\";\nimport { largestFit, type Try } from \"./fit.ts\";\nimport type { CaseCuts, Converter, DirectUse, Draw, Endurance, EnduranceLayer, IsoDate } from \"./layer.ts\";\n\n// The endurance query: the days that each draw holds when a case stops its supply.\n\n/** The options of the queries of a case. */\nexport interface CaseOptions {\n /** The date of the query. A store whose due date is on this date or before it gives nothing. */\n readonly at: IsoDate;\n /** The base stack. With it, a cut also stops each part that cannot work without a cut part (`stopped` of the core). */\n readonly stack?: Stack | undefined;\n /** The `id` of more parts that are down, with the cuts of the case. */\n readonly down?: readonly string[] | undefined;\n}\n\n/**\n * This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.\n * With a stack, it also gives each part that stops.\n */\nexport function caseStopped(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): Set<string> {\n const down = [...caseCuts.cuts.map((cut) => cut.part), ...(options.down ?? [])];\n const out = new Set(down);\n if (options.stack !== undefined) for (const id of stopped(options.stack, down)) out.add(id);\n return out;\n}\n\n/** This function gives the day number of a date, or throws a `RangeError` for a date that is not `YYYY-MM-DD`. */\nfunction dayOf(date: IsoDate): number {\n const day = dayNumber(date);\n if (day === undefined) throw new RangeError(`The date \"${date}\" is not a date YYYY-MM-DD.`);\n return day;\n}\n\n/**\n * This function gives the amount of each resource in the stores at a date, by the code of the resource.\n *\n * - A store gives nothing on its due date and after it.\n * - A store gives nothing when its part is in `stoppedParts`.\n */\nexport function storeAmounts(layer: EnduranceLayer, at: IsoDate, stoppedParts: ReadonlySet<string> = new Set()): Map<string, number> {\n const today = dayOf(at);\n const out = new Map<string, number>();\n for (const store of layer.stores) {\n if (store.due !== undefined && today >= dayOf(store.due)) continue;\n if (store.part !== undefined && stoppedParts.has(store.part)) continue;\n out.set(store.resource, (out.get(store.resource) ?? 0) + store.amount);\n }\n return out;\n}\n\n/** This function gives the amount of a need for each day in a case: the rate of the draw times the factor of the case. */\nexport function drawDemand(draw: Draw, caseCuts: CaseCuts): number {\n return draw.perDay * (caseCuts.factors?.[draw.need] ?? 1);\n}\n\n/**\n * This function gives the draws that take from the stores in a case: each draw whose supply stops, with a demand more than 0.\n * The sequence is by the level (the order of `levels`), then by the code of the need.\n */\nexport function caseDraws(layer: EnduranceLayer, caseCuts: CaseCuts, stoppedParts: ReadonlySet<string>): Draw[] {\n const rank = (level: string): number => {\n const index = layer.levels.indexOf(level);\n return index < 0 ? layer.levels.length : index;\n };\n return layer.draws\n .filter((draw) => stoppedParts.has(draw.supply) && drawDemand(draw, caseCuts) > 0)\n .sort((a, b) => rank(a.level) - rank(b.level) || (a.need < b.need ? -1 : a.need > b.need ? 1 : 0));\n}\n\n/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */\nexport function giftNeed(converter: Converter): string | undefined {\n return \"need\" in converter.gives ? converter.gives.need : undefined;\n}\n\n/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */\nexport function giftResource(converter: Converter): string | undefined {\n return \"resource\" in converter.gives ? converter.gives.resource : undefined;\n}\n\n/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */\nfunction inputsOf(converter: Converter): Map<string, number> {\n const out = new Map<string, number>();\n for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);\n return out;\n}\n\n/** This function tells if a converter can run in a case. Its device works, it takes a resource, and it gives an amount more than 0. */\nfunction canRun(converter: Converter, stoppedParts: ReadonlySet<string>): boolean {\n return converter.gives.amount > 0 && inputsOf(converter).size > 0 && (converter.device === undefined || !stoppedParts.has(converter.device));\n}\n\n/** The converters of a case that make each resource, in the order of the layer, by the code of the resource. */\ntype Makers = ReadonlyMap<string, readonly Converter[]>;\n\nfunction makersOf(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): Makers {\n const out = new Map<string, Converter[]>();\n for (const converter of layer.converters ?? []) {\n const resource = giftResource(converter);\n if (resource === undefined || !canRun(converter, stoppedParts)) continue;\n out.set(resource, [...(out.get(resource) ?? []), converter]);\n }\n return out;\n}\n\n/** The ways to get one need in a case: its direct uses, then the converters that give it, in the order of the layer. `makers` make the resources. */\ninterface Ways {\n readonly direct: readonly DirectUse[];\n readonly converters: readonly Converter[];\n readonly makers: Makers;\n}\n\nfunction waysOf(layer: EnduranceLayer, need: string, stoppedParts: ReadonlySet<string>, makers: Makers): Ways {\n return {\n direct: (layer.direct ?? []).filter((use) => use.need === need && use.amount > 0),\n converters: (layer.converters ?? []).filter((converter) => giftNeed(converter) === need && canRun(converter, stoppedParts)),\n makers,\n };\n}\n\n// A chain: the resources on the path of a take. A maker does not take a resource of its own path, so a cycle of the layer stops there.\nconst NO_PATH: ReadonlySet<string> = new Set();\n\n// The device-days that are left to the converters with a limit `perDay` are in the map of the resources, under a key that\n// no code of a resource has. Thus each copy of the map in a try copies them too. The converters of one device share one\n// key, and a converter with no device has a key of its own. One run of a converter uses `1 / perDay` of a device-day.\nconst RUNS = \"\\u0000runs:\";\n\nfunction runsKey(converter: Converter): string {\n return converter.device === undefined ? `${RUNS}converter:${converter.id}` : `${RUNS}device:${converter.device}`;\n}\n\n/** This function gives the device-days that a converter has left in `left`, or undefined with no limit. */\nfunction daysLeft(left: ReadonlyMap<string, number>, converter: Converter): number | undefined {\n return converter.perDay === undefined ? undefined : left.get(runsKey(converter));\n}\n\n/** This function gives the map with no runs left of the converters: a map of the resources only. */\nfunction resourcesOnly(left: ReadonlyMap<string, number>): Map<string, number> {\n return new Map([...left].filter(([key]) => !key.startsWith(RUNS)));\n}\n\n/**\n * This function gives the most of a resource that `left` gives: its stock, and the runs of each maker.\n * It is an upper limit. When two inputs come from one resource, the true amount can be less.\n */\nfunction mostResource(left: ReadonlyMap<string, number>, makers: Makers, resource: string, path: ReadonlySet<string>): number {\n let total = left.get(resource) ?? 0;\n if (path.has(resource)) return total;\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) total += mostRuns(left, makers, maker, next) * maker.gives.amount;\n return total;\n}\n\n/** This function gives the most runs of a converter that `left` gives. It is an upper limit, as for `mostResource`. */\nfunction mostRuns(left: ReadonlyMap<string, number>, makers: Makers, converter: Converter, path: ReadonlySet<string>): number {\n const limit = daysLeft(left, converter);\n let runs = limit === undefined ? Infinity : limit * (converter.perDay ?? 0);\n for (const [resource, each] of inputsOf(converter)) runs = Math.min(runs, mostResource(left, makers, resource, path) / each);\n return Number.isFinite(runs) ? runs : 0;\n}\n\n/**\n * This function takes an amount of a resource from `left`: the stock first, then the makers in the order of the layer.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction takeResource(left: Map<string, number>, makers: Makers, resource: string, amount: number, path: ReadonlySet<string>): number {\n const has = left.get(resource) ?? 0;\n const got = Math.min(amount, has);\n left.set(resource, has - got);\n let rest = amount - got;\n if (rest <= 0 || path.has(resource)) return Math.max(0, rest);\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) {\n if (rest <= 0) break;\n rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/**\n * This function runs a converter up to `wanted` times with the resources of `left`, and it gives the count of runs.\n * It changes `left`. When two inputs come from one resource, `largestFit` finds the runs that the resources give.\n */\nfunction run(left: Map<string, number>, makers: Makers, converter: Converter, wanted: number, path: ReadonlySet<string>): number {\n const inputs = inputsOf(converter);\n const most = Math.min(wanted, mostRuns(left, makers, converter, path));\n if (!(most > 0)) return 0;\n const attempt = (runs: number): Try<Map<string, number>> => {\n const copy = new Map(left);\n let need = 0;\n let short = 0;\n // The converter takes its device-days before its inputs. Thus a maker on the same device gets only the rest.\n const limit = daysLeft(copy, converter);\n if (limit !== undefined && converter.perDay !== undefined && converter.perDay > 0) {\n const wanted = runs / converter.perDay;\n const got = Math.min(wanted, limit);\n copy.set(runsKey(converter), limit - got);\n need += runs;\n short += (wanted - got) * converter.perDay;\n }\n for (const [resource, each] of inputs) {\n need += runs * each;\n short += takeResource(copy, makers, resource, runs * each, path);\n }\n return { short, need, value: copy };\n };\n const { x: runs, value: best } = largestFit(most, attempt);\n if (best === undefined) return 0;\n for (const [resource, amount] of best) left.set(resource, amount);\n return runs;\n}\n\n/**\n * This function takes an amount of a need from the resources in `left`: the direct uses first, then the converters.\n * A direct use or a converter takes each resource from its stock first, then from its makers.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction take(left: Map<string, number>, ways: Ways, amount: number): number {\n let rest = amount;\n for (const use of ways.direct) {\n if (rest <= 0) break;\n const wanted = rest / use.amount;\n rest -= (wanted - takeResource(left, ways.makers, use.resource, wanted, NO_PATH)) * use.amount;\n }\n for (const converter of ways.converters) {\n if (rest <= 0) break;\n rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/** This function gives each resource that a need can use: the inputs of its ways, and the inputs of their makers, through each chain. */\nfunction inputClosure(ways: Ways): Set<string> {\n const out = new Set<string>();\n const queue = [...ways.direct.map((use) => use.resource), ...ways.converters.flatMap((converter) => [...inputsOf(converter).keys()])];\n for (let resource = queue.shift(); resource !== undefined; resource = queue.shift()) {\n if (out.has(resource)) continue;\n out.add(resource);\n for (const maker of ways.makers.get(resource) ?? []) queue.push(...inputsOf(maker).keys());\n }\n return out;\n}\n\n/** The relative tolerance of a used-up resource. */\nconst USED_UP = 1e-9;\n\n/**\n * This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.\n *\n * - A draw takes from the stores only when the case stops its supply part. Each other draw holds without end, and the result leaves it out.\n * - The demand of a draw for each day is its rate times the factor of the case.\n * - The draws take the resources in the order of their level, then of their codes. A draw takes from its direct uses first, then from its converters.\n * - The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.\n * - 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.\n * - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.\n * - A converter whose device stops gives nothing. A store whose part stops gives nothing.\n * - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.\n * - A converter with a limit `perDay` runs `perDay` times `devices` times `T` times or less in `T` days. The converters of one device share it.\n * - The higher draws use the runs of a limit first.\n * - A higher draw keeps back its runs of each day for all the days of a lower draw, also when its own days are fewer. This is the safe side.\n * - Two limited converters of one device can make the shortfall of a try decrease when the days increase. Then the fit can stop below the largest fit.\n * Each result is a real fit, so the days are on the safe side. A small change of a store can change the days by a large step.\n *\n * 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.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, and the stack or the parts that are also down\n * @returns The endurance of each draw whose supply stops\n */\nexport function enduranceOf(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions): Endurance {\n const stoppedParts = caseStopped(caseCuts, options);\n const start = storeAmounts(layer, options.at, stoppedParts);\n const makers = makersOf(layer, stoppedParts);\n const stocked = new Set(layer.stores.map((store) => store.resource));\n const limited = (layer.converters ?? []).filter((converter) => converter.perDay !== undefined && canRun(converter, stoppedParts));\n // The count of devices of each key. The gate refuses two counts for one device.\n const devices = new Map(limited.map((converter) => [runsKey(converter), converter.devices ?? 1]));\n // The device-days of each key in `days`: its devices less the device-days of each day of the higher draws, times the days.\n // A higher draw keeps back its device-days of each day for all the days, also after its own days end. This is the safe side.\n const giveRuns = (left: Map<string, number>, used: ReadonlyMap<string, number>, days: number): void => {\n for (const [key, count] of devices) left.set(key, Math.max(0, count - (used.get(key) ?? 0)) * days);\n };\n const done: { readonly ways: Ways; readonly demand: number; readonly days: number }[] = [];\n const needs: Record<string, { days: number; binding: string[]; takes: Record<string, number>; capped?: string[] }> = {};\n for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {\n const ways = waysOf(layer, draw.need, stoppedParts, makers);\n const demand = drawDemand(draw, caseCuts);\n let before = new Map(start);\n // Each higher draw takes again, in its own days. Its device-days of each day count against the lower draws.\n const used = new Map<string, number>();\n for (const higher of done) {\n giveRuns(before, used, higher.days);\n const given = new Map(before);\n take(before, higher.ways, higher.days * higher.demand);\n if (!(higher.days > 0)) continue;\n for (const key of devices.keys()) used.set(key, (used.get(key) ?? 0) + ((given.get(key) ?? 0) - (before.get(key) ?? 0)) / higher.days);\n }\n before = resourcesOnly(before);\n const after = (days: number): { left: Map<string, number>; short: number } => {\n const left = new Map(before);\n giveRuns(left, used, days);\n return { left, short: take(left, ways, days * demand) };\n };\n // The upper limit: the days that the draw holds when it takes all the stores itself. `largestFit` finds the days below it.\n const fit = largestFit(capacity(start, ways) / demand, (days) => {\n const tried = after(days);\n return { short: tried.short, need: days * demand, value: tried.left };\n });\n const low = fit.x;\n const left = fit.value ?? after(low).left;\n // The binding resources are of the stores only: a used-up limit of runs is in `capped`, not here.\n const stores = resourcesOnly(left);\n const binding = [...inputClosure(ways)]\n .filter((resource) => !makers.has(resource) || stocked.has(resource))\n .filter((resource) => mostResource(stores, makers, resource, NO_PATH) <= USED_UP * Math.max(1, start.get(resource) ?? 0))\n .sort();\n const takes: Record<string, number> = {};\n for (const [resource, amount] of before) {\n const taken = amount - (left.get(resource) ?? 0);\n if (taken > 0) takes[resource] = taken;\n }\n // A limit stops the draw when its limit gives the converter no runs left, and its inputs give more runs.\n // The runs left are the device-days left times `perDay`. Thus a limit of 0 stops the draw, also with its device-days left.\n const reach = new Set([...ways.converters, ...[...inputClosure(ways)].flatMap((resource) => makers.get(resource) ?? [])]);\n const runsLeft = (converter: Converter): number => (daysLeft(left, converter) ?? 0) * (converter.perDay ?? 0);\n const runsGiven = (converter: Converter): number => (devices.get(runsKey(converter)) ?? 1) * (converter.perDay ?? 0) * low;\n const capped = limited\n .filter((converter) => reach.has(converter))\n .filter((converter) => runsLeft(converter) <= USED_UP * Math.max(1, runsGiven(converter)))\n .filter((converter) => mostRuns(stores, makers, converter, NO_PATH) > USED_UP)\n .map((converter) => converter.id)\n .sort();\n needs[draw.need] = capped.length === 0 ? { days: low, binding, takes } : { days: low, binding, takes, capped };\n done.push({ ways, demand, days: low });\n }\n return { case: caseCuts.case, at: options.at, needs };\n}\n\n/**\n * This function gives an upper limit of a need that the stores give with no other draw, through each chain.\n * A converter that takes nothing gives nothing: the gate refuses it.\n */\nfunction capacity(start: ReadonlyMap<string, number>, ways: Ways): number {\n let total = 0;\n for (const use of ways.direct) total += mostResource(start, ways.makers, use.resource, NO_PATH) * use.amount;\n for (const converter of ways.converters) total += mostRuns(start, ways.makers, converter, NO_PATH) * converter.gives.amount;\n return total;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { curveFault, dayNumber, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./endurance.ts\";\nimport type { Converter, EnduranceLayer } from \"./layer.ts\";\n\n// The gate of an endurance layer: the meaning of a layer with a correct form, for its base stack.\n\n/**\n * These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.\n *\n * - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.\n * The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.\n * - `endurance-level-unknown`: the level of a draw is not a level of the layer.\n * - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.\n * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.\n * - `endurance-range`: an amount, a rate, a count or a factor is not a finite number of 0 or more. Or a reach is not from 0 to 1.\n * - `endurance-date`: a date is not a date `YYYY-MM-DD`.\n * - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.\n * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.\n * Or its days do not increase, or its chance increases.\n * - `endurance-prior-case`: a prior names a case that the layer does not have.\n * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.\n * - `endurance-devices`: two converters of one device give two different counts of devices.\n * - `endurance-device-mix` (warning): a device has a converter with a limit `perDay` and a converter with no limit. The\n * converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.\n * - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.\n * - `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.\n */\nexport const ENDURANCE_CODES: readonly [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n] = [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n];\n\n/** A code of `ENDURANCE_CODES`. */\nexport type EnduranceCode = (typeof ENDURANCE_CODES)[number];\n\n/** A fault of the gate of an endurance layer. */\nexport interface EnduranceFault extends Fault {\n readonly code: EnduranceCode;\n}\n\nexport { curveFault } from \"@mark1russell7/system-stack\";\n\n/**\n * This function gives each fault of an endurance layer. With a base stack, it also examines the `id` of each part. A list with no error tells that the gate passes.\n *\n * The faults are in the order of the layer. The function is pure.\n *\n * @param layer - The endurance layer\n * @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.\n * @returns The faults\n */\nexport function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[] {\n const faults: EnduranceFault[] = [];\n const add = (level: EnduranceFault[\"level\"], code: EnduranceCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const once = (what: string, keys: readonly string[]): void => {\n const seen = new Set<string>();\n for (const key of keys) {\n if (seen.has(key)) add(\"error\", \"endurance-twice\", key, `Two or more ${what} have the key \"${key}\".`);\n seen.add(key);\n }\n };\n const range = (at: string, what: string, value: number): void => {\n if (!(Number.isFinite(value) && value >= 0)) add(\"error\", \"endurance-range\", at, `The ${what} of \"${at}\" is ${String(value)}. It must be a finite number of 0 or more.`);\n };\n const date = (at: string, value: string): void => {\n if (dayNumber(value) === undefined) add(\"error\", \"endurance-date\", at, `The date \"${value}\" of \"${at}\" is not a date YYYY-MM-DD.`);\n };\n const parts = stack === undefined ? undefined : new Set(stack.parts.map((part) => part.id));\n const part = (at: string, what: string, id: string | undefined): void => {\n if (parts !== undefined && id !== undefined && !parts.has(id)) add(\"error\", \"endurance-part-unknown\", at, `The ${what} \"${id}\" of \"${at}\" is not a part of the stack.`);\n };\n const resources = new Set(layer.resources.map((resource) => resource.code));\n const resource = (at: string, code: string): void => {\n if (!resources.has(code)) add(\"error\", \"endurance-resource-unknown\", at, `The resource \"${code}\" of \"${at}\" is not a resource of the layer.`);\n };\n const direct = layer.direct ?? [];\n const converters = layer.converters ?? [];\n const cases = layer.cases ?? [];\n const priors = layer.priors ?? [];\n\n once(\"levels\", layer.levels);\n once(\"resources\", layer.resources.map((item) => item.code));\n once(\"stores\", layer.stores.map((store) => store.id));\n once(\"draws\", layer.draws.map((draw) => draw.need));\n once(\"converters\", converters.map((converter) => converter.id));\n once(\"cases\", cases.map((item) => item.case));\n once(\"priors\", priors.map((prior) => `${prior.case}@${prior.place}`));\n\n for (const store of layer.stores) {\n resource(store.id, store.resource);\n range(store.id, \"amount\", store.amount);\n if (store.due !== undefined) date(store.id, store.due);\n part(store.id, \"part\", store.part);\n }\n const levels = new Set(layer.levels);\n for (const draw of layer.draws) {\n if (!levels.has(draw.level)) add(\"error\", \"endurance-level-unknown\", draw.need, `The level \"${draw.level}\" of the draw \"${draw.need}\" is not a level of the layer.`);\n range(draw.need, \"rate\", draw.perDay);\n if (draw.users !== undefined) range(draw.need, \"count of users\", draw.users);\n part(draw.need, \"supply\", draw.supply);\n const ways = direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need);\n if (!ways) add(\"warning\", \"endurance-no-way\", draw.need, `The draw \"${draw.need}\" has no direct use and no converter. It holds 0 days when its supply stops.`);\n }\n for (const use of direct) {\n const at = `${use.resource}>${use.need}`;\n resource(at, use.resource);\n range(at, \"amount\", use.amount);\n }\n for (const converter of converters) {\n once(`resources of the converter \"${converter.id}\"`, converter.takes.map((input) => input.resource));\n for (const input of converter.takes) {\n resource(converter.id, input.resource);\n range(converter.id, \"amount\", input.amount);\n }\n range(converter.id, \"amount\", converter.gives.amount);\n const made = giftResource(converter);\n if (made !== undefined) resource(converter.id, made);\n if (!converter.takes.some((input) => input.amount > 0) || converter.gives.amount === 0) add(\"error\", \"endurance-converter-empty\", converter.id, `The converter \"${converter.id}\" takes nothing, or it gives nothing.`);\n part(converter.id, \"device\", converter.device);\n if (converter.perDay !== undefined) range(converter.id, \"rate perDay\", converter.perDay);\n if (converter.devices !== undefined && !(Number.isSafeInteger(converter.devices) && converter.devices >= 1))\n add(\"error\", \"endurance-range\", converter.id, `The count of devices of \"${converter.id}\" is ${String(converter.devices)}. It must be a whole number of 1 or more.`);\n }\n const counts = new Map<string, number>();\n for (const converter of converters) {\n if (converter.device === undefined) continue;\n const count = converter.devices ?? 1;\n const seen = counts.get(converter.device);\n if (seen !== undefined && seen !== count)\n add(\"error\", \"endurance-devices\", converter.id, `The converter \"${converter.id}\" gives the count ${String(count)} for the device \"${converter.device}\". An other converter gives the count ${String(seen)}.`);\n if (seen === undefined) counts.set(converter.device, count);\n }\n // One fault names each device with a limited converter and a converter with no limit, at the first converter with no limit.\n const mixed = new Set<string>();\n for (const converter of converters) {\n const device = converter.device;\n if (device === undefined || converter.perDay !== undefined || mixed.has(device)) continue;\n const limited = converters.find((other) => other.device === device && other.perDay !== undefined);\n if (limited === undefined) continue;\n mixed.add(device);\n add(\"warning\", \"endurance-device-mix\", converter.id, `The device \"${device}\" has the limited converter \"${limited.id}\" and the converter \"${converter.id}\" with no limit. \"${converter.id}\" uses no device-days.`);\n }\n const caseCodes = new Set(cases.map((item) => item.case));\n for (const item of cases) {\n once(`cuts of the case \"${item.case}\"`, item.cuts.map((cut) => cut.part));\n for (const cut of item.cuts) {\n const at = `${item.case}/${cut.part}`;\n part(at, \"cut\", cut.part);\n if (cut.duration === undefined) {\n add(\"warning\", \"endurance-cut-no-curve\", at, `The cut \"${at}\" has no curve of its duration, so the draws that it can stop are no read.`);\n continue;\n }\n const fault = curveFault(cut.duration);\n if (fault !== undefined) add(\"error\", \"endurance-curve\", at, `The duration of the cut \"${at}\": ${fault}`);\n }\n for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, \"factor\", factor);\n if (item.leadSeconds !== undefined) range(item.case, \"lead time\", item.leadSeconds);\n }\n for (const cycle of resourceCycles(converters)) {\n const [first = \"\"] = cycle;\n const names = cycle.map((code) => `\"${code}\"`).join(\", \");\n const message = cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`;\n add(\"error\", \"endurance-cycle\", first, `${message} A chain of converters cannot end.`);\n }\n for (const prior of priors) {\n const at = `${prior.case}@${prior.place}`;\n if (!caseCodes.has(prior.case)) add(\"error\", \"endurance-prior-case\", at, `The prior \"${at}\" names the case \"${prior.case}\", which the layer does not have.`);\n range(at, \"count of events in one year\", prior.perYear);\n if (!(prior.reach >= 0 && prior.reach <= 1)) add(\"error\", \"endurance-range\", at, `The reach of \"${at}\" is ${String(prior.reach)}. It must be from 0 to 1.`);\n date(at, prior.asOf);\n }\n return faults;\n}\n\n/** This function gives each cycle of resources: a resource is made from a resource that a converter makes from it. Each cycle is a list of codes. */\nfunction resourceCycles(converters: readonly Converter[]): string[][] {\n const from = new Map<string, Set<string>>();\n for (const converter of converters) {\n const made = giftResource(converter);\n if (made === undefined) continue;\n const inputs = from.get(made) ?? new Set<string>();\n for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);\n from.set(made, inputs);\n }\n const successors = (code: string): Iterable<string> => from.get(code) ?? [];\n return stronglyConnectedComponents(from.keys(), successors).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (from.get(only)?.has(only) ?? false);\n });\n}\n\n/** This function tells if a list of faults has an error. */\nexport function hasEnduranceError(faults: readonly EnduranceFault[]): boolean {\n return faults.some((fault) => fault.level === \"error\");\n}\n","import { canonicalJson } from \"@mark1russell7/rigor-generators\";\nimport { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The join of the endurance layers of the fragments of a stack, for example one file of stores for each owner.\n\n/**\n * This function joins the endurance layers of the fragments of a stack into one layer.\n *\n * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.\n * - The records of each list are in the order of the fragments.\n * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.\n * Its message gives the canonical JSON of the record of each fragment.\n * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.\n * - One key of each other list in two or more fragments is a fault, also when the records are equal.\n * - The key of a direct use is its resource and its need.\n *\n * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer> {\n const levels = joinSetting(pieces, (layer) => (layer.levels.length > 0 ? layer.levels.join(\"\\n\") : undefined), \"levels\");\n // Two fragments can declare one resource, for example `water.stored` in `L`. Canonical JSON (RFC 8785) compares the records,\n // so the order of the keys has no effect. The message of a fault gives the canonical JSON of the record of each fragment.\n const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\", {\n equal: (first, other) => canonicalJson(first) === canonicalJson(other),\n text: canonicalJson,\n });\n const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, \"store\");\n const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, \"draw\");\n const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, \"direct use\");\n const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, \"converter\");\n const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, \"case\");\n const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, \"prior\");\n const errors = [levels, resources, stores, draws, direct, converters, cases, priors].flatMap((join) => join.errors);\n if (errors.length > 0) return { ok: false, errors };\n const has = (key: \"direct\" | \"converters\" | \"cases\" | \"priors\"): boolean => pieces.some((piece) => piece.layer[key] !== undefined);\n return {\n ok: true,\n layer: {\n schema: ENDURANCE_SCHEMA,\n levels: levels.value === undefined ? [] : levels.value.split(\"\\n\"),\n resources: resources.items,\n stores: stores.items,\n draws: draws.items,\n ...(has(\"direct\") ? { direct: direct.items } : {}),\n ...(has(\"converters\") ? { converters: converters.items } : {}),\n ...(has(\"cases\") ? { cases: cases.items } : {}),\n ...(has(\"priors\") ? { priors: priors.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;;AACA,MAAa,YAAY;;;;;AAmBzB,MAAa,WAAW,EAAE,OAAO,EAAE;;;;;;;;;;;;;;;;;AAkBnC,SAAgB,WAAc,MAAc,SAAwC;CAClF,MAAM,QAAQ,UAA2B,MAAM,SAAS,YAAY,MAAM;CAC1E,SAAS,SAAS;CAClB,MAAM,QAAQ,QAAQ,IAAI;CAC1B,IAAI,KAAK,KAAK,GAAG,OAAO;EAAE,GAAG;EAAM,OAAO,MAAM;CAAM;CACtD,IAAI,MAAM;CACV,IAAI;CACJ,IAAI,OAAO;C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the resource that one run gives, and its amount. A chain of converters cannot make a resource from itself. */
|
|
71
71
|
readonly gives: Gift;
|
|
72
|
+
/**
|
|
73
|
+
* The most runs of one device in a day, for example the pots that one stove cooks in a day. It is a cited fact of the
|
|
74
|
+
* device. With no `perDay`, the runs have no limit for each day.
|
|
75
|
+
*
|
|
76
|
+
* The converters of one `device` share its days. One run uses `1 / perDay` of a day of one device. Thus a stove with
|
|
77
|
+
* a converter for rice and a converter for beans does not cook more pots in a day than its limits give.
|
|
78
|
+
*
|
|
79
|
+
* The limit is a rate, not a store. Over `T` days, the converter runs `perDay` times `devices` times `T` times or
|
|
80
|
+
* less. The higher draws use the runs first. Each higher draw keeps back its runs of each day for all the days of a
|
|
81
|
+
* lower draw. A draw that the limit stops gets the rest of its need from its other ways. When they cannot give it, the
|
|
82
|
+
* draw falls short, also when the stores of the converter have more.
|
|
83
|
+
*/
|
|
84
|
+
readonly perDay?: number | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The count of devices of the converter, a whole number of 1 or more. The default is 1. It has an effect only with
|
|
87
|
+
* `perDay`. The converters of one `device` give one count. When the part `device` stops, all the devices stop.
|
|
88
|
+
*/
|
|
89
|
+
readonly devices?: number | undefined;
|
|
72
90
|
}
|
|
73
91
|
/** The days that one draw holds, and the resources that are used up at that time. */
|
|
74
92
|
interface DrawEndurance {
|
|
@@ -80,6 +98,14 @@ interface DrawEndurance {
|
|
|
80
98
|
readonly binding: readonly string[];
|
|
81
99
|
/** The amount of each resource that the draw takes in its days, by the code of the resource. A resource with no take is not in the record. */
|
|
82
100
|
readonly takes: Readonly<Record<string, number>>;
|
|
101
|
+
/**
|
|
102
|
+
* The converters whose limit `perDay` stops the draw at `days`, while their inputs have more, in the order of their
|
|
103
|
+
* `id`. The record has no field `capped` when no limit stops the draw.
|
|
104
|
+
*
|
|
105
|
+
* After `days`, such a draw can still get a part of its need at the rate of the limit. The shortfall counts each of
|
|
106
|
+
* those days as a full shortfall. This is the safe side for a plan.
|
|
107
|
+
*/
|
|
108
|
+
readonly capped?: readonly string[] | undefined;
|
|
83
109
|
}
|
|
84
110
|
/** The days that each draw holds when a case stops its supply. A draw whose supply works is not in `needs`. */
|
|
85
111
|
interface Endurance {
|
|
@@ -102,4 +128,4 @@ interface EnduranceLayer {
|
|
|
102
128
|
readonly priors?: readonly Prior$1[] | undefined;
|
|
103
129
|
}
|
|
104
130
|
export { Draw as a, Endurance as c, IsoDate as d, Prior as f, Survival as h, DirectUse as i, EnduranceLayer as l, Store as m, Converter as n, DrawEndurance as o, Resource as p, Cut as r, ENDURANCE_SCHEMA as s, CaseCuts as t, Gift as u };
|
|
105
|
-
//# sourceMappingURL=layer-
|
|
131
|
+
//# sourceMappingURL=layer-CF0r-9ww.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-CF0r-9ww.d.ts","names":["CaseCuts","Prior"],"sources":["../src/layer.ts"],"mappings":";;cAQa;;KAGD;;UAGK;WACN;WACA;;;UAIM;WACN;;WAEA;;WAEA;;WAEA,MAAM;;WAEN;;;;;;;UAQM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;WACN;WACA;WACA;;;KAIC;WAAkB;WAAuB;WAA2B;;WAA8B;WAA2B;WAAuB;;;;;;;UAO/I;WACN;;WAEA;;WAEA;aAA2B;aAA2B;;;WAEtD,OAAO;;;;;;;;;;;;;WAaP;;;;;WAKA;;;UAOM;WACN;;;;;WAKA;;WAEA,OAAO,SAAS;;;;;;;;WAQhB;;;UAIM;WACN;WACA,IAAI;;WAEJ,OAAO,SAAS,eAAe;;;UAIzB;WACN,eAAe;;WAEf;WACA,oBAAoB;WACpB,iBAAiB;WACjB,gBAAgB;WAChB,kBAAkB;WAClB,sBAAsB;WACtB,iBAAiBA;WACjB,kBAAkBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-a3Fr70Uh.js","names":[],"sources":["../src/layer.ts"],"sourcesContent":["// The records of the endurance add-on. They are one layer of a stack, with the key `endurance/1` in `Stack.layers`.\n// A store holds an amount of a resource. A draw takes a need each day. A converter changes resources into a need.\n// A case cuts some parts for a time. The queries give the days that each draw holds, and the days that it does not get its need.\n// The add-on names no topic: the resources, the needs and the levels are data. The unit of time is the day.\n\nimport type { CaseCuts, Prior } from \"@mark1russell7/system-stack\";\n\n/** The name of the format of an endurance layer. It is the key of the layer in `Stack.layers`. */\nexport const ENDURANCE_SCHEMA = \"endurance/1\";\n\n/** A date as `YYYY-MM-DD`. */\nexport type IsoDate = string;\n\n/** A resource of a store, with its unit, for example `L`, `kg` or `Wh`. */\nexport interface Resource {\n readonly code: string;\n readonly unit: string;\n}\n\n/** A store: an amount of one resource. */\nexport interface Store {\n readonly id: string;\n /** The `code` of the resource. */\n readonly resource: string;\n /** The amount, in the unit of the resource. */\n readonly amount: number;\n /** The due date. On this date and after it, the store gives nothing. A store with no due date does not expire. */\n readonly due?: IsoDate | undefined;\n /** The `id` of the part of the stack that holds the store. When the part stops, the store gives nothing. */\n readonly part?: string | undefined;\n}\n\n/**\n * A draw: a need that a load takes each day from its supply.\n * Examples are the power of a rack and the drinking water of a building.\n * When the supply part stops, the draw takes the need from the stores.\n */\nexport interface Draw {\n /** The code of the need. One draw has each code. */\n readonly need: string;\n /** The level of the draw. It is one of the `levels` of the layer. */\n readonly level: string;\n /** The amount of the need for each day. */\n readonly perDay: number;\n /** The count of the users of the draw, for example the persons or the machines. The shortfall counts each user. The default is 1. */\n readonly users?: number | undefined;\n /** The `id` of the part of the stack that supplies the need when no case stops it. */\n readonly supply: string;\n}\n\n/** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */\nexport interface DirectUse {\n readonly resource: string;\n readonly need: string;\n readonly amount: number;\n}\n\n/** The gift of one run of a converter: an amount of a need, or an amount of a resource, in its unit. */\nexport type Gift = { readonly need: string; readonly resource?: never; readonly amount: number } | { readonly resource: string; readonly need?: never; readonly amount: number };\n\n/**\n * A converter: a device or an action that changes resources into a need or into a resource.\n * Example: a stove cooks 1 kg of dry rice with 2 L of water and 0.05 kg of fuel, and gives 3600 kcal.\n * Example: a generator changes 1 L of fuel into 3000 Wh of the battery. Then a direct use of the battery can take that energy.\n */\nexport interface Converter {\n readonly id: string;\n /** The `id` of the device in the stack. The converter stops when the device stops. */\n readonly device?: string | undefined;\n /** The resources that one run takes. */\n readonly takes: readonly { readonly resource: string; readonly amount: number }[];\n /** The need or the resource that one run gives, and its amount. A chain of converters cannot make a resource from itself. */\n readonly gives: Gift;\n}\n\n// The core holds the records of the cuts of a case, so that each add-on shares them. This entry gives them again.\nexport type { CaseCuts, Cut, Prior, Survival } from \"@mark1russell7/system-stack\";\n\n/** The days that one draw holds, and the resources that are used up at that time. */\nexport interface DrawEndurance {\n readonly days: number;\n /**\n * The inputs of the draw that are used up at `days`, through each chain of converters, in the order of their codes. A higher draw can use up an input first.\n * A resource that only converters make, with no store of the layer, is not in the list.\n */\n readonly binding: readonly string[];\n /** The amount of each resource that the draw takes in its days, by the code of the resource. A resource with no take is not in the record. */\n readonly takes: Readonly<Record<string, number>>;\n}\n\n/** The days that each draw holds when a case stops its supply. A draw whose supply works is not in `needs`. */\nexport interface Endurance {\n readonly case: string;\n readonly at: IsoDate;\n /** The result of each draw, by the code of its need. */\n readonly needs: Readonly<Record<string, DrawEndurance>>;\n}\n\n/** An endurance layer: the levels, the resources, the stores, the draws, the uses and the converters, the cases and their priors. */\nexport interface EnduranceLayer {\n readonly schema: typeof ENDURANCE_SCHEMA;\n /** The levels of the draws, the most important first, for example `[\"critical\", \"normal\"]`. A higher level takes the resources first. */\n readonly levels: readonly string[];\n readonly resources: readonly Resource[];\n readonly stores: readonly Store[];\n readonly draws: readonly Draw[];\n readonly direct?: readonly DirectUse[] | undefined;\n readonly converters?: readonly Converter[] | undefined;\n readonly cases?: readonly CaseCuts[] | undefined;\n readonly priors?: readonly Prior[] | undefined;\n}\n"],"mappings":";;AAQA,MAAa,mBAAmB"}
|
|
1
|
+
{"version":3,"file":"layer-a3Fr70Uh.js","names":[],"sources":["../src/layer.ts"],"sourcesContent":["// The records of the endurance add-on. They are one layer of a stack, with the key `endurance/1` in `Stack.layers`.\n// A store holds an amount of a resource. A draw takes a need each day. A converter changes resources into a need.\n// A case cuts some parts for a time. The queries give the days that each draw holds, and the days that it does not get its need.\n// The add-on names no topic: the resources, the needs and the levels are data. The unit of time is the day.\n\nimport type { CaseCuts, Prior } from \"@mark1russell7/system-stack\";\n\n/** The name of the format of an endurance layer. It is the key of the layer in `Stack.layers`. */\nexport const ENDURANCE_SCHEMA = \"endurance/1\";\n\n/** A date as `YYYY-MM-DD`. */\nexport type IsoDate = string;\n\n/** A resource of a store, with its unit, for example `L`, `kg` or `Wh`. */\nexport interface Resource {\n readonly code: string;\n readonly unit: string;\n}\n\n/** A store: an amount of one resource. */\nexport interface Store {\n readonly id: string;\n /** The `code` of the resource. */\n readonly resource: string;\n /** The amount, in the unit of the resource. */\n readonly amount: number;\n /** The due date. On this date and after it, the store gives nothing. A store with no due date does not expire. */\n readonly due?: IsoDate | undefined;\n /** The `id` of the part of the stack that holds the store. When the part stops, the store gives nothing. */\n readonly part?: string | undefined;\n}\n\n/**\n * A draw: a need that a load takes each day from its supply.\n * Examples are the power of a rack and the drinking water of a building.\n * When the supply part stops, the draw takes the need from the stores.\n */\nexport interface Draw {\n /** The code of the need. One draw has each code. */\n readonly need: string;\n /** The level of the draw. It is one of the `levels` of the layer. */\n readonly level: string;\n /** The amount of the need for each day. */\n readonly perDay: number;\n /** The count of the users of the draw, for example the persons or the machines. The shortfall counts each user. The default is 1. */\n readonly users?: number | undefined;\n /** The `id` of the part of the stack that supplies the need when no case stops it. */\n readonly supply: string;\n}\n\n/** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */\nexport interface DirectUse {\n readonly resource: string;\n readonly need: string;\n readonly amount: number;\n}\n\n/** The gift of one run of a converter: an amount of a need, or an amount of a resource, in its unit. */\nexport type Gift = { readonly need: string; readonly resource?: never; readonly amount: number } | { readonly resource: string; readonly need?: never; readonly amount: number };\n\n/**\n * A converter: a device or an action that changes resources into a need or into a resource.\n * Example: a stove cooks 1 kg of dry rice with 2 L of water and 0.05 kg of fuel, and gives 3600 kcal.\n * Example: a generator changes 1 L of fuel into 3000 Wh of the battery. Then a direct use of the battery can take that energy.\n */\nexport interface Converter {\n readonly id: string;\n /** The `id` of the device in the stack. The converter stops when the device stops. */\n readonly device?: string | undefined;\n /** The resources that one run takes. */\n readonly takes: readonly { readonly resource: string; readonly amount: number }[];\n /** The need or the resource that one run gives, and its amount. A chain of converters cannot make a resource from itself. */\n readonly gives: Gift;\n /**\n * The most runs of one device in a day, for example the pots that one stove cooks in a day. It is a cited fact of the\n * device. With no `perDay`, the runs have no limit for each day.\n *\n * The converters of one `device` share its days. One run uses `1 / perDay` of a day of one device. Thus a stove with\n * a converter for rice and a converter for beans does not cook more pots in a day than its limits give.\n *\n * The limit is a rate, not a store. Over `T` days, the converter runs `perDay` times `devices` times `T` times or\n * less. The higher draws use the runs first. Each higher draw keeps back its runs of each day for all the days of a\n * lower draw. A draw that the limit stops gets the rest of its need from its other ways. When they cannot give it, the\n * draw falls short, also when the stores of the converter have more.\n */\n readonly perDay?: number | undefined;\n /**\n * The count of devices of the converter, a whole number of 1 or more. The default is 1. It has an effect only with\n * `perDay`. The converters of one `device` give one count. When the part `device` stops, all the devices stop.\n */\n readonly devices?: number | undefined;\n}\n\n// The core holds the records of the cuts of a case, so that each add-on shares them. This entry gives them again.\nexport type { CaseCuts, Cut, Prior, Survival } from \"@mark1russell7/system-stack\";\n\n/** The days that one draw holds, and the resources that are used up at that time. */\nexport interface DrawEndurance {\n readonly days: number;\n /**\n * The inputs of the draw that are used up at `days`, through each chain of converters, in the order of their codes. A higher draw can use up an input first.\n * A resource that only converters make, with no store of the layer, is not in the list.\n */\n readonly binding: readonly string[];\n /** The amount of each resource that the draw takes in its days, by the code of the resource. A resource with no take is not in the record. */\n readonly takes: Readonly<Record<string, number>>;\n /**\n * The converters whose limit `perDay` stops the draw at `days`, while their inputs have more, in the order of their\n * `id`. The record has no field `capped` when no limit stops the draw.\n *\n * After `days`, such a draw can still get a part of its need at the rate of the limit. The shortfall counts each of\n * those days as a full shortfall. This is the safe side for a plan.\n */\n readonly capped?: readonly string[] | undefined;\n}\n\n/** The days that each draw holds when a case stops its supply. A draw whose supply works is not in `needs`. */\nexport interface Endurance {\n readonly case: string;\n readonly at: IsoDate;\n /** The result of each draw, by the code of its need. */\n readonly needs: Readonly<Record<string, DrawEndurance>>;\n}\n\n/** An endurance layer: the levels, the resources, the stores, the draws, the uses and the converters, the cases and their priors. */\nexport interface EnduranceLayer {\n readonly schema: typeof ENDURANCE_SCHEMA;\n /** The levels of the draws, the most important first, for example `[\"critical\", \"normal\"]`. A higher level takes the resources first. */\n readonly levels: readonly string[];\n readonly resources: readonly Resource[];\n readonly stores: readonly Store[];\n readonly draws: readonly Draw[];\n readonly direct?: readonly DirectUse[] | undefined;\n readonly converters?: readonly Converter[] | undefined;\n readonly cases?: readonly CaseCuts[] | undefined;\n readonly priors?: readonly Prior[] | undefined;\n}\n"],"mappings":";;AAQA,MAAa,mBAAmB"}
|
package/build/schema.d.ts
CHANGED
package/build/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;qBAqEa,iBAAiB,EAAE,QAAQ;;YAa5B;WAA4B;WAAmB,OAAO;;WAA8B;WAAoB;;;;;;wBAMpG,eAAe,iBAAiB"}
|
package/build/schema.js
CHANGED
|
@@ -40,7 +40,9 @@ const converter = z.strictObject({
|
|
|
40
40
|
}), z.strictObject({
|
|
41
41
|
resource: id,
|
|
42
42
|
amount
|
|
43
|
-
})])
|
|
43
|
+
})]),
|
|
44
|
+
perDay: amount.optional(),
|
|
45
|
+
devices: amount.optional()
|
|
44
46
|
});
|
|
45
47
|
const point = z.tuple([z.number(), z.number()]).readonly();
|
|
46
48
|
const cut = z.strictObject({
|
package/build/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { formErrors } from \"@mark1russell7/system-stack/schema\";\nimport { z } from \"zod\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The zod schema of an endurance layer and the read of its JSON. This module is the entry `/schema` of the package.\n// The root entry has no zod, so a host that only calculates gets no schema library.\n\nconst id = z.string().min(1);\nconst amount = z.number();\n\nconst resource = z.strictObject({ code: id, unit: id });\n\nconst store = z.strictObject({\n id,\n resource: id,\n amount,\n due: id.optional(),\n part: id.optional(),\n});\n\nconst draw = z.strictObject({\n need: id,\n level: id,\n perDay: amount,\n users: amount.optional(),\n supply: id,\n});\n\nconst directUse = z.strictObject({ resource: id, need: id, amount });\n\nconst converter = z.strictObject({\n id,\n device: id.optional(),\n takes: z.array(z.strictObject({ resource: id, amount })).readonly(),\n gives: z.union([z.strictObject({ need: id, amount }), z.strictObject({ resource: id, amount })]),\n});\n\nconst point = z.tuple([z.number(), z.number()]).readonly();\n\nconst cut = z.strictObject({\n part: id,\n title: id,\n duration: z.array(point).readonly().optional(),\n source: id,\n});\n\nconst caseCuts = z.strictObject({\n case: id,\n title: id,\n cuts: z.array(cut).readonly(),\n factors: z.record(z.string(), amount).optional(),\n leadSeconds: amount.optional(),\n});\n\nconst prior = z.strictObject({\n case: id,\n place: id,\n perYear: amount,\n reach: amount,\n source: id,\n asOf: id,\n});\n\n/**\n * The schema of an endurance layer. It examines the form of the record: the fields and their types.\n * It refuses a field that the format does not have. `checkEndurance` examines the meaning of a layer with a correct form.\n */\nexport const enduranceSchema: z.ZodType<EnduranceLayer> = z.strictObject({\n schema: z.literal(ENDURANCE_SCHEMA),\n levels: z.array(id).readonly(),\n resources: z.array(resource).readonly(),\n stores: z.array(store).readonly(),\n draws: z.array(draw).readonly(),\n direct: z.array(directUse).readonly().optional(),\n converters: z.array(converter).readonly().optional(),\n cases: z.array(caseCuts).readonly().optional(),\n priors: z.array(prior).readonly().optional(),\n});\n\n/** The result of the read of an endurance layer: the layer, or the faults of its form. */\nexport type EnduranceParse = { readonly ok: true; readonly layer: EnduranceLayer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of an endurance layer. It gives the layer, or the faults of its form.\n * Each fault names its place in the record, for example `stores.0.amount`.\n */\nexport function parseEndurance(input: unknown): EnduranceParse {\n const read = enduranceSchema.safeParse(input);\n if (read.success) return { ok: true, layer: read.data };\n return { ok: false, errors: formErrors(ENDURANCE_SCHEMA, read.error.issues) };\n}\n"],"mappings":";;;;AAOA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC3B,MAAM,SAAS,EAAE,OAAO;AAExB,MAAM,WAAW,EAAE,aAAa;CAAE,MAAM;CAAI,MAAM;AAAG,CAAC;AAEtD,MAAM,QAAQ,EAAE,aAAa;CAC3B;CACA,UAAU;CACV;CACA,KAAK,GAAG,SAAS;CACjB,MAAM,GAAG,SAAS;AACpB,CAAC;AAED,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM;CACN,OAAO;CACP,QAAQ;CACR,OAAO,OAAO,SAAS;CACvB,QAAQ;AACV,CAAC;AAED,MAAM,YAAY,EAAE,aAAa;CAAE,UAAU;CAAI,MAAM;CAAI;AAAO,CAAC;AAEnE,MAAM,YAAY,EAAE,aAAa;CAC/B;CACA,QAAQ,GAAG,SAAS;CACpB,OAAO,EAAE,MAAM,EAAE,aAAa;EAAE,UAAU;EAAI;CAAO,CAAC,CAAC,CAAC,CAAC,SAAS;CAClE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa;EAAE,MAAM;EAAI;CAAO,CAAC,GAAG,EAAE,aAAa;EAAE,UAAU;EAAI;CAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { formErrors } from \"@mark1russell7/system-stack/schema\";\nimport { z } from \"zod\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The zod schema of an endurance layer and the read of its JSON. This module is the entry `/schema` of the package.\n// The root entry has no zod, so a host that only calculates gets no schema library.\n\nconst id = z.string().min(1);\nconst amount = z.number();\n\nconst resource = z.strictObject({ code: id, unit: id });\n\nconst store = z.strictObject({\n id,\n resource: id,\n amount,\n due: id.optional(),\n part: id.optional(),\n});\n\nconst draw = z.strictObject({\n need: id,\n level: id,\n perDay: amount,\n users: amount.optional(),\n supply: id,\n});\n\nconst directUse = z.strictObject({ resource: id, need: id, amount });\n\nconst converter = z.strictObject({\n id,\n device: id.optional(),\n takes: z.array(z.strictObject({ resource: id, amount })).readonly(),\n gives: z.union([z.strictObject({ need: id, amount }), z.strictObject({ resource: id, amount })]),\n perDay: amount.optional(),\n devices: amount.optional(),\n});\n\nconst point = z.tuple([z.number(), z.number()]).readonly();\n\nconst cut = z.strictObject({\n part: id,\n title: id,\n duration: z.array(point).readonly().optional(),\n source: id,\n});\n\nconst caseCuts = z.strictObject({\n case: id,\n title: id,\n cuts: z.array(cut).readonly(),\n factors: z.record(z.string(), amount).optional(),\n leadSeconds: amount.optional(),\n});\n\nconst prior = z.strictObject({\n case: id,\n place: id,\n perYear: amount,\n reach: amount,\n source: id,\n asOf: id,\n});\n\n/**\n * The schema of an endurance layer. It examines the form of the record: the fields and their types.\n * It refuses a field that the format does not have. `checkEndurance` examines the meaning of a layer with a correct form.\n */\nexport const enduranceSchema: z.ZodType<EnduranceLayer> = z.strictObject({\n schema: z.literal(ENDURANCE_SCHEMA),\n levels: z.array(id).readonly(),\n resources: z.array(resource).readonly(),\n stores: z.array(store).readonly(),\n draws: z.array(draw).readonly(),\n direct: z.array(directUse).readonly().optional(),\n converters: z.array(converter).readonly().optional(),\n cases: z.array(caseCuts).readonly().optional(),\n priors: z.array(prior).readonly().optional(),\n});\n\n/** The result of the read of an endurance layer: the layer, or the faults of its form. */\nexport type EnduranceParse = { readonly ok: true; readonly layer: EnduranceLayer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of an endurance layer. It gives the layer, or the faults of its form.\n * Each fault names its place in the record, for example `stores.0.amount`.\n */\nexport function parseEndurance(input: unknown): EnduranceParse {\n const read = enduranceSchema.safeParse(input);\n if (read.success) return { ok: true, layer: read.data };\n return { ok: false, errors: formErrors(ENDURANCE_SCHEMA, read.error.issues) };\n}\n"],"mappings":";;;;AAOA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC3B,MAAM,SAAS,EAAE,OAAO;AAExB,MAAM,WAAW,EAAE,aAAa;CAAE,MAAM;CAAI,MAAM;AAAG,CAAC;AAEtD,MAAM,QAAQ,EAAE,aAAa;CAC3B;CACA,UAAU;CACV;CACA,KAAK,GAAG,SAAS;CACjB,MAAM,GAAG,SAAS;AACpB,CAAC;AAED,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM;CACN,OAAO;CACP,QAAQ;CACR,OAAO,OAAO,SAAS;CACvB,QAAQ;AACV,CAAC;AAED,MAAM,YAAY,EAAE,aAAa;CAAE,UAAU;CAAI,MAAM;CAAI;AAAO,CAAC;AAEnE,MAAM,YAAY,EAAE,aAAa;CAC/B;CACA,QAAQ,GAAG,SAAS;CACpB,OAAO,EAAE,MAAM,EAAE,aAAa;EAAE,UAAU;EAAI;CAAO,CAAC,CAAC,CAAC,CAAC,SAAS;CAClE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa;EAAE,MAAM;EAAI;CAAO,CAAC,GAAG,EAAE,aAAa;EAAE,UAAU;EAAI;CAAO,CAAC,CAAC,CAAC;CAC/F,QAAQ,OAAO,SAAS;CACxB,SAAS,OAAO,SAAS;AAC3B,CAAC;AAED,MAAM,QAAQ,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC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M,MAAM;CAAE;AAC9E"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/stack-endurance",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "Stores, draws and converters of a system stack: the days that each draw holds when a case cuts its supply, and the shortfall of each level in one year. An add-on of system-stack.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"join-BRnPkac5.js","names":["curveFault"],"sources":["../src/fit.ts","../src/endurance.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["/** The relative tolerance of a take and of a fit. */\nexport const TOLERANCE = 1e-13;\n\n/** One try of a fit: the amount that the stores could not give, out of the amount wanted, and the value of the try. */\nexport interface Try<T> {\n readonly short: number;\n readonly need: number;\n readonly value: T;\n}\n\n/** The result of a fit: the largest amount with no shortfall, and the value of its try. The value is `undefined` when only 0 fits. */\nexport interface Fit<T> {\n readonly x: number;\n readonly value: T | undefined;\n}\n\n/**\n * The count of the tries of `largestFit`, for the tests of the cost. It is not in the public API, and it does not change a result.\n * It is the one side effect of `largestFit` and of the queries that use it.\n */\nexport const fitTries = { count: 0 };\n\n/**\n * This function gives the largest `x` in `[0, most]` at which `attempt` has no shortfall, to the relative tolerance `TOLERANCE`.\n *\n * - A try fits when its shortfall is not more than `TOLERANCE` times its need.\n * - The shortfall must not decrease when `x` increases. A take of a chain of converters gives a shortfall that is linear in parts.\n * - The first try is `most`. After it, each step tries the zero of the line through the last two tries that do not fit.\n * With one try that does not fit, the step tries `x` times the part of the need that the stores gave.\n * - When a step does not halve the interval, the next step is a bisection. Thus a fit takes at most approximately twice the steps of a bisection.\n * - A step on the lower end tries a point just above it, so a correct estimate ends the fit in one more try.\n * - An estimate that fits with a shortfall above 0 is in the band of the tolerance above the zero, so the fit ends there.\n * A bisection step or a probe at the lower end can fit with a shortfall of rounding below the zero. The fit does not end there.\n *\n * @param most - The upper limit of `x`\n * @param attempt - The try at an amount. It must not change its input\n * @returns The largest amount that fits, and the value of its try\n */\nexport function largestFit<T>(most: number, attempt: (x: number) => Try<T>): Fit<T> {\n const fits = (tried: Try<T>): boolean => tried.short <= TOLERANCE * tried.need;\n fitTries.count += 1;\n const first = attempt(most);\n if (fits(first)) return { x: most, value: first.value };\n let low = 0;\n let best: T | undefined;\n let high = most;\n let highShort = first.short;\n let highNeed = first.need;\n let before: { readonly x: number; readonly short: number } | undefined;\n let bisect = false;\n for (let step = 0; step < 400 && high - low > 4 * TOLERANCE * high; step += 1) {\n const width = high - low;\n let x: number;\n if (bisect) x = (low + high) / 2;\n else if (before !== undefined && before.short > highShort) x = high - (highShort * (before.x - high)) / (before.short - highShort);\n else x = high * (1 - highShort / highNeed);\n // Only a secant or ratio estimate through tries that do not fit lands at or above the zero of a convex shortfall.\n const estimate = !bisect && x < high;\n if (!(x < high)) x = (low + high) / 2;\n const floor = low + 2 * TOLERANCE * high;\n const clamped = !(x > floor);\n if (clamped) x = floor;\n fitTries.count += 1;\n const tried = attempt(x);\n if (fits(tried)) {\n low = x;\n best = tried.value;\n // An estimate that fits with a shortfall is in the band of the tolerance above the zero, so the fit ends.\n if (tried.short > 0 && estimate && !clamped) break;\n } else {\n before = { x: high, short: highShort };\n high = x;\n highShort = tried.short;\n highNeed = tried.need;\n }\n bisect = !bisect && high - low > width / 2;\n }\n return { x: low, value: best };\n}\n","import { dayNumber, stopped, type Stack } from \"@mark1russell7/system-stack\";\nimport { largestFit, type Try } from \"./fit.ts\";\nimport type { CaseCuts, Converter, DirectUse, Draw, Endurance, EnduranceLayer, IsoDate } from \"./layer.ts\";\n\n// The endurance query: the days that each draw holds when a case stops its supply.\n\n/** The options of the queries of a case. */\nexport interface CaseOptions {\n /** The date of the query. A store whose due date is on this date or before it gives nothing. */\n readonly at: IsoDate;\n /** The base stack. With it, a cut also stops each part that cannot work without a cut part (`stopped` of the core). */\n readonly stack?: Stack | undefined;\n /** The `id` of more parts that are down, with the cuts of the case. */\n readonly down?: readonly string[] | undefined;\n}\n\n/**\n * This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.\n * With a stack, it also gives each part that stops.\n */\nexport function caseStopped(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): Set<string> {\n const down = [...caseCuts.cuts.map((cut) => cut.part), ...(options.down ?? [])];\n const out = new Set(down);\n if (options.stack !== undefined) for (const id of stopped(options.stack, down)) out.add(id);\n return out;\n}\n\n/** This function gives the day number of a date, or throws a `RangeError` for a date that is not `YYYY-MM-DD`. */\nfunction dayOf(date: IsoDate): number {\n const day = dayNumber(date);\n if (day === undefined) throw new RangeError(`The date \"${date}\" is not a date YYYY-MM-DD.`);\n return day;\n}\n\n/**\n * This function gives the amount of each resource in the stores at a date, by the code of the resource.\n *\n * - A store gives nothing on its due date and after it.\n * - A store gives nothing when its part is in `stoppedParts`.\n */\nexport function storeAmounts(layer: EnduranceLayer, at: IsoDate, stoppedParts: ReadonlySet<string> = new Set()): Map<string, number> {\n const today = dayOf(at);\n const out = new Map<string, number>();\n for (const store of layer.stores) {\n if (store.due !== undefined && today >= dayOf(store.due)) continue;\n if (store.part !== undefined && stoppedParts.has(store.part)) continue;\n out.set(store.resource, (out.get(store.resource) ?? 0) + store.amount);\n }\n return out;\n}\n\n/** This function gives the amount of a need for each day in a case: the rate of the draw times the factor of the case. */\nexport function drawDemand(draw: Draw, caseCuts: CaseCuts): number {\n return draw.perDay * (caseCuts.factors?.[draw.need] ?? 1);\n}\n\n/**\n * This function gives the draws that take from the stores in a case: each draw whose supply stops, with a demand more than 0.\n * The sequence is by the level (the order of `levels`), then by the code of the need.\n */\nexport function caseDraws(layer: EnduranceLayer, caseCuts: CaseCuts, stoppedParts: ReadonlySet<string>): Draw[] {\n const rank = (level: string): number => {\n const index = layer.levels.indexOf(level);\n return index < 0 ? layer.levels.length : index;\n };\n return layer.draws\n .filter((draw) => stoppedParts.has(draw.supply) && drawDemand(draw, caseCuts) > 0)\n .sort((a, b) => rank(a.level) - rank(b.level) || (a.need < b.need ? -1 : a.need > b.need ? 1 : 0));\n}\n\n/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */\nexport function giftNeed(converter: Converter): string | undefined {\n return \"need\" in converter.gives ? converter.gives.need : undefined;\n}\n\n/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */\nexport function giftResource(converter: Converter): string | undefined {\n return \"resource\" in converter.gives ? converter.gives.resource : undefined;\n}\n\n/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */\nfunction inputsOf(converter: Converter): Map<string, number> {\n const out = new Map<string, number>();\n for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);\n return out;\n}\n\n/** This function tells if a converter can run in a case. Its device works, it takes a resource, and it gives an amount more than 0. */\nfunction canRun(converter: Converter, stoppedParts: ReadonlySet<string>): boolean {\n return converter.gives.amount > 0 && inputsOf(converter).size > 0 && (converter.device === undefined || !stoppedParts.has(converter.device));\n}\n\n/** The converters of a case that make each resource, in the order of the layer, by the code of the resource. */\ntype Makers = ReadonlyMap<string, readonly Converter[]>;\n\nfunction makersOf(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): Makers {\n const out = new Map<string, Converter[]>();\n for (const converter of layer.converters ?? []) {\n const resource = giftResource(converter);\n if (resource === undefined || !canRun(converter, stoppedParts)) continue;\n out.set(resource, [...(out.get(resource) ?? []), converter]);\n }\n return out;\n}\n\n/** The ways to get one need in a case: its direct uses, then the converters that give it, in the order of the layer. `makers` make the resources. */\ninterface Ways {\n readonly direct: readonly DirectUse[];\n readonly converters: readonly Converter[];\n readonly makers: Makers;\n}\n\nfunction waysOf(layer: EnduranceLayer, need: string, stoppedParts: ReadonlySet<string>, makers: Makers): Ways {\n return {\n direct: (layer.direct ?? []).filter((use) => use.need === need && use.amount > 0),\n converters: (layer.converters ?? []).filter((converter) => giftNeed(converter) === need && canRun(converter, stoppedParts)),\n makers,\n };\n}\n\n// A chain: the resources on the path of a take. A maker does not take a resource of its own path, so a cycle of the layer stops there.\nconst NO_PATH: ReadonlySet<string> = new Set();\n\n/**\n * This function gives the most of a resource that `left` gives: its stock, and the runs of each maker.\n * It is an upper limit. When two inputs come from one resource, the true amount can be less.\n */\nfunction mostResource(left: ReadonlyMap<string, number>, makers: Makers, resource: string, path: ReadonlySet<string>): number {\n let total = left.get(resource) ?? 0;\n if (path.has(resource)) return total;\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) total += mostRuns(left, makers, maker, next) * maker.gives.amount;\n return total;\n}\n\n/** This function gives the most runs of a converter that `left` gives. It is an upper limit, as for `mostResource`. */\nfunction mostRuns(left: ReadonlyMap<string, number>, makers: Makers, converter: Converter, path: ReadonlySet<string>): number {\n let runs = Infinity;\n for (const [resource, each] of inputsOf(converter)) runs = Math.min(runs, mostResource(left, makers, resource, path) / each);\n return Number.isFinite(runs) ? runs : 0;\n}\n\n/**\n * This function takes an amount of a resource from `left`: the stock first, then the makers in the order of the layer.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction takeResource(left: Map<string, number>, makers: Makers, resource: string, amount: number, path: ReadonlySet<string>): number {\n const has = left.get(resource) ?? 0;\n const got = Math.min(amount, has);\n left.set(resource, has - got);\n let rest = amount - got;\n if (rest <= 0 || path.has(resource)) return Math.max(0, rest);\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) {\n if (rest <= 0) break;\n rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/**\n * This function runs a converter up to `wanted` times with the resources of `left`, and it gives the count of runs.\n * It changes `left`. When two inputs come from one resource, `largestFit` finds the runs that the resources give.\n */\nfunction run(left: Map<string, number>, makers: Makers, converter: Converter, wanted: number, path: ReadonlySet<string>): number {\n const inputs = inputsOf(converter);\n const most = Math.min(wanted, mostRuns(left, makers, converter, path));\n if (!(most > 0)) return 0;\n const attempt = (runs: number): Try<Map<string, number>> => {\n const copy = new Map(left);\n let need = 0;\n let short = 0;\n for (const [resource, each] of inputs) {\n need += runs * each;\n short += takeResource(copy, makers, resource, runs * each, path);\n }\n return { short, need, value: copy };\n };\n const { x: runs, value: best } = largestFit(most, attempt);\n if (best === undefined) return 0;\n for (const [resource, amount] of best) left.set(resource, amount);\n return runs;\n}\n\n/**\n * This function takes an amount of a need from the resources in `left`: the direct uses first, then the converters.\n * A direct use or a converter takes each resource from its stock first, then from its makers.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction take(left: Map<string, number>, ways: Ways, amount: number): number {\n let rest = amount;\n for (const use of ways.direct) {\n if (rest <= 0) break;\n const wanted = rest / use.amount;\n rest -= (wanted - takeResource(left, ways.makers, use.resource, wanted, NO_PATH)) * use.amount;\n }\n for (const converter of ways.converters) {\n if (rest <= 0) break;\n rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/** This function gives each resource that a need can use: the inputs of its ways, and the inputs of their makers, through each chain. */\nfunction inputClosure(ways: Ways): Set<string> {\n const out = new Set<string>();\n const queue = [...ways.direct.map((use) => use.resource), ...ways.converters.flatMap((converter) => [...inputsOf(converter).keys()])];\n for (let resource = queue.shift(); resource !== undefined; resource = queue.shift()) {\n if (out.has(resource)) continue;\n out.add(resource);\n for (const maker of ways.makers.get(resource) ?? []) queue.push(...inputsOf(maker).keys());\n }\n return out;\n}\n\n/** The relative tolerance of a used-up resource. */\nconst USED_UP = 1e-9;\n\n/**\n * This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.\n *\n * - A draw takes from the stores only when the case stops its supply part. Each other draw holds without end, and the result leaves it out.\n * - The demand of a draw for each day is its rate times the factor of the case.\n * - The draws take the resources in the order of their level, then of their codes. A draw takes from its direct uses first, then from its converters.\n * - The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.\n * - 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.\n * - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.\n * - A converter whose device stops gives nothing. A store whose part stops gives nothing.\n * - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.\n *\n * 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.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, and the stack or the parts that are also down\n * @returns The endurance of each draw whose supply stops\n */\nexport function enduranceOf(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions): Endurance {\n const stoppedParts = caseStopped(caseCuts, options);\n const start = storeAmounts(layer, options.at, stoppedParts);\n const makers = makersOf(layer, stoppedParts);\n const stocked = new Set(layer.stores.map((store) => store.resource));\n const done: { readonly ways: Ways; readonly demand: number; readonly days: number }[] = [];\n const needs: Record<string, { days: number; binding: string[]; takes: Record<string, number> }> = {};\n for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {\n const ways = waysOf(layer, draw.need, stoppedParts, makers);\n const demand = drawDemand(draw, caseCuts);\n const before = new Map(start);\n for (const higher of done) take(before, higher.ways, higher.days * higher.demand);\n const after = (days: number): { left: Map<string, number>; short: number } => {\n const left = new Map(before);\n return { left, short: take(left, ways, days * demand) };\n };\n // The upper limit: the days that the draw holds when it takes all the stores itself. `largestFit` finds the days below it.\n const fit = largestFit(capacity(start, ways) / demand, (days) => {\n const tried = after(days);\n return { short: tried.short, need: days * demand, value: tried.left };\n });\n const low = fit.x;\n const left = fit.value ?? after(low).left;\n const binding = [...inputClosure(ways)]\n .filter((resource) => !makers.has(resource) || stocked.has(resource))\n .filter((resource) => mostResource(left, makers, resource, NO_PATH) <= USED_UP * Math.max(1, start.get(resource) ?? 0))\n .sort();\n const takes: Record<string, number> = {};\n for (const [resource, amount] of before) {\n const taken = amount - (left.get(resource) ?? 0);\n if (taken > 0) takes[resource] = taken;\n }\n needs[draw.need] = { days: low, binding, takes };\n done.push({ ways, demand, days: low });\n }\n return { case: caseCuts.case, at: options.at, needs };\n}\n\n/**\n * This function gives an upper limit of a need that the stores give with no other draw, through each chain.\n * A converter that takes nothing gives nothing: the gate refuses it.\n */\nfunction capacity(start: ReadonlyMap<string, number>, ways: Ways): number {\n let total = 0;\n for (const use of ways.direct) total += mostResource(start, ways.makers, use.resource, NO_PATH) * use.amount;\n for (const converter of ways.converters) total += mostRuns(start, ways.makers, converter, NO_PATH) * converter.gives.amount;\n return total;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { curveFault, dayNumber, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./endurance.ts\";\nimport type { Converter, EnduranceLayer } from \"./layer.ts\";\n\n// The gate of an endurance layer: the meaning of a layer with a correct form, for its base stack.\n\n/**\n * These are the codes of the gate. Each code is an error, except `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.\n *\n * - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.\n * The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.\n * - `endurance-level-unknown`: the level of a draw is not a level of the layer.\n * - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.\n * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.\n * - `endurance-range`: an amount, a rate, a count or a factor is not a finite number of 0 or more. Or a reach is not from 0 to 1.\n * - `endurance-date`: a date is not a date `YYYY-MM-DD`.\n * - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.\n * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.\n * Or its days do not increase, or its chance increases.\n * - `endurance-prior-case`: a prior names a case that the layer does not have.\n * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.\n * - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.\n * - `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.\n */\nexport const ENDURANCE_CODES: readonly [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n] = [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n];\n\n/** A code of `ENDURANCE_CODES`. */\nexport type EnduranceCode = (typeof ENDURANCE_CODES)[number];\n\n/** A fault of the gate of an endurance layer. */\nexport interface EnduranceFault extends Fault {\n readonly code: EnduranceCode;\n}\n\nexport { curveFault } from \"@mark1russell7/system-stack\";\n\n/**\n * This function gives each fault of an endurance layer. With a base stack, it also examines the `id` of each part. A list with no error tells that the gate passes.\n *\n * The faults are in the order of the layer. The function is pure.\n *\n * @param layer - The endurance layer\n * @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.\n * @returns The faults\n */\nexport function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[] {\n const faults: EnduranceFault[] = [];\n const add = (level: EnduranceFault[\"level\"], code: EnduranceCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const once = (what: string, keys: readonly string[]): void => {\n const seen = new Set<string>();\n for (const key of keys) {\n if (seen.has(key)) add(\"error\", \"endurance-twice\", key, `Two or more ${what} have the key \"${key}\".`);\n seen.add(key);\n }\n };\n const range = (at: string, what: string, value: number): void => {\n if (!(Number.isFinite(value) && value >= 0)) add(\"error\", \"endurance-range\", at, `The ${what} of \"${at}\" is ${String(value)}. It must be a finite number of 0 or more.`);\n };\n const date = (at: string, value: string): void => {\n if (dayNumber(value) === undefined) add(\"error\", \"endurance-date\", at, `The date \"${value}\" of \"${at}\" is not a date YYYY-MM-DD.`);\n };\n const parts = stack === undefined ? undefined : new Set(stack.parts.map((part) => part.id));\n const part = (at: string, what: string, id: string | undefined): void => {\n if (parts !== undefined && id !== undefined && !parts.has(id)) add(\"error\", \"endurance-part-unknown\", at, `The ${what} \"${id}\" of \"${at}\" is not a part of the stack.`);\n };\n const resources = new Set(layer.resources.map((resource) => resource.code));\n const resource = (at: string, code: string): void => {\n if (!resources.has(code)) add(\"error\", \"endurance-resource-unknown\", at, `The resource \"${code}\" of \"${at}\" is not a resource of the layer.`);\n };\n const direct = layer.direct ?? [];\n const converters = layer.converters ?? [];\n const cases = layer.cases ?? [];\n const priors = layer.priors ?? [];\n\n once(\"levels\", layer.levels);\n once(\"resources\", layer.resources.map((item) => item.code));\n once(\"stores\", layer.stores.map((store) => store.id));\n once(\"draws\", layer.draws.map((draw) => draw.need));\n once(\"converters\", converters.map((converter) => converter.id));\n once(\"cases\", cases.map((item) => item.case));\n once(\"priors\", priors.map((prior) => `${prior.case}@${prior.place}`));\n\n for (const store of layer.stores) {\n resource(store.id, store.resource);\n range(store.id, \"amount\", store.amount);\n if (store.due !== undefined) date(store.id, store.due);\n part(store.id, \"part\", store.part);\n }\n const levels = new Set(layer.levels);\n for (const draw of layer.draws) {\n if (!levels.has(draw.level)) add(\"error\", \"endurance-level-unknown\", draw.need, `The level \"${draw.level}\" of the draw \"${draw.need}\" is not a level of the layer.`);\n range(draw.need, \"rate\", draw.perDay);\n if (draw.users !== undefined) range(draw.need, \"count of users\", draw.users);\n part(draw.need, \"supply\", draw.supply);\n const ways = direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need);\n if (!ways) add(\"warning\", \"endurance-no-way\", draw.need, `The draw \"${draw.need}\" has no direct use and no converter. It holds 0 days when its supply stops.`);\n }\n for (const use of direct) {\n const at = `${use.resource}>${use.need}`;\n resource(at, use.resource);\n range(at, \"amount\", use.amount);\n }\n for (const converter of converters) {\n once(`resources of the converter \"${converter.id}\"`, converter.takes.map((input) => input.resource));\n for (const input of converter.takes) {\n resource(converter.id, input.resource);\n range(converter.id, \"amount\", input.amount);\n }\n range(converter.id, \"amount\", converter.gives.amount);\n const made = giftResource(converter);\n if (made !== undefined) resource(converter.id, made);\n if (!converter.takes.some((input) => input.amount > 0) || converter.gives.amount === 0) add(\"error\", \"endurance-converter-empty\", converter.id, `The converter \"${converter.id}\" takes nothing, or it gives nothing.`);\n part(converter.id, \"device\", converter.device);\n }\n const caseCodes = new Set(cases.map((item) => item.case));\n for (const item of cases) {\n once(`cuts of the case \"${item.case}\"`, item.cuts.map((cut) => cut.part));\n for (const cut of item.cuts) {\n const at = `${item.case}/${cut.part}`;\n part(at, \"cut\", cut.part);\n if (cut.duration === undefined) {\n add(\"warning\", \"endurance-cut-no-curve\", at, `The cut \"${at}\" has no curve of its duration, so the draws that it can stop are no read.`);\n continue;\n }\n const fault = curveFault(cut.duration);\n if (fault !== undefined) add(\"error\", \"endurance-curve\", at, `The duration of the cut \"${at}\": ${fault}`);\n }\n for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, \"factor\", factor);\n if (item.leadSeconds !== undefined) range(item.case, \"lead time\", item.leadSeconds);\n }\n for (const cycle of resourceCycles(converters)) {\n const [first = \"\"] = cycle;\n const names = cycle.map((code) => `\"${code}\"`).join(\", \");\n const message = cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`;\n add(\"error\", \"endurance-cycle\", first, `${message} A chain of converters cannot end.`);\n }\n for (const prior of priors) {\n const at = `${prior.case}@${prior.place}`;\n if (!caseCodes.has(prior.case)) add(\"error\", \"endurance-prior-case\", at, `The prior \"${at}\" names the case \"${prior.case}\", which the layer does not have.`);\n range(at, \"count of events in one year\", prior.perYear);\n if (!(prior.reach >= 0 && prior.reach <= 1)) add(\"error\", \"endurance-range\", at, `The reach of \"${at}\" is ${String(prior.reach)}. It must be from 0 to 1.`);\n date(at, prior.asOf);\n }\n return faults;\n}\n\n/** This function gives each cycle of resources: a resource is made from a resource that a converter makes from it. Each cycle is a list of codes. */\nfunction resourceCycles(converters: readonly Converter[]): string[][] {\n const from = new Map<string, Set<string>>();\n for (const converter of converters) {\n const made = giftResource(converter);\n if (made === undefined) continue;\n const inputs = from.get(made) ?? new Set<string>();\n for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);\n from.set(made, inputs);\n }\n const successors = (code: string): Iterable<string> => from.get(code) ?? [];\n return stronglyConnectedComponents(from.keys(), successors).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (from.get(only)?.has(only) ?? false);\n });\n}\n\n/** This function tells if a list of faults has an error. */\nexport function hasEnduranceError(faults: readonly EnduranceFault[]): boolean {\n return faults.some((fault) => fault.level === \"error\");\n}\n","import { canonicalJson } from \"@mark1russell7/rigor-generators\";\nimport { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The join of the endurance layers of the fragments of a stack, for example one file of stores for each owner.\n\n/**\n * This function joins the endurance layers of the fragments of a stack into one layer.\n *\n * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.\n * - The records of each list are in the order of the fragments.\n * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.\n * Its message gives the canonical JSON of the record of each fragment.\n * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.\n * - One key of each other list in two or more fragments is a fault, also when the records are equal.\n * - The key of a direct use is its resource and its need.\n *\n * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer> {\n const levels = joinSetting(pieces, (layer) => (layer.levels.length > 0 ? layer.levels.join(\"\\n\") : undefined), \"levels\");\n // Two fragments can declare one resource, for example `water.stored` in `L`. Canonical JSON (RFC 8785) compares the records,\n // so the order of the keys has no effect. The message of a fault gives the canonical JSON of the record of each fragment.\n const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\", {\n equal: (first, other) => canonicalJson(first) === canonicalJson(other),\n text: canonicalJson,\n });\n const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, \"store\");\n const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, \"draw\");\n const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, \"direct use\");\n const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, \"converter\");\n const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, \"case\");\n const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, \"prior\");\n const errors = [levels, resources, stores, draws, direct, converters, cases, priors].flatMap((join) => join.errors);\n if (errors.length > 0) return { ok: false, errors };\n const has = (key: \"direct\" | \"converters\" | \"cases\" | \"priors\"): boolean => pieces.some((piece) => piece.layer[key] !== undefined);\n return {\n ok: true,\n layer: {\n schema: ENDURANCE_SCHEMA,\n levels: levels.value === undefined ? [] : levels.value.split(\"\\n\"),\n resources: resources.items,\n stores: stores.items,\n draws: draws.items,\n ...(has(\"direct\") ? { direct: direct.items } : {}),\n ...(has(\"converters\") ? { converters: converters.items } : {}),\n ...(has(\"cases\") ? { cases: cases.items } : {}),\n ...(has(\"priors\") ? { priors: priors.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;;AACA,MAAa,YAAY;;;;;AAmBzB,MAAa,WAAW,EAAE,OAAO,EAAE;;;;;;;;;;;;;;;;;AAkBnC,SAAgB,WAAc,MAAc,SAAwC;CAClF,MAAM,QAAQ,UAA2B,MAAM,SAAS,YAAY,MAAM;CAC1E,SAAS,SA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