@mark1russell7/stack-endurance 0.8.19 → 0.8.20
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 +12 -1
- package/build/add-on.d.ts +1 -1
- package/build/add-on.js +1 -1
- package/build/index.d.ts +36 -7
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -5
- package/build/index.js.map +1 -1
- package/build/{join-Du2gsJJ6.js → join-BB1qLU4e.js} +177 -49
- package/build/join-BB1qLU4e.js.map +1 -0
- package/build/{layer-BCQy77mt.d.ts → layer-CsVKqL3L.d.ts} +11 -2
- package/build/layer-CsVKqL3L.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 +1 -0
- package/build/schema.js.map +1 -1
- package/package.json +1 -1
- package/build/join-Du2gsJJ6.js.map +0 -1
- package/build/layer-BCQy77mt.d.ts.map +0 -1
|
@@ -11,9 +11,21 @@ function inputsOf(converter) {
|
|
|
11
11
|
for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);
|
|
12
12
|
return out;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* This function tells if a converter is a source (M2-solar): it takes nothing, and it has a limit `perDay` more than 0.
|
|
16
|
+
* Its runs of a day are lost when no draw uses them. Thus a take uses a source before a store.
|
|
17
|
+
*/
|
|
18
|
+
function isSource(converter) {
|
|
19
|
+
if (!(converter.perDay !== void 0 && converter.perDay > 0)) return false;
|
|
20
|
+
for (const input of converter.takes) if (input.amount > 0) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This function tells if a converter can run in a case. Its device works, it takes a resource or it is a source, and it
|
|
25
|
+
* gives an amount more than 0.
|
|
26
|
+
*/
|
|
15
27
|
function canRun(converter, stoppedParts) {
|
|
16
|
-
return converter.gives.amount > 0 && inputsOf(converter).size > 0 && (converter.device === void 0 || !stoppedParts.has(converter.device));
|
|
28
|
+
return converter.gives.amount > 0 && (inputsOf(converter).size > 0 || isSource(converter)) && (converter.device === void 0 || !stoppedParts.has(converter.device));
|
|
17
29
|
}
|
|
18
30
|
/**
|
|
19
31
|
* This function gives the key of the device-days that a converter uses. The converters of one device share one key.
|
|
@@ -295,17 +307,23 @@ function seasonPlan(supply, parts, caseCuts, draws, devices) {
|
|
|
295
307
|
origin: lot.origin
|
|
296
308
|
}))];
|
|
297
309
|
const inside = (day) => day > 0 && day < supply.horizon;
|
|
310
|
+
const shares = monthlyShares([...all.cooks, ...all.makers]);
|
|
311
|
+
const months = shares.size === 0 ? [] : monthEdges(supply.start, supply.horizon);
|
|
312
|
+
const edges = [.../* @__PURE__ */ new Set([
|
|
313
|
+
0,
|
|
314
|
+
supply.horizon,
|
|
315
|
+
...months,
|
|
316
|
+
...lots.flatMap((lot) => [lot.day, lot.spoils]).filter(inside)
|
|
317
|
+
])].sort((a, b) => a - b);
|
|
298
318
|
return {
|
|
299
319
|
parts: all,
|
|
300
320
|
caseCuts,
|
|
301
321
|
draws,
|
|
302
322
|
devices,
|
|
303
323
|
lots,
|
|
304
|
-
edges
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
...lots.flatMap((lot) => [lot.day, lot.spoils]).filter(inside)
|
|
308
|
-
])].sort((a, b) => a - b)
|
|
324
|
+
edges,
|
|
325
|
+
shares,
|
|
326
|
+
months: edges.slice(0, -1).map((edge) => shares.size === 0 ? 0 : monthOf(supply.start, edge))
|
|
309
327
|
};
|
|
310
328
|
}
|
|
311
329
|
const edgeOf = (plan, index) => exact(plan.edges[index] ?? 0);
|
|
@@ -386,9 +404,13 @@ function addFixed(program, plan, fixed, cells) {
|
|
|
386
404
|
}
|
|
387
405
|
return kept;
|
|
388
406
|
}
|
|
389
|
-
/**
|
|
407
|
+
/** The share of the device-days of a key in a segment (M2-solar): its share `monthly` in the month of the segment, or 1. */
|
|
408
|
+
function shareIn(plan, segment, key) {
|
|
409
|
+
return shareOf(plan.shares, key, plan.months[segment] ?? 0);
|
|
410
|
+
}
|
|
411
|
+
/** This function gives the device-days of each day that the fixed draws leave in a segment: the devices times the share, less the kept device-days. */
|
|
390
412
|
function roomOf(plan, kept, segment, key, devices) {
|
|
391
|
-
const left = sub(exact(plan.devices.get(key) ?? devices), kept.get(segment)?.get(key) ?? ZERO);
|
|
413
|
+
const left = sub(mul(exact(plan.devices.get(key) ?? devices), exact(shareIn(plan, segment, key))), kept.get(segment)?.get(key) ?? ZERO);
|
|
392
414
|
return sign(left) > 0 ? left : ZERO;
|
|
393
415
|
}
|
|
394
416
|
/**
|
|
@@ -672,7 +694,10 @@ function seasonBest(plan, fixed, levels, stored) {
|
|
|
672
694
|
if (sign(fed) <= 0) continue;
|
|
673
695
|
const into = perDay.get(cell.draw.need) ?? /* @__PURE__ */ new Map();
|
|
674
696
|
perDay.set(cell.draw.need, into);
|
|
675
|
-
for (const [key, limit] of deviceUse(cell.block.runs).limits)
|
|
697
|
+
for (const [key, limit] of deviceUse(cell.block.runs).limits) {
|
|
698
|
+
const share = shareIn(plan, cell.segment, key);
|
|
699
|
+
if (share > 0) into.set(key, Math.max(into.get(key) ?? 0, toNumber(div(valueAt(limit.row, x), fed)) / share));
|
|
700
|
+
}
|
|
676
701
|
}
|
|
677
702
|
return {
|
|
678
703
|
needs,
|
|
@@ -715,14 +740,16 @@ function seasonJoint(plan, stored) {
|
|
|
715
740
|
*
|
|
716
741
|
* @param stock - The stocks that the higher draws leave.
|
|
717
742
|
* @param lots - The rest of each harvest lot that the higher draws leave.
|
|
718
|
-
* @param room - The device-days of each day that the higher draws leave, by the key of the device
|
|
743
|
+
* @param room - The device-days of each day that the higher draws leave, by the key of the device, before the shares `monthly`.
|
|
744
|
+
* @param start - The first day of the event, for the months of the shares.
|
|
719
745
|
*/
|
|
720
|
-
function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, room) {
|
|
746
|
+
function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, room, start) {
|
|
721
747
|
const supply = {
|
|
722
748
|
stock: new Map(stock),
|
|
723
749
|
harvests: [],
|
|
724
750
|
lots,
|
|
725
|
-
horizon
|
|
751
|
+
horizon,
|
|
752
|
+
start
|
|
726
753
|
};
|
|
727
754
|
const plan = seasonPlan(supply, caseParts(layer, stoppedParts, supply.stock, /* @__PURE__ */ new Set([draw.need])), caseCuts, [draw], room);
|
|
728
755
|
const fixed = /* @__PURE__ */ new Map();
|
|
@@ -823,6 +850,38 @@ function dayOf(date) {
|
|
|
823
850
|
if (day === void 0) throw new RangeError(`The date "${date}" is not a date YYYY-MM-DD.`);
|
|
824
851
|
return day;
|
|
825
852
|
}
|
|
853
|
+
const DAY_MS = 864e5;
|
|
854
|
+
/** This function gives the month of the day `day` after the start, 0 for January (M2-solar). It throws a `RangeError` for a bad date. */
|
|
855
|
+
function monthOf(start, day) {
|
|
856
|
+
dayOf(start);
|
|
857
|
+
return new Date(Date.parse(`${start}T00:00:00Z`) + Math.floor(day) * DAY_MS).getUTCMonth();
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* This function gives the days from the start to the first day of each month, in increasing order (M2-solar). Each
|
|
861
|
+
* day is more than 0 and less than the horizon. It throws a `RangeError` for a date that is not `YYYY-MM-DD`.
|
|
862
|
+
*/
|
|
863
|
+
function monthEdges(start, horizon) {
|
|
864
|
+
dayOf(start);
|
|
865
|
+
const first = Date.parse(`${start}T00:00:00Z`);
|
|
866
|
+
const date = new Date(first);
|
|
867
|
+
const out = [];
|
|
868
|
+
for (let month = date.getUTCMonth() + 1;; month += 1) {
|
|
869
|
+
const day = Math.round((Date.UTC(date.getUTCFullYear(), month, 1) - first) / DAY_MS);
|
|
870
|
+
if (!(day < horizon)) break;
|
|
871
|
+
out.push(day);
|
|
872
|
+
}
|
|
873
|
+
return out;
|
|
874
|
+
}
|
|
875
|
+
/** This function gives the shares `monthly` of each device key of the converters with a limit and shares (M2-solar). */
|
|
876
|
+
function monthlyShares(converters) {
|
|
877
|
+
const out = /* @__PURE__ */ new Map();
|
|
878
|
+
for (const converter of converters) if (converter.monthly !== void 0 && converter.perDay !== void 0) out.set(deviceKey(converter), converter.monthly);
|
|
879
|
+
return out;
|
|
880
|
+
}
|
|
881
|
+
/** This function gives the share of the device-days of a key in a month: its share `monthly`, or 1. */
|
|
882
|
+
function shareOf(shares, key, month) {
|
|
883
|
+
return shares.get(key)?.[month] ?? 1;
|
|
884
|
+
}
|
|
826
885
|
/**
|
|
827
886
|
* This function gives the amount of each resource in the stores at a date, by the code of the resource.
|
|
828
887
|
*
|
|
@@ -872,10 +931,15 @@ function makersOf(layer, stoppedParts) {
|
|
|
872
931
|
return out;
|
|
873
932
|
}
|
|
874
933
|
function waysOf(layer, need, stoppedParts, makers) {
|
|
934
|
+
const converters = (layer.converters ?? []).filter((converter) => giftNeed(converter) === need && canRun(converter, stoppedParts));
|
|
935
|
+
const sources = converters.filter(isSource);
|
|
875
936
|
return {
|
|
876
937
|
direct: (layer.direct ?? []).filter((use) => use.need === need && use.amount > 0),
|
|
877
|
-
converters
|
|
878
|
-
makers
|
|
938
|
+
converters,
|
|
939
|
+
makers,
|
|
940
|
+
sources,
|
|
941
|
+
others: sources.length === 0 ? converters : converters.filter((converter) => !isSource(converter)),
|
|
942
|
+
open: [.../* @__PURE__ */ new Set([...sources, ...[...makers.values()].flat().filter(isSource)])]
|
|
879
943
|
};
|
|
880
944
|
}
|
|
881
945
|
const NO_PATH = /* @__PURE__ */ new Set();
|
|
@@ -914,15 +978,25 @@ function mostRuns(left, makers, converter, path) {
|
|
|
914
978
|
* It changes `left`, and it gives the amount that it could not take.
|
|
915
979
|
*/
|
|
916
980
|
function takeResource(left, makers, resource, amount, path) {
|
|
981
|
+
let rest = amount;
|
|
982
|
+
const ways = path.has(resource) ? void 0 : makers.get(resource);
|
|
983
|
+
let next;
|
|
984
|
+
if (ways !== void 0 && ways.some(isSource)) {
|
|
985
|
+
next = new Set(path).add(resource);
|
|
986
|
+
for (const maker of ways) {
|
|
987
|
+
if (rest <= 0) break;
|
|
988
|
+
if (isSource(maker)) rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
917
991
|
const has = left.get(resource) ?? 0;
|
|
918
|
-
const got = Math.min(
|
|
992
|
+
const got = Math.min(Math.max(0, rest), has);
|
|
919
993
|
left.set(resource, has - got);
|
|
920
|
-
|
|
921
|
-
if (rest <= 0 ||
|
|
922
|
-
|
|
923
|
-
for (const maker of
|
|
994
|
+
rest -= got;
|
|
995
|
+
if (rest <= 0 || ways === void 0) return Math.max(0, rest);
|
|
996
|
+
next ??= new Set(path).add(resource);
|
|
997
|
+
for (const maker of ways) {
|
|
924
998
|
if (rest <= 0) break;
|
|
925
|
-
rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;
|
|
999
|
+
if (!isSource(maker)) rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;
|
|
926
1000
|
}
|
|
927
1001
|
return Math.max(0, rest);
|
|
928
1002
|
}
|
|
@@ -968,12 +1042,16 @@ function run(left, makers, converter, wanted, path) {
|
|
|
968
1042
|
*/
|
|
969
1043
|
function take(left, ways, amount) {
|
|
970
1044
|
let rest = amount;
|
|
1045
|
+
for (const converter of ways.sources) {
|
|
1046
|
+
if (rest <= 0) break;
|
|
1047
|
+
rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;
|
|
1048
|
+
}
|
|
971
1049
|
for (const use of ways.direct) {
|
|
972
1050
|
if (rest <= 0) break;
|
|
973
1051
|
const wanted = rest / use.amount;
|
|
974
1052
|
rest -= (wanted - takeResource(left, ways.makers, use.resource, wanted, NO_PATH)) * use.amount;
|
|
975
1053
|
}
|
|
976
|
-
for (const converter of ways.
|
|
1054
|
+
for (const converter of ways.others) {
|
|
977
1055
|
if (rest <= 0) break;
|
|
978
1056
|
rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;
|
|
979
1057
|
}
|
|
@@ -1107,7 +1185,8 @@ function sowings(layer, stoppedParts, stock, makers, start, horizon) {
|
|
|
1107
1185
|
function seasonSupply(layer, stoppedParts, options) {
|
|
1108
1186
|
const stock = storeAmounts(layer, options.at, stoppedParts);
|
|
1109
1187
|
const horizon = seasonHorizon(options.horizon);
|
|
1110
|
-
const
|
|
1188
|
+
const start = options.start ?? options.at;
|
|
1189
|
+
const sown = sowings(layer, stoppedParts, stock, makersOf(layer, stoppedParts), start, horizon);
|
|
1111
1190
|
const lots = sown.lots.filter((lot) => lot.day < horizon && lot.left > 0).sort((a, b) => a.day - b.day).map((lot) => ({
|
|
1112
1191
|
resource: lot.resource,
|
|
1113
1192
|
day: lot.day,
|
|
@@ -1118,12 +1197,17 @@ function seasonSupply(layer, stoppedParts, options) {
|
|
|
1118
1197
|
stock,
|
|
1119
1198
|
harvests: sown.harvests,
|
|
1120
1199
|
lots,
|
|
1121
|
-
horizon
|
|
1200
|
+
horizon,
|
|
1201
|
+
start
|
|
1122
1202
|
};
|
|
1123
1203
|
}
|
|
1124
|
-
/**
|
|
1204
|
+
/**
|
|
1205
|
+
* This function tells if a layer has a converter with a season, with shares `monthly` or a source (M2-solar) that can run
|
|
1206
|
+
* in a case. Such a layer needs the queries in segments of days to a horizon. A harvest, a spoil day and the start of a
|
|
1207
|
+
* month end a segment. A source can feed a draw with no end, thus the horizon is the upper limit of its days.
|
|
1208
|
+
*/
|
|
1125
1209
|
function hasSeason(layer, stoppedParts) {
|
|
1126
|
-
return (layer.converters ?? []).some((converter) => converter.season !== void 0 && canRun(converter, stoppedParts));
|
|
1210
|
+
return (layer.converters ?? []).some((converter) => (converter.season !== void 0 || converter.monthly !== void 0 || isSource(converter)) && canRun(converter, stoppedParts));
|
|
1127
1211
|
}
|
|
1128
1212
|
/**
|
|
1129
1213
|
* This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.
|
|
@@ -1153,6 +1237,9 @@ function hasSeason(layer, stoppedParts) {
|
|
|
1153
1237
|
* A lower draw gets the stocks that the higher draws leave, the earliest stocks first taken. This is the safe side.
|
|
1154
1238
|
* - A draw with a shared device and a season gets the programs of `bestEndurance` for itself alone (M2-grow-share-sweep). Its stocks,
|
|
1155
1239
|
* its harvest lots and its device-days are those that the higher draws leave. It has no field `spoiled`.
|
|
1240
|
+
* - A source (M2-solar) takes nothing and has a limit `perDay`. A take uses it first: its runs of a day are lost when no
|
|
1241
|
+
* draw uses them. With shares `monthly`, the device-days of a day are the devices times the share of its month. Each
|
|
1242
|
+
* span also ends at the start of a month, and a draw can hold again from the start of a month.
|
|
1156
1243
|
*
|
|
1157
1244
|
* 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.
|
|
1158
1245
|
*
|
|
@@ -1170,6 +1257,11 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1170
1257
|
const stocked = new Set(layer.stores.map((store) => store.resource));
|
|
1171
1258
|
const limited = (layer.converters ?? []).filter((converter) => converter.perDay !== void 0 && canRun(converter, stoppedParts));
|
|
1172
1259
|
const devices = new Map(limited.map((converter) => [deviceKey(converter), converter.devices ?? 1]));
|
|
1260
|
+
const monthShares = monthlyShares(limited);
|
|
1261
|
+
const begin = options.start ?? options.at;
|
|
1262
|
+
const shareAt = (key, at) => monthShares.size === 0 ? 1 : shareOf(monthShares, key, monthOf(begin, at));
|
|
1263
|
+
const months = monthShares.size === 0 || supply === void 0 ? [] : monthEdges(begin, supply.horizon);
|
|
1264
|
+
const nextMonth = (at) => months.find((day) => day > at) ?? 1e400;
|
|
1173
1265
|
const used = /* @__PURE__ */ new Map();
|
|
1174
1266
|
let before = new Map(start);
|
|
1175
1267
|
const horizon = supply?.horizon ?? 1e400;
|
|
@@ -1182,17 +1274,17 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1182
1274
|
const room = new Map([...devices].map(([key, count]) => [key, Math.max(0, count - (used.get(key) ?? 0))]));
|
|
1183
1275
|
const closure = inputClosure(ways);
|
|
1184
1276
|
const reach = /* @__PURE__ */ new Set([...ways.converters, ...[...closure].flatMap((resource) => makers.get(resource) ?? [])]);
|
|
1185
|
-
const after = (stock, days) => {
|
|
1277
|
+
const after = (stock, days, at = 0) => {
|
|
1186
1278
|
const tried = new Map(stock);
|
|
1187
|
-
for (const [key, free] of room) tried.set(RUNS + key, free * days);
|
|
1279
|
+
for (const [key, free] of room) tried.set(RUNS + key, free * shareAt(key, at) * days);
|
|
1188
1280
|
return {
|
|
1189
1281
|
left: tried,
|
|
1190
1282
|
short: take(tried, ways, days * demand)
|
|
1191
1283
|
};
|
|
1192
1284
|
};
|
|
1193
|
-
const span = (stock, limit, bound) => {
|
|
1285
|
+
const span = (stock, limit, bound, at = 0) => {
|
|
1194
1286
|
const fit = largestFit(Math.min(limit, bound / demand), (days) => {
|
|
1195
|
-
const tried = after(stock, days);
|
|
1287
|
+
const tried = after(stock, days, at);
|
|
1196
1288
|
return {
|
|
1197
1289
|
short: tried.short,
|
|
1198
1290
|
need: days * demand,
|
|
@@ -1201,7 +1293,7 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1201
1293
|
});
|
|
1202
1294
|
return {
|
|
1203
1295
|
days: fit.x,
|
|
1204
|
-
left: fit.value ?? after(stock, fit.x).left
|
|
1296
|
+
left: fit.value ?? after(stock, fit.x, at).left
|
|
1205
1297
|
};
|
|
1206
1298
|
};
|
|
1207
1299
|
const shares = sharesDevice(reach);
|
|
@@ -1212,7 +1304,7 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1212
1304
|
spoils: lot.spoils,
|
|
1213
1305
|
amount: lot.amount
|
|
1214
1306
|
}));
|
|
1215
|
-
const held = seasonDraw(layer, stoppedParts, caseCuts, draw, resourcesOnly(before), lots, horizon, room);
|
|
1307
|
+
const held = seasonDraw(layer, stoppedParts, caseCuts, draw, resourcesOnly(before), lots, horizon, room, begin);
|
|
1216
1308
|
needs[draw.need] = held.need;
|
|
1217
1309
|
for (const [key, each] of held.perDay) used.set(key, (used.get(key) ?? 0) + each);
|
|
1218
1310
|
before = held.stock;
|
|
@@ -1238,13 +1330,16 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1238
1330
|
const again = [];
|
|
1239
1331
|
let atHorizon = false;
|
|
1240
1332
|
const perDay = /* @__PURE__ */ new Map();
|
|
1241
|
-
const count = (spanLeft, days) => {
|
|
1333
|
+
const count = (spanLeft, days, at = 0) => {
|
|
1242
1334
|
if (days > 0) for (const [key, free] of room) {
|
|
1243
|
-
const
|
|
1335
|
+
const share = shareAt(key, at);
|
|
1336
|
+
if (!(share > 0)) continue;
|
|
1337
|
+
const each = (free * share * days - (spanLeft.get(RUNS + key) ?? 0)) / days / share;
|
|
1244
1338
|
perDay.set(key, perDay.has(key) ? Math.max(perDay.get(key), each) : each);
|
|
1245
1339
|
}
|
|
1246
1340
|
};
|
|
1247
1341
|
let spanDays;
|
|
1342
|
+
let spanAt = 0;
|
|
1248
1343
|
if (share !== void 0) {
|
|
1249
1344
|
low = share.days;
|
|
1250
1345
|
spanDays = low;
|
|
@@ -1294,9 +1389,9 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1294
1389
|
advance();
|
|
1295
1390
|
for (;;) {
|
|
1296
1391
|
const spoil = Math.min(...pool.filter((lot) => lot.left > 0).map((lot) => lot.spoils));
|
|
1297
|
-
const end = Math.min(next < later.length ? later[next].day : 1e400, spoil, horizon);
|
|
1298
|
-
const part = span(stock, end - at, capacity(stock, ways));
|
|
1299
|
-
count(part.left, part.days);
|
|
1392
|
+
const end = Math.min(next < later.length ? later[next].day : 1e400, spoil, horizon, nextMonth(at));
|
|
1393
|
+
const part = span(stock, end - at, capacity(stock, ways, shareAt, at), at);
|
|
1394
|
+
count(part.left, part.days, at);
|
|
1300
1395
|
const rest = resourcesOnly(part.left);
|
|
1301
1396
|
useLots(pool, stock, rest);
|
|
1302
1397
|
stock = rest;
|
|
@@ -1305,14 +1400,16 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1305
1400
|
if (first === void 0) first = {
|
|
1306
1401
|
days: stop,
|
|
1307
1402
|
left: part.left,
|
|
1308
|
-
spanDays: part.days
|
|
1403
|
+
spanDays: part.days,
|
|
1404
|
+
spanAt: at
|
|
1309
1405
|
};
|
|
1310
1406
|
else if (stop > resumed) again.push({
|
|
1311
1407
|
from: resumed,
|
|
1312
1408
|
to: stop
|
|
1313
1409
|
});
|
|
1314
|
-
|
|
1315
|
-
|
|
1410
|
+
const resume = Math.min(next < later.length ? later[next].day : 1e400, nextMonth(at));
|
|
1411
|
+
if (!(resume < horizon)) break;
|
|
1412
|
+
at = resume;
|
|
1316
1413
|
resumed = at;
|
|
1317
1414
|
} else {
|
|
1318
1415
|
at = end;
|
|
@@ -1330,6 +1427,7 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1330
1427
|
low = first?.days ?? horizon;
|
|
1331
1428
|
left = first?.left ?? stock;
|
|
1332
1429
|
spanDays = first?.spanDays ?? horizon;
|
|
1430
|
+
spanAt = first?.spanAt ?? 0;
|
|
1333
1431
|
final = stock;
|
|
1334
1432
|
}
|
|
1335
1433
|
const stores = resourcesOnly(left);
|
|
@@ -1341,7 +1439,7 @@ function enduranceOf(layer, caseCuts, options) {
|
|
|
1341
1439
|
}
|
|
1342
1440
|
const spoiled = Object.fromEntries([...lost].filter(([, amount]) => amount > 0));
|
|
1343
1441
|
const runsLeft = (converter) => (daysLeft(left, converter) ?? 0) * (converter.perDay ?? 0);
|
|
1344
|
-
const runsGiven = (converter) => (devices.get(deviceKey(converter)) ?? 1) * (converter.perDay ?? 0) * spanDays;
|
|
1442
|
+
const runsGiven = (converter) => (devices.get(deviceKey(converter)) ?? 1) * shareAt(deviceKey(converter), spanAt) * (converter.perDay ?? 0) * spanDays;
|
|
1345
1443
|
const capped = atHorizon ? [] : 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();
|
|
1346
1444
|
needs[draw.need] = {
|
|
1347
1445
|
days: low,
|
|
@@ -1385,10 +1483,11 @@ function sharesDevice(reach) {
|
|
|
1385
1483
|
return false;
|
|
1386
1484
|
}
|
|
1387
1485
|
/**
|
|
1388
|
-
* This function gives an upper limit of a need that the stores give with no other draw, through each chain.
|
|
1389
|
-
*
|
|
1486
|
+
* This function gives an upper limit of a need that the stores give with no other draw, through each chain. A source
|
|
1487
|
+
* (M2-solar) with a share more than 0 gives no upper limit, thus the limit is Infinity. The span of the sweep is finite.
|
|
1390
1488
|
*/
|
|
1391
|
-
function capacity(start, ways) {
|
|
1489
|
+
function capacity(start, ways, shareAt, at = 0) {
|
|
1490
|
+
for (const converter of ways.open) if ((shareAt === void 0 ? 1 : shareAt(deviceKey(converter), at)) > 0) return 1e400;
|
|
1392
1491
|
let total = 0;
|
|
1393
1492
|
for (const use of ways.direct) total += mostResource(start, ways.makers, use.resource, NO_PATH) * use.amount;
|
|
1394
1493
|
for (const converter of ways.converters) total += mostRuns(start, ways.makers, converter, NO_PATH) * converter.gives.amount;
|
|
@@ -1405,7 +1504,8 @@ function capacity(start, ways) {
|
|
|
1405
1504
|
* - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.
|
|
1406
1505
|
* - `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.
|
|
1407
1506
|
* - `endurance-date`: a date is not a date `YYYY-MM-DD`.
|
|
1408
|
-
* - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.
|
|
1507
|
+
* - `endurance-converter-empty`: a converter takes nothing and has no limit `perDay` more than 0, or it gives an amount of 0.
|
|
1508
|
+
* A converter with a limit can take nothing: it is a source, for example a solar panel. Since 0.8.20 (M2-solar).
|
|
1409
1509
|
* - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.
|
|
1410
1510
|
* Or its days do not increase, or its chance increases.
|
|
1411
1511
|
* - `endurance-bound`: the bound of a cut is not a value of `CUT_BOUNDS` of the core. Since 0.8.4.
|
|
@@ -1419,6 +1519,8 @@ function capacity(start, ways) {
|
|
|
1419
1519
|
* - `endurance-season`: the season of a converter has a day that is not `MM-DD`. Or its delay or its shelf life is not more than 0.
|
|
1420
1520
|
* Or its count of sowings is not a finite number of 0 or more. Or the converter with a season gives a need, or it has
|
|
1421
1521
|
* `perDay` or `devices`. Since 0.8.16 (M2-grow).
|
|
1522
|
+
* - `endurance-monthly`: the shares `monthly` of a converter are not 12 numbers from 0 to 1. Or the converter has
|
|
1523
|
+
* `monthly` and no `perDay`, or a season. Or two converters of one device have different shares. Since 0.8.20 (M2-solar).
|
|
1422
1524
|
*/
|
|
1423
1525
|
const ENDURANCE_CODES = [
|
|
1424
1526
|
"endurance-twice",
|
|
@@ -1436,7 +1538,8 @@ const ENDURANCE_CODES = [
|
|
|
1436
1538
|
"endurance-device-mix",
|
|
1437
1539
|
"endurance-no-way",
|
|
1438
1540
|
"endurance-cut-no-curve",
|
|
1439
|
-
"endurance-season"
|
|
1541
|
+
"endurance-season",
|
|
1542
|
+
"endurance-monthly"
|
|
1440
1543
|
];
|
|
1441
1544
|
/**
|
|
1442
1545
|
* 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.
|
|
@@ -1517,11 +1620,19 @@ function checkEndurance(layer, stack) {
|
|
|
1517
1620
|
range(converter.id, "amount", converter.gives.amount);
|
|
1518
1621
|
const made = giftResource(converter);
|
|
1519
1622
|
if (made !== void 0) resource(converter.id, made);
|
|
1520
|
-
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.`);
|
|
1623
|
+
if (!(converter.perDay !== void 0 && converter.perDay > 0) && !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.`);
|
|
1521
1624
|
part(converter.id, "device", converter.device);
|
|
1522
1625
|
if (converter.perDay !== void 0) range(converter.id, "rate perDay", converter.perDay);
|
|
1523
1626
|
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.`);
|
|
1524
1627
|
if (converter.season !== void 0) for (const message of seasonFaults(converter)) add("error", "endurance-season", converter.id, message);
|
|
1628
|
+
for (const message of monthlyFaults(converter)) add("error", "endurance-monthly", converter.id, message);
|
|
1629
|
+
}
|
|
1630
|
+
const shares = /* @__PURE__ */ new Map();
|
|
1631
|
+
for (const converter of converters) {
|
|
1632
|
+
if (converter.device === void 0 || converter.perDay === void 0) continue;
|
|
1633
|
+
const seen = shares.get(converter.device);
|
|
1634
|
+
if (seen === void 0) shares.set(converter.device, converter);
|
|
1635
|
+
else if (!sameShares(seen.monthly, converter.monthly)) add("error", "endurance-monthly", converter.id, `The converter "${converter.id}" and the converter "${seen.id}" of the device "${converter.device}" have different shares monthly. The converters of one device have the same shares.`);
|
|
1525
1636
|
}
|
|
1526
1637
|
const counts = /* @__PURE__ */ new Map();
|
|
1527
1638
|
for (const converter of converters) {
|
|
@@ -1593,6 +1704,23 @@ function seasonFaults(converter) {
|
|
|
1593
1704
|
if (converter.perDay !== void 0 || converter.devices !== void 0) out.push(`The converter "${converter.id}" has a season and a limit perDay or devices. A converter with a season has no such limit.`);
|
|
1594
1705
|
return out;
|
|
1595
1706
|
}
|
|
1707
|
+
/** This function gives the messages of the faults of the shares `monthly` of a converter (M2-solar). */
|
|
1708
|
+
function monthlyFaults(converter) {
|
|
1709
|
+
const monthly = converter.monthly;
|
|
1710
|
+
if (monthly === void 0) return [];
|
|
1711
|
+
const out = [];
|
|
1712
|
+
if (monthly.length !== 12 || !monthly.every((share) => Number.isFinite(share) && share >= 0 && share <= 1)) out.push(`The shares monthly of "${converter.id}" are not 12 numbers from 0 to 1.`);
|
|
1713
|
+
if (converter.perDay === void 0) out.push(`The converter "${converter.id}" has shares monthly and no limit perDay. The shares are parts of the limit.`);
|
|
1714
|
+
if (converter.season !== void 0) out.push(`The converter "${converter.id}" has shares monthly and a season. A converter has one or the other.`);
|
|
1715
|
+
return out;
|
|
1716
|
+
}
|
|
1717
|
+
/** This function tells if two lists of shares `monthly` are equal. No list is equal to a list of 12 ones. */
|
|
1718
|
+
function sameShares(a, b) {
|
|
1719
|
+
const full = (shares) => shares ?? Array.from({ length: 12 }, () => 1);
|
|
1720
|
+
const left = full(a);
|
|
1721
|
+
const right = full(b);
|
|
1722
|
+
return left.length === right.length && left.every((share, index) => share === right[index]);
|
|
1723
|
+
}
|
|
1596
1724
|
/**
|
|
1597
1725
|
* 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.
|
|
1598
1726
|
* A converter with a season is not part of a cycle: its harvest comes after its sowing, thus a chain of it ends.
|
|
@@ -1675,6 +1803,6 @@ function joinEndurance(pieces) {
|
|
|
1675
1803
|
}
|
|
1676
1804
|
};
|
|
1677
1805
|
}
|
|
1678
|
-
export {
|
|
1806
|
+
export { drawBlock as A, fixStops as C, Program as D, seasonPlan as E, dense as F, exact as I, isSource as L, reachOf as M, valueAt as N, caseParts as O, addTo as P, firstStop as S, seasonJoint as T, seasonSupply as _, hasEnduranceError as a, storeAmounts as b, caseStopped as c, giftNeed as d, giftResource as f, monthlyShares as g, monthOf as h, curveFault as i, fewestRow as j, deviceUse as k, drawDemand as l, monthEdges as m, ENDURANCE_CODES as n, SEASON_HORIZON_DAYS as o, hasSeason as p, checkEndurance as r, caseDraws as s, joinEndurance as t, enduranceOf as u, shareOf as v, seasonBest as w, fewestOpen as x, sowDays as y };
|
|
1679
1807
|
|
|
1680
|
-
//# sourceMappingURL=join-
|
|
1808
|
+
//# sourceMappingURL=join-BB1qLU4e.js.map
|