@mark1russell7/stack-endurance 0.0.0-bootstrap.0 → 0.3.1
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/LICENSE +21 -0
- package/README.md +86 -1
- package/build/add-on.d.ts +12 -0
- package/build/add-on.d.ts.map +1 -0
- package/build/add-on.js +23 -0
- package/build/add-on.js.map +1 -0
- package/build/index.d.ts +258 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +529 -0
- package/build/index.js.map +1 -0
- package/build/join-D7KyUpGf.js +557 -0
- package/build/join-D7KyUpGf.js.map +1 -0
- package/build/layer-DzGZC5XH.d.ts +143 -0
- package/build/layer-DzGZC5XH.d.ts.map +1 -0
- package/build/layer-a3Fr70Uh.js +6 -0
- package/build/layer-a3Fr70Uh.js.map +1 -0
- package/build/schema.d.ts +21 -0
- package/build/schema.d.ts.map +1 -0
- package/build/schema.js +99 -0
- package/build/schema.js.map +1 -0
- package/package.json +71 -6
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
+
import { dayNumber, joinRecords, joinSetting, stopped } from "@mark1russell7/system-stack";
|
|
3
|
+
import { stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
4
|
+
// src/fit.ts
|
|
5
|
+
/** The relative tolerance of a take and of a fit. */
|
|
6
|
+
const TOLERANCE = 1e-13;
|
|
7
|
+
/**
|
|
8
|
+
* 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.
|
|
9
|
+
* It is the one side effect of `largestFit` and of the queries that use it.
|
|
10
|
+
*/
|
|
11
|
+
const fitTries = { count: 0 };
|
|
12
|
+
/**
|
|
13
|
+
* This function gives the largest `x` in `[0, most]` at which `attempt` has no shortfall, to the relative tolerance `TOLERANCE`.
|
|
14
|
+
*
|
|
15
|
+
* - A try fits when its shortfall is not more than `TOLERANCE` times its need.
|
|
16
|
+
* - The shortfall must not decrease when `x` increases. A take of a chain of converters gives a shortfall that is linear in parts.
|
|
17
|
+
* - The first try is `most`. After it, each step tries the zero of the line through the last two tries that do not fit.
|
|
18
|
+
* With one try that does not fit, the step tries `x` times the part of the need that the stores gave.
|
|
19
|
+
* - 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.
|
|
20
|
+
* - A step on the lower end tries a point just above it, so a correct estimate ends the fit in one more try.
|
|
21
|
+
* - An estimate that fits with a shortfall above 0 is in the band of the tolerance above the zero, so the fit ends there.
|
|
22
|
+
* 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.
|
|
23
|
+
*
|
|
24
|
+
* @param most - The upper limit of `x`
|
|
25
|
+
* @param attempt - The try at an amount. It must not change its input
|
|
26
|
+
* @returns The largest amount that fits, and the value of its try
|
|
27
|
+
*/
|
|
28
|
+
function largestFit(most, attempt) {
|
|
29
|
+
const fits = (tried) => tried.short <= TOLERANCE * tried.need;
|
|
30
|
+
fitTries.count += 1;
|
|
31
|
+
const first = attempt(most);
|
|
32
|
+
if (fits(first)) return {
|
|
33
|
+
x: most,
|
|
34
|
+
value: first.value
|
|
35
|
+
};
|
|
36
|
+
let low = 0;
|
|
37
|
+
let best;
|
|
38
|
+
let high = most;
|
|
39
|
+
let highShort = first.short;
|
|
40
|
+
let highNeed = first.need;
|
|
41
|
+
let before;
|
|
42
|
+
let bisect = false;
|
|
43
|
+
for (let step = 0; step < 400 && high - low > 4e-13 * high; step += 1) {
|
|
44
|
+
const width = high - low;
|
|
45
|
+
let x;
|
|
46
|
+
if (bisect) x = (low + high) / 2;
|
|
47
|
+
else if (before !== void 0 && before.short > highShort) x = high - highShort * (before.x - high) / (before.short - highShort);
|
|
48
|
+
else x = high * (1 - highShort / highNeed);
|
|
49
|
+
const estimate = !bisect && x < high;
|
|
50
|
+
if (!(x < high)) x = (low + high) / 2;
|
|
51
|
+
const floor = low + 2 * TOLERANCE * high;
|
|
52
|
+
const clamped = !(x > floor);
|
|
53
|
+
if (clamped) x = floor;
|
|
54
|
+
fitTries.count += 1;
|
|
55
|
+
const tried = attempt(x);
|
|
56
|
+
if (fits(tried)) {
|
|
57
|
+
low = x;
|
|
58
|
+
best = tried.value;
|
|
59
|
+
if (tried.short > 0 && estimate && !clamped) break;
|
|
60
|
+
} else {
|
|
61
|
+
before = {
|
|
62
|
+
x: high,
|
|
63
|
+
short: highShort
|
|
64
|
+
};
|
|
65
|
+
high = x;
|
|
66
|
+
highShort = tried.short;
|
|
67
|
+
highNeed = tried.need;
|
|
68
|
+
}
|
|
69
|
+
bisect = !bisect && high - low > width / 2;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
x: low,
|
|
73
|
+
value: best
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// src/endurance.ts
|
|
77
|
+
/**
|
|
78
|
+
* This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.
|
|
79
|
+
* With a stack, it also gives each part that stops.
|
|
80
|
+
*/
|
|
81
|
+
function caseStopped(caseCuts, options) {
|
|
82
|
+
const down = [...caseCuts.cuts.map((cut) => cut.part), ...options.down ?? []];
|
|
83
|
+
const out = new Set(down);
|
|
84
|
+
if (options.stack !== void 0) for (const id of stopped(options.stack, down)) out.add(id);
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/** This function gives the day number of a date, or throws a `RangeError` for a date that is not `YYYY-MM-DD`. */
|
|
88
|
+
function dayOf(date) {
|
|
89
|
+
const day = dayNumber(date);
|
|
90
|
+
if (day === void 0) throw new RangeError(`The date "${date}" is not a date YYYY-MM-DD.`);
|
|
91
|
+
return day;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* This function gives the amount of each resource in the stores at a date, by the code of the resource.
|
|
95
|
+
*
|
|
96
|
+
* - A store gives nothing on its due date and after it.
|
|
97
|
+
* - A store gives nothing when its part is in `stoppedParts`.
|
|
98
|
+
*/
|
|
99
|
+
function storeAmounts(layer, at, stoppedParts = /* @__PURE__ */ new Set()) {
|
|
100
|
+
const today = dayOf(at);
|
|
101
|
+
const out = /* @__PURE__ */ new Map();
|
|
102
|
+
for (const store of layer.stores) {
|
|
103
|
+
if (store.due !== void 0 && today >= dayOf(store.due)) continue;
|
|
104
|
+
if (store.part !== void 0 && stoppedParts.has(store.part)) continue;
|
|
105
|
+
out.set(store.resource, (out.get(store.resource) ?? 0) + store.amount);
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/** 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. */
|
|
110
|
+
function drawDemand(draw, caseCuts) {
|
|
111
|
+
return draw.perDay * (caseCuts.factors?.[draw.need] ?? 1);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* This function gives the draws that take from the stores in a case: each draw whose supply stops, with a demand more than 0.
|
|
115
|
+
* The sequence is by the level (the order of `levels`), then by the code of the need.
|
|
116
|
+
*/
|
|
117
|
+
function caseDraws(layer, caseCuts, stoppedParts) {
|
|
118
|
+
const rank = (level) => {
|
|
119
|
+
const index = layer.levels.indexOf(level);
|
|
120
|
+
return index < 0 ? layer.levels.length : index;
|
|
121
|
+
};
|
|
122
|
+
return layer.draws.filter((draw) => stoppedParts.has(draw.supply) && drawDemand(draw, caseCuts) > 0).sort((a, b) => rank(a.level) - rank(b.level) || (a.need < b.need ? -1 : a.need > b.need ? 1 : 0));
|
|
123
|
+
}
|
|
124
|
+
/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */
|
|
125
|
+
function giftNeed(converter) {
|
|
126
|
+
return "need" in converter.gives ? converter.gives.need : void 0;
|
|
127
|
+
}
|
|
128
|
+
/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */
|
|
129
|
+
function giftResource(converter) {
|
|
130
|
+
return "resource" in converter.gives ? converter.gives.resource : void 0;
|
|
131
|
+
}
|
|
132
|
+
/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */
|
|
133
|
+
function inputsOf(converter) {
|
|
134
|
+
const out = /* @__PURE__ */ new Map();
|
|
135
|
+
for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/** 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. */
|
|
139
|
+
function canRun(converter, stoppedParts) {
|
|
140
|
+
return converter.gives.amount > 0 && inputsOf(converter).size > 0 && (converter.device === void 0 || !stoppedParts.has(converter.device));
|
|
141
|
+
}
|
|
142
|
+
function makersOf(layer, stoppedParts) {
|
|
143
|
+
const out = /* @__PURE__ */ new Map();
|
|
144
|
+
for (const converter of layer.converters ?? []) {
|
|
145
|
+
const resource = giftResource(converter);
|
|
146
|
+
if (resource === void 0 || !canRun(converter, stoppedParts)) continue;
|
|
147
|
+
out.set(resource, [...out.get(resource) ?? [], converter]);
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
function waysOf(layer, need, stoppedParts, makers) {
|
|
152
|
+
return {
|
|
153
|
+
direct: (layer.direct ?? []).filter((use) => use.need === need && use.amount > 0),
|
|
154
|
+
converters: (layer.converters ?? []).filter((converter) => giftNeed(converter) === need && canRun(converter, stoppedParts)),
|
|
155
|
+
makers
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const NO_PATH = /* @__PURE__ */ new Set();
|
|
159
|
+
/**
|
|
160
|
+
* This function gives the most of a resource that `left` gives: its stock, and the runs of each maker.
|
|
161
|
+
* It is an upper limit. When two inputs come from one resource, the true amount can be less.
|
|
162
|
+
*/
|
|
163
|
+
function mostResource(left, makers, resource, path) {
|
|
164
|
+
let total = left.get(resource) ?? 0;
|
|
165
|
+
if (path.has(resource)) return total;
|
|
166
|
+
const next = new Set(path).add(resource);
|
|
167
|
+
for (const maker of makers.get(resource) ?? []) total += mostRuns(left, makers, maker, next) * maker.gives.amount;
|
|
168
|
+
return total;
|
|
169
|
+
}
|
|
170
|
+
/** This function gives the most runs of a converter that `left` gives. It is an upper limit, as for `mostResource`. */
|
|
171
|
+
function mostRuns(left, makers, converter, path) {
|
|
172
|
+
let runs = 1e400;
|
|
173
|
+
for (const [resource, each] of inputsOf(converter)) runs = Math.min(runs, mostResource(left, makers, resource, path) / each);
|
|
174
|
+
return Number.isFinite(runs) ? runs : 0;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* This function takes an amount of a resource from `left`: the stock first, then the makers in the order of the layer.
|
|
178
|
+
* It changes `left`, and it gives the amount that it could not take.
|
|
179
|
+
*/
|
|
180
|
+
function takeResource(left, makers, resource, amount, path) {
|
|
181
|
+
const has = left.get(resource) ?? 0;
|
|
182
|
+
const got = Math.min(amount, has);
|
|
183
|
+
left.set(resource, has - got);
|
|
184
|
+
let rest = amount - got;
|
|
185
|
+
if (rest <= 0 || path.has(resource)) return Math.max(0, rest);
|
|
186
|
+
const next = new Set(path).add(resource);
|
|
187
|
+
for (const maker of makers.get(resource) ?? []) {
|
|
188
|
+
if (rest <= 0) break;
|
|
189
|
+
rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;
|
|
190
|
+
}
|
|
191
|
+
return Math.max(0, rest);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* This function runs a converter up to `wanted` times with the resources of `left`, and it gives the count of runs.
|
|
195
|
+
* It changes `left`. When two inputs come from one resource, `largestFit` finds the runs that the resources give.
|
|
196
|
+
*/
|
|
197
|
+
function run(left, makers, converter, wanted, path) {
|
|
198
|
+
const inputs = inputsOf(converter);
|
|
199
|
+
const most = Math.min(wanted, mostRuns(left, makers, converter, path));
|
|
200
|
+
if (!(most > 0)) return 0;
|
|
201
|
+
const attempt = (runs) => {
|
|
202
|
+
const copy = new Map(left);
|
|
203
|
+
let need = 0;
|
|
204
|
+
let short = 0;
|
|
205
|
+
for (const [resource, each] of inputs) {
|
|
206
|
+
need += runs * each;
|
|
207
|
+
short += takeResource(copy, makers, resource, runs * each, path);
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
short,
|
|
211
|
+
need,
|
|
212
|
+
value: copy
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
const { x: runs, value: best } = largestFit(most, attempt);
|
|
216
|
+
if (best === void 0) return 0;
|
|
217
|
+
for (const [resource, amount] of best) left.set(resource, amount);
|
|
218
|
+
return runs;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* This function takes an amount of a need from the resources in `left`: the direct uses first, then the converters.
|
|
222
|
+
* A direct use or a converter takes each resource from its stock first, then from its makers.
|
|
223
|
+
* It changes `left`, and it gives the amount that it could not take.
|
|
224
|
+
*/
|
|
225
|
+
function take(left, ways, amount) {
|
|
226
|
+
let rest = amount;
|
|
227
|
+
for (const use of ways.direct) {
|
|
228
|
+
if (rest <= 0) break;
|
|
229
|
+
const wanted = rest / use.amount;
|
|
230
|
+
rest -= (wanted - takeResource(left, ways.makers, use.resource, wanted, NO_PATH)) * use.amount;
|
|
231
|
+
}
|
|
232
|
+
for (const converter of ways.converters) {
|
|
233
|
+
if (rest <= 0) break;
|
|
234
|
+
rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;
|
|
235
|
+
}
|
|
236
|
+
return Math.max(0, rest);
|
|
237
|
+
}
|
|
238
|
+
/** This function gives each resource that a need can use: the inputs of its ways, and the inputs of their makers, through each chain. */
|
|
239
|
+
function inputClosure(ways) {
|
|
240
|
+
const out = /* @__PURE__ */ new Set();
|
|
241
|
+
const queue = [...ways.direct.map((use) => use.resource), ...ways.converters.flatMap((converter) => [...inputsOf(converter).keys()])];
|
|
242
|
+
for (let resource = queue.shift(); resource !== void 0; resource = queue.shift()) {
|
|
243
|
+
if (out.has(resource)) continue;
|
|
244
|
+
out.add(resource);
|
|
245
|
+
for (const maker of ways.makers.get(resource) ?? []) queue.push(...inputsOf(maker).keys());
|
|
246
|
+
}
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
/** The relative tolerance of a used-up resource. */
|
|
250
|
+
const USED_UP = 1e-9;
|
|
251
|
+
/**
|
|
252
|
+
* This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.
|
|
253
|
+
*
|
|
254
|
+
* - 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.
|
|
255
|
+
* - The demand of a draw for each day is its rate times the factor of the case.
|
|
256
|
+
* - 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.
|
|
257
|
+
* - The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.
|
|
258
|
+
* - 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.
|
|
259
|
+
* - 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.
|
|
260
|
+
* - A converter whose device stops gives nothing. A store whose part stops gives nothing.
|
|
261
|
+
* - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.
|
|
262
|
+
*
|
|
263
|
+
* 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.
|
|
264
|
+
*
|
|
265
|
+
* @param layer - The endurance layer
|
|
266
|
+
* @param caseCuts - The case
|
|
267
|
+
* @param options - The date, and the stack or the parts that are also down
|
|
268
|
+
* @returns The endurance of each draw whose supply stops
|
|
269
|
+
*/
|
|
270
|
+
function enduranceOf(layer, caseCuts, options) {
|
|
271
|
+
const stoppedParts = caseStopped(caseCuts, options);
|
|
272
|
+
const start = storeAmounts(layer, options.at, stoppedParts);
|
|
273
|
+
const makers = makersOf(layer, stoppedParts);
|
|
274
|
+
const stocked = new Set(layer.stores.map((store) => store.resource));
|
|
275
|
+
const done = [];
|
|
276
|
+
const needs = {};
|
|
277
|
+
for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {
|
|
278
|
+
const ways = waysOf(layer, draw.need, stoppedParts, makers);
|
|
279
|
+
const demand = drawDemand(draw, caseCuts);
|
|
280
|
+
const before = new Map(start);
|
|
281
|
+
for (const higher of done) take(before, higher.ways, higher.days * higher.demand);
|
|
282
|
+
const after = (days) => {
|
|
283
|
+
const left = new Map(before);
|
|
284
|
+
return {
|
|
285
|
+
left,
|
|
286
|
+
short: take(left, ways, days * demand)
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
const fit = largestFit(capacity(start, ways) / demand, (days) => {
|
|
290
|
+
const tried = after(days);
|
|
291
|
+
return {
|
|
292
|
+
short: tried.short,
|
|
293
|
+
need: days * demand,
|
|
294
|
+
value: tried.left
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
const low = fit.x;
|
|
298
|
+
const left = fit.value ?? after(low).left;
|
|
299
|
+
const binding = [...inputClosure(ways)].filter((resource) => !makers.has(resource) || stocked.has(resource)).filter((resource) => mostResource(left, makers, resource, NO_PATH) <= USED_UP * Math.max(1, start.get(resource) ?? 0)).sort();
|
|
300
|
+
const takes = {};
|
|
301
|
+
for (const [resource, amount] of before) {
|
|
302
|
+
const taken = amount - (left.get(resource) ?? 0);
|
|
303
|
+
if (taken > 0) takes[resource] = taken;
|
|
304
|
+
}
|
|
305
|
+
needs[draw.need] = {
|
|
306
|
+
days: low,
|
|
307
|
+
binding,
|
|
308
|
+
takes
|
|
309
|
+
};
|
|
310
|
+
done.push({
|
|
311
|
+
ways,
|
|
312
|
+
demand,
|
|
313
|
+
days: low
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
case: caseCuts.case,
|
|
318
|
+
at: options.at,
|
|
319
|
+
needs
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* This function gives an upper limit of a need that the stores give with no other draw, through each chain.
|
|
324
|
+
* A converter that takes nothing gives nothing: the gate refuses it.
|
|
325
|
+
*/
|
|
326
|
+
function capacity(start, ways) {
|
|
327
|
+
let total = 0;
|
|
328
|
+
for (const use of ways.direct) total += mostResource(start, ways.makers, use.resource, NO_PATH) * use.amount;
|
|
329
|
+
for (const converter of ways.converters) total += mostRuns(start, ways.makers, converter, NO_PATH) * converter.gives.amount;
|
|
330
|
+
return total;
|
|
331
|
+
}
|
|
332
|
+
// src/check.ts
|
|
333
|
+
/**
|
|
334
|
+
* These are the codes of the gate. Each code is an error, except `endurance-no-way`, which is a warning.
|
|
335
|
+
*
|
|
336
|
+
* - `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.
|
|
337
|
+
* 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.
|
|
338
|
+
* - `endurance-level-unknown`: the level of a draw is not a level of the layer.
|
|
339
|
+
* - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.
|
|
340
|
+
* - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.
|
|
341
|
+
* - `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.
|
|
342
|
+
* - `endurance-date`: a date is not a date `YYYY-MM-DD`.
|
|
343
|
+
* - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.
|
|
344
|
+
* - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.
|
|
345
|
+
* Or its days do not increase, or its chance increases.
|
|
346
|
+
* - `endurance-prior-case`: a prior names a case that the layer does not have.
|
|
347
|
+
* - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.
|
|
348
|
+
* - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.
|
|
349
|
+
*/
|
|
350
|
+
const ENDURANCE_CODES = [
|
|
351
|
+
"endurance-twice",
|
|
352
|
+
"endurance-level-unknown",
|
|
353
|
+
"endurance-resource-unknown",
|
|
354
|
+
"endurance-part-unknown",
|
|
355
|
+
"endurance-range",
|
|
356
|
+
"endurance-date",
|
|
357
|
+
"endurance-converter-empty",
|
|
358
|
+
"endurance-curve",
|
|
359
|
+
"endurance-prior-case",
|
|
360
|
+
"endurance-cycle",
|
|
361
|
+
"endurance-no-way"
|
|
362
|
+
];
|
|
363
|
+
/** This function gives the first fault of a survival curve, or `undefined`. */
|
|
364
|
+
function curveFault(curve) {
|
|
365
|
+
const first = curve[0];
|
|
366
|
+
if (first === void 0 || first[0] !== 0 || first[1] !== 1) return "The curve does not start at [0, 1].";
|
|
367
|
+
for (let index = 1; index < curve.length; index += 1) {
|
|
368
|
+
const [t0, p0] = curve[index - 1] ?? [0, 1];
|
|
369
|
+
const [t1, p1] = curve[index] ?? [0, 0];
|
|
370
|
+
if (!(Number.isFinite(t1) && t1 > t0)) return `The days of the point ${String(index)} are not more than the days of the point before it.`;
|
|
371
|
+
if (!(p1 >= 0 && p1 <= p0)) return `The chance of the point ${String(index)} is not from 0 to the chance of the point before it.`;
|
|
372
|
+
}
|
|
373
|
+
if (curve[curve.length - 1]?.[1] !== 0) return "The curve does not end at a chance of 0.";
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* 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.
|
|
377
|
+
*
|
|
378
|
+
* The faults are in the order of the layer. The function is pure.
|
|
379
|
+
*
|
|
380
|
+
* @param layer - The endurance layer
|
|
381
|
+
* @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.
|
|
382
|
+
* @returns The faults
|
|
383
|
+
*/
|
|
384
|
+
function checkEndurance(layer, stack) {
|
|
385
|
+
const faults = [];
|
|
386
|
+
const add = (level, code, at, message) => {
|
|
387
|
+
faults.push({
|
|
388
|
+
level,
|
|
389
|
+
code,
|
|
390
|
+
at,
|
|
391
|
+
message
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
const once = (what, keys) => {
|
|
395
|
+
const seen = /* @__PURE__ */ new Set();
|
|
396
|
+
for (const key of keys) {
|
|
397
|
+
if (seen.has(key)) add("error", "endurance-twice", key, `Two or more ${what} have the key "${key}".`);
|
|
398
|
+
seen.add(key);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
const range = (at, what, value) => {
|
|
402
|
+
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.`);
|
|
403
|
+
};
|
|
404
|
+
const date = (at, value) => {
|
|
405
|
+
if (dayNumber(value) === void 0) add("error", "endurance-date", at, `The date "${value}" of "${at}" is not a date YYYY-MM-DD.`);
|
|
406
|
+
};
|
|
407
|
+
const parts = stack === void 0 ? void 0 : new Set(stack.parts.map((part) => part.id));
|
|
408
|
+
const part = (at, what, id) => {
|
|
409
|
+
if (parts !== void 0 && id !== void 0 && !parts.has(id)) add("error", "endurance-part-unknown", at, `The ${what} "${id}" of "${at}" is not a part of the stack.`);
|
|
410
|
+
};
|
|
411
|
+
const resources = new Set(layer.resources.map((resource) => resource.code));
|
|
412
|
+
const resource = (at, code) => {
|
|
413
|
+
if (!resources.has(code)) add("error", "endurance-resource-unknown", at, `The resource "${code}" of "${at}" is not a resource of the layer.`);
|
|
414
|
+
};
|
|
415
|
+
const direct = layer.direct ?? [];
|
|
416
|
+
const converters = layer.converters ?? [];
|
|
417
|
+
const cases = layer.cases ?? [];
|
|
418
|
+
const priors = layer.priors ?? [];
|
|
419
|
+
once("levels", layer.levels);
|
|
420
|
+
once("resources", layer.resources.map((item) => item.code));
|
|
421
|
+
once("stores", layer.stores.map((store) => store.id));
|
|
422
|
+
once("draws", layer.draws.map((draw) => draw.need));
|
|
423
|
+
once("converters", converters.map((converter) => converter.id));
|
|
424
|
+
once("cases", cases.map((item) => item.case));
|
|
425
|
+
once("priors", priors.map((prior) => `${prior.case}@${prior.place}`));
|
|
426
|
+
for (const store of layer.stores) {
|
|
427
|
+
resource(store.id, store.resource);
|
|
428
|
+
range(store.id, "amount", store.amount);
|
|
429
|
+
if (store.due !== void 0) date(store.id, store.due);
|
|
430
|
+
part(store.id, "part", store.part);
|
|
431
|
+
}
|
|
432
|
+
const levels = new Set(layer.levels);
|
|
433
|
+
for (const draw of layer.draws) {
|
|
434
|
+
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.`);
|
|
435
|
+
range(draw.need, "rate", draw.perDay);
|
|
436
|
+
if (draw.users !== void 0) range(draw.need, "count of users", draw.users);
|
|
437
|
+
part(draw.need, "supply", draw.supply);
|
|
438
|
+
if (!(direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need))) 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.`);
|
|
439
|
+
}
|
|
440
|
+
for (const use of direct) {
|
|
441
|
+
const at = `${use.resource}>${use.need}`;
|
|
442
|
+
resource(at, use.resource);
|
|
443
|
+
range(at, "amount", use.amount);
|
|
444
|
+
}
|
|
445
|
+
for (const converter of converters) {
|
|
446
|
+
once(`resources of the converter "${converter.id}"`, converter.takes.map((input) => input.resource));
|
|
447
|
+
for (const input of converter.takes) {
|
|
448
|
+
resource(converter.id, input.resource);
|
|
449
|
+
range(converter.id, "amount", input.amount);
|
|
450
|
+
}
|
|
451
|
+
range(converter.id, "amount", converter.gives.amount);
|
|
452
|
+
const made = giftResource(converter);
|
|
453
|
+
if (made !== void 0) resource(converter.id, made);
|
|
454
|
+
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.`);
|
|
455
|
+
part(converter.id, "device", converter.device);
|
|
456
|
+
}
|
|
457
|
+
const caseCodes = new Set(cases.map((item) => item.case));
|
|
458
|
+
for (const item of cases) {
|
|
459
|
+
once(`cuts of the case "${item.case}"`, item.cuts.map((cut) => cut.part));
|
|
460
|
+
for (const cut of item.cuts) {
|
|
461
|
+
const at = `${item.case}/${cut.part}`;
|
|
462
|
+
part(at, "cut", cut.part);
|
|
463
|
+
const fault = curveFault(cut.duration);
|
|
464
|
+
if (fault !== void 0) add("error", "endurance-curve", at, `The duration of the cut "${at}": ${fault}`);
|
|
465
|
+
}
|
|
466
|
+
for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, "factor", factor);
|
|
467
|
+
if (item.leadSeconds !== void 0) range(item.case, "lead time", item.leadSeconds);
|
|
468
|
+
}
|
|
469
|
+
for (const cycle of resourceCycles(converters)) {
|
|
470
|
+
const [first = ""] = cycle;
|
|
471
|
+
const names = cycle.map((code) => `"${code}"`).join(", ");
|
|
472
|
+
add("error", "endurance-cycle", first, `${cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`} A chain of converters cannot end.`);
|
|
473
|
+
}
|
|
474
|
+
for (const prior of priors) {
|
|
475
|
+
const at = `${prior.case}@${prior.place}`;
|
|
476
|
+
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.`);
|
|
477
|
+
range(at, "count of events in one year", prior.perYear);
|
|
478
|
+
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.`);
|
|
479
|
+
date(at, prior.asOf);
|
|
480
|
+
}
|
|
481
|
+
return faults;
|
|
482
|
+
}
|
|
483
|
+
/** 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. */
|
|
484
|
+
function resourceCycles(converters) {
|
|
485
|
+
const from = /* @__PURE__ */ new Map();
|
|
486
|
+
for (const converter of converters) {
|
|
487
|
+
const made = giftResource(converter);
|
|
488
|
+
if (made === void 0) continue;
|
|
489
|
+
const inputs = from.get(made) ?? /* @__PURE__ */ new Set();
|
|
490
|
+
for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);
|
|
491
|
+
from.set(made, inputs);
|
|
492
|
+
}
|
|
493
|
+
const successors = (code) => from.get(code) ?? [];
|
|
494
|
+
return stronglyConnectedComponents(from.keys(), successors).filter((component) => {
|
|
495
|
+
const [only = ""] = component;
|
|
496
|
+
return component.length > 1 || (from.get(only)?.has(only) ?? false);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
/** This function tells if a list of faults has an error. */
|
|
500
|
+
function hasEnduranceError(faults) {
|
|
501
|
+
return faults.some((fault) => fault.level === "error");
|
|
502
|
+
}
|
|
503
|
+
// src/join.ts
|
|
504
|
+
/**
|
|
505
|
+
* This function joins the endurance layers of the fragments of a stack into one layer.
|
|
506
|
+
*
|
|
507
|
+
* - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.
|
|
508
|
+
* - The records of each list are in the order of the fragments.
|
|
509
|
+
* - One key in two or more fragments is a fault, also when the records are equal. The key of a direct use is its resource and its need.
|
|
510
|
+
*
|
|
511
|
+
* The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.
|
|
512
|
+
*
|
|
513
|
+
* @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.
|
|
514
|
+
* @returns The joined layer, or the faults of the join.
|
|
515
|
+
*/
|
|
516
|
+
function joinEndurance(pieces) {
|
|
517
|
+
const levels = joinSetting(pieces, (layer) => layer.levels.length > 0 ? layer.levels.join("\n") : void 0, "levels");
|
|
518
|
+
const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, "resource");
|
|
519
|
+
const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, "store");
|
|
520
|
+
const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, "draw");
|
|
521
|
+
const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, "direct use");
|
|
522
|
+
const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, "converter");
|
|
523
|
+
const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, "case");
|
|
524
|
+
const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, "prior");
|
|
525
|
+
const errors = [
|
|
526
|
+
levels,
|
|
527
|
+
resources,
|
|
528
|
+
stores,
|
|
529
|
+
draws,
|
|
530
|
+
direct,
|
|
531
|
+
converters,
|
|
532
|
+
cases,
|
|
533
|
+
priors
|
|
534
|
+
].flatMap((join) => join.errors);
|
|
535
|
+
if (errors.length > 0) return {
|
|
536
|
+
ok: false,
|
|
537
|
+
errors
|
|
538
|
+
};
|
|
539
|
+
const has = (key) => pieces.some((piece) => piece.layer[key] !== void 0);
|
|
540
|
+
return {
|
|
541
|
+
ok: true,
|
|
542
|
+
layer: {
|
|
543
|
+
schema: ENDURANCE_SCHEMA,
|
|
544
|
+
levels: levels.value === void 0 ? [] : levels.value.split("\n"),
|
|
545
|
+
resources: resources.items,
|
|
546
|
+
stores: stores.items,
|
|
547
|
+
draws: draws.items,
|
|
548
|
+
...has("direct") ? { direct: direct.items } : {},
|
|
549
|
+
...has("converters") ? { converters: converters.items } : {},
|
|
550
|
+
...has("cases") ? { cases: cases.items } : {},
|
|
551
|
+
...has("priors") ? { priors: priors.items } : {}
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
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 };
|
|
556
|
+
|
|
557
|
+
//# sourceMappingURL=join-D7KyUpGf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-D7KyUpGf.js","names":[],"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 { dayNumber, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./endurance.ts\";\nimport type { Converter, EnduranceLayer, Survival } 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`, which is a warning.\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 */\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] = [\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];\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\n/** This function gives the first fault of a survival curve, or `undefined`. */\nexport function curveFault(curve: Survival): string | undefined {\n const first = curve[0];\n if (first === undefined || first[0] !== 0 || first[1] !== 1) return \"The curve does not start at [0, 1].\";\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (!(Number.isFinite(t1) && t1 > t0)) return `The days of the point ${String(index)} are not more than the days of the point before it.`;\n if (!(p1 >= 0 && p1 <= p0)) return `The chance of the point ${String(index)} is not from 0 to the chance of the point before it.`;\n }\n if (curve[curve.length - 1]?.[1] !== 0) return \"The curve does not end at a chance of 0.\";\n return undefined;\n}\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 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 { 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 * - One key in two or more fragments is a fault, also when the records are equal. 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 const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\");\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;CACX,IAAI,YAAY,MAAM;CACtB,IAAI,WAAW,MAAM;CACrB,IAAI;CACJ,IAAI,SAAS;CACb,KAAK,IAAI,OAAO,GAAG,OAAO,OAAO,OAAO,MAAM,QAAgB,MAAM,QAAQ,GAAG;EAC7E,MAAM,QAAQ,OAAO;EACrB,IAAI;EACJ,IAAI,QAAQ,KAAK,MAAM,QAAQ;OAC1B,IAAI,WAAW,KAAA,KAAa,OAAO,QAAQ,WAAW,IAAI,OAAQ,aAAa,OAAO,IAAI,SAAU,OAAO,QAAQ;OACnH,IAAI,QAAQ,IAAI,YAAY;EAEjC,MAAM,WAAW,CAAC,UAAU,IAAI;EAChC,IAAI,EAAE,IAAI,OAAO,KAAK,MAAM,QAAQ;EACpC,MAAM,QAAQ,MAAM,IAAI,YAAY;EACpC,MAAM,UAAU,EAAE,IAAI;EACtB,IAAI,SAAS,IAAI;EACjB,SAAS,SAAS;EAClB,MAAM,QAAQ,QAAQ,CAAC;EACvB,IAAI,KAAK,KAAK,GAAG;GACf,MAAM;GACN,OAAO,MAAM;GAEb,IAAI,MAAM,QAAQ,KAAK,YAAY,CAAC,SAAS;EAC/C,OAAO;GACL,SAAS;IAAE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