@mark1russell7/stack-endurance 0.8.7 → 0.8.8

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/build/add-on.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as checkEndurance, t as joinEndurance } from "./join-DdVFmRh6.js";
1
+ import { r as checkEndurance, t as joinEndurance } from "./join-BJJdchyI.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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBASiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0LxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBC7P7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+BK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCNtG,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBClDhF,SAAS,OAAO,UAAU,cAAc;;;;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kBxB,kBAAkB"}
1
+ {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAUiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuLxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBC3P7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+BK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCNtG,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBClDhF,SAAS,OAAO,UAAU,cAAc;;;;;;;;;;iBAqBvC,yBAAyB,KAAK,gCAAgC,KAAK;;WAEzE;;iBAGM,yBAAyB;;WAE/B;;;;;;wBAqBK,iBAAiB,OAAO,UAAU;;wBAWlC,WAAW,OAAO;;wBAKlB,SAAS,OAAO;;;;;;;;;;;;;;;;wBAoDhB,UAAU,iBAAiB,YAAY,QAAQ,sCAAsC;;;;;;;;wBAiBrF,YAAY,iBAAiB,aAAa;;;;;qBAU7C;;;;;wBAMG,aAAa,eAAe,QAAQ;;;;;;;;;;wBA8BpC,UAAU,iBAAiB,YAAY,mDAAmD;;qBAiB7F;;;;;;qBAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6BG,gBAAgB,iBAAiB,YAAY,kDAAkD,mBAAyC;;;;;iBAiKvI;WACN,OAAO;;WAEP,aAAa;WACb,OAAO;;;;;WAKP;;WAEA;;;;;;WAMA,OAAOA;;;;;;;;;;;;;;;;wBAmEF,WAAW,UAAU,UAAU,MAAM,MAAM,UAAS,mBAAwB;;iBAM3E;;;;;WAKN,QAAQ,SAAS;;WAEjB,aAAa,SAAS;;WAEtB,OAAO,SAAS;;;;;WAKhB;;WAEA;;WAEA;;;;;;;;;WASA,OAAOA;;;;;;;;;;;;wBAiBF,cAAc,OAAO,gBAAgB,UAAU,UAAU,WAAW,WAAW,UAAS,mBAAwB;;iBA8B/G,sBAAsB;WAC5B;;WAEA;aAA2B;aAAuB;aAAuB,WAAW;aAAoB,WAAW;;;;;;;;;;;;;;;;;wBAiB9G,cAAc,OAAO,gBAAgB,eAAe,SAAS,cAAc,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;qBCrjBjG;;YAmCD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBAiJtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBC7MnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
package/build/index.js CHANGED
@@ -1,161 +1,9 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
- import { _ as deviceKey, a as hasEnduranceError, c as drawDemand, d as giftResource, f as storeAmounts, g as canRun, h as exact, i as curveFault, l as enduranceOf, m as dense, n as ENDURANCE_CODES, o as caseDraws, p as addTo, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed, v as inputsOf } from "./join-DdVFmRh6.js";
2
+ import { S as exact, _ as fewestRow, a as hasEnduranceError, b as addTo, c as drawDemand, d as giftResource, f as storeAmounts, g as drawBlock, h as deviceUse, i as curveFault, l as enduranceOf, m as caseParts, n as ENDURANCE_CODES, o as caseDraws, p as Program, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed, v as reachOf, x as dense, y as valueAt } from "./join-BJJdchyI.js";
3
3
  import { DEFAULT_MAX_SETS, STACK_SCHEMA, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
4
- import { solveLexicographic } from "@mark1russell7/linear";
5
4
  import { ONE, ZERO, add, div, equals, mul, neg, sign, sub, toNumber } from "@mark1russell7/rational";
5
+ import { solveLexicographic } from "@mark1russell7/linear";
6
6
  import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
7
- // src/program.ts
8
- /** A program in construction: the count of its variables and its rows. */
9
- var Program = class {
10
- count = 0;
11
- rows = [];
12
- /** This method adds a variable and gives its index. */
13
- next() {
14
- return this.count++;
15
- }
16
- /** This method adds a row and gives its index. */
17
- push(row, relation, rhs) {
18
- this.rows.push({
19
- row,
20
- relation,
21
- rhs
22
- });
23
- return this.rows.length - 1;
24
- }
25
- /** This method gives the dense rows for `solveLexicographic`. */
26
- constraints() {
27
- return this.rows.map(({ row, relation, rhs }) => ({
28
- coefficients: dense(row, this.count),
29
- relation,
30
- rhs
31
- }));
32
- }
33
- };
34
- /** This function gives the parts of a case for the draws of `needs`. */
35
- function caseParts(layer, stoppedParts, stock, needs) {
36
- const direct = (layer.direct ?? []).filter((use) => needs.has(use.need) && use.amount > 0);
37
- const live = (layer.converters ?? []).filter((converter) => canRun(converter, stoppedParts));
38
- const cooks = live.filter((converter) => needs.has(giftNeed(converter) ?? ""));
39
- const makers = live.filter((converter) => giftResource(converter) !== void 0);
40
- const resources = /* @__PURE__ */ new Set([...direct.map((use) => use.resource), ...[...cooks, ...makers].flatMap((converter) => [...inputsOf(converter).keys()])]);
41
- for (const maker of makers) resources.add(giftResource(maker) ?? "");
42
- return {
43
- stock,
44
- direct,
45
- cooks,
46
- makers,
47
- resources,
48
- stocked: [...resources].filter((resource) => (stock.get(resource) ?? 0) > 0).sort()
49
- };
50
- }
51
- /**
52
- * This function adds the columns of one draw to a program, and the balance row of each of its resources.
53
- * In a balance row, the takes of the draw are not more than its share of the stock plus the gifts of its makers.
54
- * The caller adds the row of the need, with the term of the days.
55
- *
56
- * @param stocked - False for a draw that takes no stock. Its shares are not columns.
57
- */
58
- function drawBlock(program, parts, draw, stocked = true) {
59
- const gifts = /* @__PURE__ */ new Map();
60
- const balance = new Map([...parts.resources].map((resource) => [resource, /* @__PURE__ */ new Map()]));
61
- const consume = (resource, index, amount) => addTo(balance.get(resource), index, amount);
62
- for (const use of parts.direct) {
63
- if (use.need !== draw.need) continue;
64
- const index = program.next();
65
- addTo(gifts, index, exact(use.amount));
66
- consume(use.resource, index, ONE);
67
- }
68
- const runs = /* @__PURE__ */ new Map();
69
- for (const cook of parts.cooks) {
70
- if (giftNeed(cook) !== draw.need) continue;
71
- const index = program.next();
72
- runs.set(cook, index);
73
- addTo(gifts, index, exact(cook.gives.amount));
74
- for (const [resource, each] of inputsOf(cook)) consume(resource, index, exact(each));
75
- }
76
- for (const maker of parts.makers) {
77
- const index = program.next();
78
- runs.set(maker, index);
79
- for (const [resource, each] of inputsOf(maker)) consume(resource, index, exact(each));
80
- consume(giftResource(maker), index, neg(exact(maker.gives.amount)));
81
- }
82
- const shares = new Map(stocked ? parts.stocked.map((resource) => [resource, program.next()]) : []);
83
- for (const [resource, index] of shares) consume(resource, index, neg(ONE));
84
- for (const row of balance.values()) if (row.size > 0) program.push(row, "<=", ZERO);
85
- return {
86
- draw,
87
- gifts,
88
- shares,
89
- runs
90
- };
91
- }
92
- /**
93
- * This function gives the device-days of each device of a set of run columns, by the key of the device (`deviceKey`).
94
- * One run uses `1 / perDay` of a day of one device. The converters of one device share one limit. A converter with no device has a limit of its own.
95
- * A converter with no limit `perDay` is not in the record. The list `stopped` has the columns of the converters with a limit of 0.
96
- */
97
- function deviceUse(runs) {
98
- const limits = /* @__PURE__ */ new Map();
99
- const stopped = [];
100
- for (const [converter, index] of runs) {
101
- if (converter.perDay === void 0) continue;
102
- if (!(converter.perDay > 0)) {
103
- stopped.push(index);
104
- continue;
105
- }
106
- const key = deviceKey(converter);
107
- const limit = limits.get(key) ?? {
108
- row: /* @__PURE__ */ new Map(),
109
- devices: converter.devices ?? 1,
110
- converters: []
111
- };
112
- limits.set(key, limit);
113
- if (!limit.converters.includes(converter)) limit.converters.push(converter);
114
- addTo(limit.row, index, div(ONE, exact(converter.perDay)));
115
- }
116
- return {
117
- limits,
118
- stopped
119
- };
120
- }
121
- /**
122
- * This function gives the row of the fewest device-days of a set of run columns: the runs over `perDay`, or the runs with no limit.
123
- * As an objective, it gives no more runs than the plan uses.
124
- */
125
- function fewestRow(runs) {
126
- const out = /* @__PURE__ */ new Map();
127
- for (const [converter, index] of runs) addTo(out, index, converter.perDay !== void 0 && converter.perDay > 0 ? div(ONE, exact(converter.perDay)) : ONE);
128
- return out;
129
- }
130
- /** This function gives the value of a sparse row at the point `x`. */
131
- function valueAt(row, x) {
132
- let out = ZERO;
133
- for (const [index, value] of row) out = add(out, mul(value, x[index] ?? ZERO));
134
- return out;
135
- }
136
- /**
137
- * This function gives each resource that a draw can use: the resources of its direct uses and the inputs of its cooks.
138
- * It also gives the inputs of their makers, through each chain.
139
- */
140
- function inputClosure(direct, cooks, makers) {
141
- const out = /* @__PURE__ */ new Set();
142
- const queue = [...direct, ...cooks.flatMap((cook) => [...inputsOf(cook).keys()])];
143
- for (let resource = queue.shift(); resource !== void 0; resource = queue.shift()) {
144
- if (out.has(resource)) continue;
145
- out.add(resource);
146
- for (const maker of makers) if (giftResource(maker) === resource) queue.push(...inputsOf(maker).keys());
147
- }
148
- return out;
149
- }
150
- /** This function gives the resources that the draws of `needs` can use, and the converters that they can use. */
151
- function reachOf(parts, needs) {
152
- const cooks = parts.cooks.filter((cook) => needs.has(giftNeed(cook) ?? ""));
153
- const closure = inputClosure(parts.direct.filter((use) => needs.has(use.need)).map((use) => use.resource), cooks, parts.makers);
154
- return {
155
- closure,
156
- reach: /* @__PURE__ */ new Set([...cooks, ...parts.makers.filter((maker) => closure.has(giftResource(maker) ?? ""))])
157
- };
158
- }
159
7
  // src/joint.ts
160
8
  /**
161
9
  * This function gives the joint days of a set of draws. These are the largest count of days `d` at which each draw holds `d` days.
@@ -450,7 +298,8 @@ function buildStep(parts, caseCuts, draws, fixed, open, devices, mode) {
450
298
  for (const draw of draws) {
451
299
  const fix = fixed.get(draw.need);
452
300
  if (fix === void 0 && !opened.has(draw.need)) continue;
453
- const block = drawBlock(program, parts, draw, !(fix?.endless ?? mode === "day"));
301
+ const endless = fix?.endless ?? mode === "day";
302
+ const block = drawBlock(program, parts, draw, !endless);
454
303
  blocks.push(block);
455
304
  const demand = exact(drawDemand(draw, caseCuts));
456
305
  const need = new Map(block.gifts);