@mark1russell7/stack-endurance 0.8.17 → 0.8.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/build/add-on.js +1 -1
- package/build/index.d.ts +38 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +478 -7
- package/build/index.js.map +1 -1
- package/build/{join-B7THRfQS.js → join-D4KzcbbY.js} +30 -17
- package/build/join-D4KzcbbY.js.map +1 -0
- package/package.json +1 -1
- package/build/join-B7THRfQS.js.map +0 -1
package/README.md
CHANGED
|
@@ -50,7 +50,10 @@ A converter can have a `season`. It has a window of sow days in each year (`from
|
|
|
50
50
|
- The query reads the sowings up to the horizon (`horizon` of `enduranceOf`, default `SEASON_HORIZON_DAYS` = 730). `start` moves the event in the year, and the stores stay the stores at `at`.
|
|
51
51
|
- `days` is the first stop of a draw. `again` gives the spans after it in which a harvest feeds the draw. `harvests` lists each sowing with its runs and its amount.
|
|
52
52
|
- The shortfall leaves out the fed spans (`heldTail`). For a layer with a season, `yearShortfall` gives the mean over `starts` start dates in the year (default `YEAR_STARTS` = 12). An event can start on any day.
|
|
53
|
-
- `bestEndurance` and `jointDays`
|
|
53
|
+
- Since 0.8.18, `bestEndurance` and `jointDays` read the harvests. The days go in segments that end at each harvest day, at each spoil day and at the horizon. A segment takes only the lots that are ready and not spoiled in all of it.
|
|
54
|
+
- In `bestEndurance`, `days` is the first stop of each draw, with the same share by level and leximin. A last program gives the most fed days after the stops to each level (`again`). Two draws that use one limited device after their stops take turns on it. This is the safe side.
|
|
55
|
+
- `jointDays` gives the largest common first stop. With `atHorizon`, the plan holds the horizon.
|
|
56
|
+
- `enduranceOf` still refuses a draw with a shared device and a season (M2-grow-share-sweep).
|
|
54
57
|
|
|
55
58
|
## The rule of shortfall
|
|
56
59
|
|
package/build/add-on.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as checkEndurance, t as joinEndurance } from "./join-
|
|
1
|
+
import { r as checkEndurance, t as joinEndurance } from "./join-D4KzcbbY.js";
|
|
2
2
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
3
3
|
import { parseEndurance } from "./schema.js";
|
|
4
4
|
// src/add-on.ts
|
package/build/index.d.ts
CHANGED
|
@@ -53,6 +53,28 @@ export declare function giftResource(converter: Converter): string | undefined;
|
|
|
53
53
|
* @throws RangeError when the start is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
54
54
|
*/
|
|
55
55
|
export declare function sowDays(season: Pick<Season, "from" | "to">, start: IsoDate, horizon: number): number[];
|
|
56
|
+
/** A lot of a harvest that the draws can take: its resource, its day, its spoil day (Infinity for none) and its amount. */
|
|
57
|
+
export interface HarvestLot {
|
|
58
|
+
readonly resource: string;
|
|
59
|
+
readonly day: number;
|
|
60
|
+
readonly spoils: number;
|
|
61
|
+
readonly amount: number;
|
|
62
|
+
}
|
|
63
|
+
/** The supply of a case with a season: the stocks after the sowings, the sowings, and the lots of the harvests before the horizon. */
|
|
64
|
+
export interface SeasonSupply {
|
|
65
|
+
/** The stock of each resource of the stores at `at`, less the inputs of the sowings. */
|
|
66
|
+
readonly stock: Map<string, number>;
|
|
67
|
+
readonly harvests: Harvest[];
|
|
68
|
+
/** The rest of each harvest after the later sowings, in the order of its day. Each lot has a day before the horizon and an amount more than 0. */
|
|
69
|
+
readonly lots: readonly HarvestLot[];
|
|
70
|
+
/** The horizon in days (`horizon` of the options, default `SEASON_HORIZON_DAYS`). */
|
|
71
|
+
readonly horizon: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* This function gives the supply of a case with a season (M2-grow-share). `enduranceOf`, `bestEndurance` and `jointDays`
|
|
75
|
+
* use it, so they read the same sowings. It throws a `RangeError` for a horizon that is not more than 0, or a date that is not `YYYY-MM-DD`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function seasonSupply(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>, options: CaseOptions): SeasonSupply;
|
|
56
78
|
/** This function tells if a layer has a converter with a season that can run in a case. */
|
|
57
79
|
export declare function hasSeason(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): boolean;
|
|
58
80
|
/**
|
|
@@ -123,6 +145,8 @@ export interface JointDays {
|
|
|
123
145
|
* The list is empty when `days` is `Infinity` or 0. Else it has each converter of the plan with a limit of 0.
|
|
124
146
|
*/
|
|
125
147
|
readonly capped: readonly string[];
|
|
148
|
+
/** True when a layer with a season holds the plan to the horizon (M2-grow-share). `days` is then the horizon. */
|
|
149
|
+
readonly atHorizon?: true | undefined;
|
|
126
150
|
}
|
|
127
151
|
/**
|
|
128
152
|
* 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.
|
|
@@ -145,12 +169,15 @@ export interface JointDays {
|
|
|
145
169
|
*
|
|
146
170
|
* The program uses exact rationals, so the result has no error of the method. Only the change back to a number rounds.
|
|
147
171
|
*
|
|
172
|
+
* With a converter with a season, `days` is the largest common first stop of the plan (M2-grow-share). The sowings, the lots and
|
|
173
|
+
* the segments are those of `bestEndurance`. The plan holds the horizon at most (default `SEASON_HORIZON_DAYS`), with `atHorizon`.
|
|
174
|
+
*
|
|
148
175
|
* @param layer - The endurance layer
|
|
149
176
|
* @param caseCuts - The case
|
|
150
177
|
* @param options - The date, and the stack or the parts that are also down
|
|
151
178
|
* @param needs - The codes of the needs of the draws of the set
|
|
152
179
|
* @returns The joint days, the takes of each draw, the binding resources and the runs of each converter
|
|
153
|
-
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`. Or a
|
|
180
|
+
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`. Or the horizon of a layer with a season is not more than 0.
|
|
154
181
|
*/
|
|
155
182
|
export declare function jointDays(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions, needs: readonly string[]): JointDays;
|
|
156
183
|
/** The options of `bestEndurance`: the options of a case, and a horizon. */
|
|
@@ -189,11 +216,20 @@ export interface BestOptions extends CaseOptions {
|
|
|
189
216
|
* The programs use exact rationals, so the result has no error of the method. Only the change back to a number rounds.
|
|
190
217
|
* The fewest days of the first level are the joint days (`jointDays`) of the draws of that level.
|
|
191
218
|
*
|
|
219
|
+
* A layer with a converter with a season has the programs of a season (M2-grow-share):
|
|
220
|
+
* - The sowings take their inputs before the draws, as in `enduranceOf`. Each harvest is a lot from its day, and its rest spoils on its spoil day.
|
|
221
|
+
* - The days go in segments that end at each harvest day, at each spoil day and at the horizon (default `SEASON_HORIZON_DAYS`). A segment takes only
|
|
222
|
+
* the lots that are ready and not spoiled in all of it.
|
|
223
|
+
* - `days` is the first stop of each draw, with the same leximin share. The days to a stop are not linear, so each step tries the segments in order.
|
|
224
|
+
* - After the stops, a last program gives the most fed days to each level in order. `again` gives the spans in which a later harvest feeds a draw.
|
|
225
|
+
* In such a span, the runs share the device-days of the whole segment that the stops leave.
|
|
226
|
+
* - The result has the field `harvests`. It has no field `spoiled`: the share of a lot between the draws has no spoil of one draw.
|
|
227
|
+
*
|
|
192
228
|
* @param layer - The endurance layer
|
|
193
229
|
* @param caseCuts - The case
|
|
194
230
|
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
195
231
|
* @returns The endurance of each draw whose supply stops
|
|
196
|
-
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
232
|
+
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
197
233
|
*/
|
|
198
234
|
export declare function bestEndurance(layer: EnduranceLayer, caseCuts: CaseCuts, options: BestOptions): Endurance;
|
|
199
235
|
/**
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAUiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;WAKA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,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;;;;;;;;wBAyKxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;
|
|
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;;;;;WAKA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,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;;;;;;;;wBAyKxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;;;;;wBAOK,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;wBAa9F,UAAU,OAAO,gBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuC/C,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBCta7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;WAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;iBCpDrG,oBAAoB;;;;;;WAM1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkEK,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBCjFhF,SAAS,OAAO,UAAU,cAAc;;;;;;;;;wBAoBxC,SAAS,OAAO,UAAU,MAAM,KAAK,kCAAkC;;;;;;;;;;iBAetE,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;;;;;YAiCpH;;qBAGC,iBAAiB;;iBAeb,6BAA6B,aAAa;;;;;;WAMhD,QAAQ;;;;;;;WAOR;;;qBAIE;;YAGD,gBAAgB,KAAK;;;;;;;iBAQhB;;WAEN;WACA,KAAK;WACL,MAAM;;WAEN;;;iBAIM;WACN;;WAEA;;WAEA,yBAAyB,aAAa;;WAEtC,WAAW;;WAEX,WAAW;;WAEX,kBAAkB;;;iBAIZ;WACN,OAAO;WACP,WAAW;;;iBAIL,sBAAsB;WAC5B;;WAEA,gBAAgB;;WAEhB,QAAQ;;;;;;;;;;;;;;;;;;;wBAoBH,cAAc,OAAO,gBAAgB,eAAe,SAAS,uBAAuB;;YA0ExF,iBAAiB;;iBAGZ;;WAEN;;WAEA;;WAEA;;;iBAIM;WACN,OAAO;WACP,WAAW;;;;;;;iBAQL;WACN,SAAS;WACT,QAAQ;;;iBAIF;WACN;WACA;WACA;WACA;;WAEA;;WAEA;;;;;;WAMA,OAAO;;WAEP,WAAW;;WAEX,OAAOA;;WAEP;;;;;WAKA,OAAO;;;iBAID;WACN;WACA;WACA;WACA,OAAO;;WAEP;;WAEA,gBAAgB;;WAEhB;;WAEA;;WAEA,OAAOA;;;;;;;;;;;;;;;;wBAiBF,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;qBCzzBpF;;YAqCD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBA6KtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBC9OnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
|
package/build/index.js
CHANGED
|
@@ -1,9 +1,426 @@
|
|
|
1
1
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
-
import { C as
|
|
2
|
+
import { C as reachOf, D as exact, E as dense, S as partsOf, T as addTo, _ as Program, a as hasEnduranceError, b as drawBlock, c as caseStopped, d as giftNeed, f as giftResource, g as storeAmounts, h as sowDays, i as curveFault, l as drawDemand, m as seasonSupply, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as caseParts, w as valueAt, x as fewestRow, y as deviceUse } from "./join-D4KzcbbY.js";
|
|
3
3
|
import { DEFAULT_MAX_SETS, STACK_SCHEMA, dateOfDay, dayNumber, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
|
|
4
4
|
import { ONE, ZERO, add, div, equals, mul, neg, sign, sub, toNumber } from "@mark1russell7/rational";
|
|
5
5
|
import { solveLexicographic } from "@mark1russell7/linear";
|
|
6
6
|
import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
7
|
+
// src/seasonal.ts
|
|
8
|
+
/**
|
|
9
|
+
* This function gives the parts of the programs of a case with a season. `parts` are the parts of the case with the
|
|
10
|
+
* stock after the sowings (`seasonSupply`).
|
|
11
|
+
*/
|
|
12
|
+
function seasonPlan(supply, parts, caseCuts, draws, devices) {
|
|
13
|
+
const total = new Map(supply.stock);
|
|
14
|
+
const harvests = supply.lots.filter((lot) => parts.resources.has(lot.resource));
|
|
15
|
+
for (const lot of harvests) total.set(lot.resource, (total.get(lot.resource) ?? 0) + lot.amount);
|
|
16
|
+
const all = partsOf(total, parts.direct, parts.cooks, parts.makers);
|
|
17
|
+
const lots = [...all.stocked.filter((resource) => (supply.stock.get(resource) ?? 0) > 0).map((resource) => ({
|
|
18
|
+
resource,
|
|
19
|
+
day: 0,
|
|
20
|
+
spoils: 1e400,
|
|
21
|
+
amount: exact(supply.stock.get(resource) ?? 0)
|
|
22
|
+
})), ...harvests.map((lot) => ({
|
|
23
|
+
resource: lot.resource,
|
|
24
|
+
day: Math.max(0, lot.day),
|
|
25
|
+
spoils: lot.spoils,
|
|
26
|
+
amount: exact(lot.amount)
|
|
27
|
+
}))];
|
|
28
|
+
const inside = (day) => day > 0 && day < supply.horizon;
|
|
29
|
+
return {
|
|
30
|
+
parts: all,
|
|
31
|
+
caseCuts,
|
|
32
|
+
draws,
|
|
33
|
+
devices,
|
|
34
|
+
lots,
|
|
35
|
+
edges: [.../* @__PURE__ */ new Set([
|
|
36
|
+
0,
|
|
37
|
+
supply.horizon,
|
|
38
|
+
...lots.flatMap((lot) => [lot.day, lot.spoils]).filter(inside)
|
|
39
|
+
])].sort((a, b) => a - b)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const edgeOf = (plan, index) => exact(plan.edges[index] ?? 0);
|
|
43
|
+
const lengthOf = (plan, index) => sub(edgeOf(plan, index + 1), edgeOf(plan, index));
|
|
44
|
+
const segmentsOf = (plan) => plan.edges.length - 1;
|
|
45
|
+
/** This function gives the fed days of a fixed draw in a segment. It is all of a segment before the stop, the part to the stop, then 0. */
|
|
46
|
+
function fixedFed(plan, fix, segment) {
|
|
47
|
+
if (segment < fix.segment) return lengthOf(plan, segment);
|
|
48
|
+
if (segment === fix.segment) return sub(fix.stop, edgeOf(plan, segment));
|
|
49
|
+
return ZERO;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* This function adds the columns of one draw in one segment. The gifts of the need are not less than the demand times the fed days.
|
|
53
|
+
* The share of each stock is the sum of the takes of the lots that are ready and not spoiled in the whole segment.
|
|
54
|
+
*/
|
|
55
|
+
function addCell(program, plan, draw, segment, fed) {
|
|
56
|
+
const block = drawBlock(program, plan.parts, draw);
|
|
57
|
+
const demand = exact(drawDemand(draw, plan.caseCuts));
|
|
58
|
+
const need = new Map(block.gifts);
|
|
59
|
+
if (typeof fed === "number") {
|
|
60
|
+
addTo(need, fed, neg(demand));
|
|
61
|
+
program.push(need, ">=", ZERO);
|
|
62
|
+
} else program.push(need, ">=", mul(demand, fed));
|
|
63
|
+
const from = plan.edges[segment] ?? 0;
|
|
64
|
+
const to = plan.edges[segment + 1] ?? 1e400;
|
|
65
|
+
const takes = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const [resource, share] of block.shares) {
|
|
67
|
+
const row = /* @__PURE__ */ new Map([[share, ONE]]);
|
|
68
|
+
for (const lot of plan.lots) {
|
|
69
|
+
if (lot.resource !== resource || lot.day > from || lot.spoils < to) continue;
|
|
70
|
+
const column = program.next();
|
|
71
|
+
takes.set(lot, column);
|
|
72
|
+
addTo(row, column, neg(ONE));
|
|
73
|
+
}
|
|
74
|
+
program.push(row, "=", ZERO);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
draw,
|
|
78
|
+
segment,
|
|
79
|
+
block,
|
|
80
|
+
fed,
|
|
81
|
+
takes
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** This function adds the row of each lot: the takes of all the cells are not more than its amount. */
|
|
85
|
+
function lotRows(program, plan, cells) {
|
|
86
|
+
for (const lot of plan.lots) {
|
|
87
|
+
const row = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const cell of cells) {
|
|
89
|
+
const column = cell.takes.get(lot);
|
|
90
|
+
if (column !== void 0) addTo(row, column, ONE);
|
|
91
|
+
}
|
|
92
|
+
if (row.size > 0) program.push(row, "<=", lot.amount);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* This function adds the cells of the fixed draws. Each one is fed to its first stop, and its runs use the device-days of each day
|
|
97
|
+
* that it keeps. It gives the device-days of each day that the fixed draws keep, by the index of the segment, then the key.
|
|
98
|
+
*/
|
|
99
|
+
function addFixed(program, plan, fixed, cells) {
|
|
100
|
+
const kept = /* @__PURE__ */ new Map();
|
|
101
|
+
for (const draw of plan.draws) {
|
|
102
|
+
const fix = fixed.get(draw.need);
|
|
103
|
+
if (fix === void 0) continue;
|
|
104
|
+
for (let segment = 0; segment <= fix.segment; segment += 1) {
|
|
105
|
+
const fed = fixedFed(plan, fix, segment);
|
|
106
|
+
const keep = fix.keep.get(segment) ?? /* @__PURE__ */ new Map();
|
|
107
|
+
const into = kept.get(segment) ?? /* @__PURE__ */ new Map();
|
|
108
|
+
kept.set(segment, into);
|
|
109
|
+
for (const [key, value] of keep) into.set(key, add(into.get(key) ?? ZERO, value));
|
|
110
|
+
if (sign(fed) <= 0) continue;
|
|
111
|
+
const cell = addCell(program, plan, draw, segment, fed);
|
|
112
|
+
cells.push(cell);
|
|
113
|
+
const { limits, stopped } = deviceUse(cell.block.runs);
|
|
114
|
+
for (const index of stopped) program.push(/* @__PURE__ */ new Map([[index, ONE]]), "<=", ZERO);
|
|
115
|
+
for (const [key, limit] of limits) program.push(limit.row, "<=", mul(keep.get(key) ?? ZERO, fed));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return kept;
|
|
119
|
+
}
|
|
120
|
+
/** This function gives the device-days of each day that the fixed draws leave in a segment. */
|
|
121
|
+
function roomOf(plan, kept, segment, key, devices) {
|
|
122
|
+
const left = sub(exact(plan.devices.get(key) ?? devices), kept.get(segment)?.get(key) ?? ZERO);
|
|
123
|
+
return sign(left) > 0 ? left : ZERO;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* This function gives the program of one step with the stop of the open draws in segment `segment`. The open draws are fed in
|
|
127
|
+
* each segment before it. In it, each one is fed for `t - edge` days or more, and their runs share the device-days that
|
|
128
|
+
* the fixed draws leave, for `t - edge` days. This is the safe side, as in `bestEndurance`.
|
|
129
|
+
*/
|
|
130
|
+
function buildStep$1(plan, fixed, open, segment) {
|
|
131
|
+
const program = new Program();
|
|
132
|
+
const t = program.next();
|
|
133
|
+
program.push(/* @__PURE__ */ new Map([[t, ONE]]), "<=", edgeOf(plan, segment + 1));
|
|
134
|
+
const cells = [];
|
|
135
|
+
const kept = addFixed(program, plan, fixed, cells);
|
|
136
|
+
const opened = new Set(open.map((draw) => draw.need));
|
|
137
|
+
const floors = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const draw of plan.draws) {
|
|
139
|
+
if (!opened.has(draw.need)) continue;
|
|
140
|
+
for (let index = 0; index < segment; index += 1) cells.push(addCell(program, plan, draw, index, lengthOf(plan, index)));
|
|
141
|
+
const fed = program.next();
|
|
142
|
+
program.push(/* @__PURE__ */ new Map([[fed, ONE]]), "<=", lengthOf(plan, segment));
|
|
143
|
+
floors.set(draw.need, program.push(/* @__PURE__ */ new Map([[fed, ONE], [t, neg(ONE)]]), ">=", neg(edgeOf(plan, segment))));
|
|
144
|
+
cells.push(addCell(program, plan, draw, segment, fed));
|
|
145
|
+
}
|
|
146
|
+
const shared = /* @__PURE__ */ new Map();
|
|
147
|
+
for (let index = 0; index <= segment; index += 1) {
|
|
148
|
+
const { limits, stopped } = deviceUse(cells.filter((cell) => cell.segment === index && opened.has(cell.draw.need)).flatMap((cell) => [...cell.block.runs]));
|
|
149
|
+
for (const column of stopped) program.push(/* @__PURE__ */ new Map([[column, ONE]]), "<=", ZERO);
|
|
150
|
+
const bySegment = /* @__PURE__ */ new Map();
|
|
151
|
+
shared.set(index, bySegment);
|
|
152
|
+
for (const [key, limit] of limits) {
|
|
153
|
+
const room = roomOf(plan, kept, index, key, limit.devices);
|
|
154
|
+
bySegment.set(key, {
|
|
155
|
+
row: limit.row,
|
|
156
|
+
room,
|
|
157
|
+
converters: limit.converters
|
|
158
|
+
});
|
|
159
|
+
const row = new Map(limit.row);
|
|
160
|
+
if (index < segment) program.push(row, "<=", mul(room, lengthOf(plan, index)));
|
|
161
|
+
else {
|
|
162
|
+
addTo(row, t, neg(room));
|
|
163
|
+
program.push(row, "<=", neg(mul(room, edgeOf(plan, segment))));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
lotRows(program, plan, cells);
|
|
168
|
+
return {
|
|
169
|
+
program,
|
|
170
|
+
t,
|
|
171
|
+
cells,
|
|
172
|
+
floors,
|
|
173
|
+
shared,
|
|
174
|
+
segment
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* This function gives the largest common first stop of the open draws, with the fixed draws at their stops. The days to
|
|
179
|
+
* a first stop are not a linear function of the takes, so the function tries the segments in order. When the days reach
|
|
180
|
+
* the end of a segment, it tries the next segment. The days of the last step are exact.
|
|
181
|
+
* After the largest days, the step takes the objectives of `tail`.
|
|
182
|
+
*/
|
|
183
|
+
function firstStop(plan, fixed, open, tail = () => []) {
|
|
184
|
+
const segments = segmentsOf(plan);
|
|
185
|
+
for (let segment = 0; segment < segments; segment += 1) {
|
|
186
|
+
const step = buildStep$1(plan, fixed, open, segment);
|
|
187
|
+
const most = {
|
|
188
|
+
sense: "max",
|
|
189
|
+
coefficients: dense(/* @__PURE__ */ new Map([[step.t, ONE]]), step.program.count)
|
|
190
|
+
};
|
|
191
|
+
const solved = solveLexicographic(step.program.constraints(), [most]);
|
|
192
|
+
if (solved.status !== "optimal") throw new Error("The step of a season has no optimum. The point of the stop of the last segment is a point of it.");
|
|
193
|
+
const days = solved.values[0] ?? ZERO;
|
|
194
|
+
const end = edgeOf(plan, segment + 1);
|
|
195
|
+
if (segment + 1 < segments && equals(days, end)) continue;
|
|
196
|
+
const full = tail(step).length === 0 ? solved : solveLexicographic(step.program.constraints(), [most, ...tail(step)]);
|
|
197
|
+
if (full.status !== "optimal") throw new Error("The step of a season has no optimum for its later objectives.");
|
|
198
|
+
const first = full.stages[0]?.result;
|
|
199
|
+
return {
|
|
200
|
+
step,
|
|
201
|
+
x: full.x,
|
|
202
|
+
dual: first?.status === "optimal" ? first.dual : [],
|
|
203
|
+
days,
|
|
204
|
+
atHorizon: segment + 1 === segments && equals(days, end)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
throw new Error("A season plan has no segment.");
|
|
208
|
+
}
|
|
209
|
+
/** This function gives the fewest device-days of the runs of the open cells of a step, as an objective. */
|
|
210
|
+
function fewestOpen(step, open) {
|
|
211
|
+
return {
|
|
212
|
+
sense: "min",
|
|
213
|
+
coefficients: dense(fewestRow(step.cells.filter((cell) => open.has(cell.draw.need)).flatMap((cell) => [...cell.block.runs])), step.program.count)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/** This function gives the smallest sum of the shares of the stocks, each over the total of its lots, as an objective. */
|
|
217
|
+
function leastShares(plan, cells, count) {
|
|
218
|
+
const least = /* @__PURE__ */ new Map();
|
|
219
|
+
for (const cell of cells) for (const [resource, index] of cell.block.shares) addTo(least, index, div(ONE, exact(plan.parts.stock.get(resource) ?? 1)));
|
|
220
|
+
return {
|
|
221
|
+
sense: "min",
|
|
222
|
+
coefficients: dense(least, count)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** This function fixes the open draws of `done` at the stop: the device-days of each day that they keep, and their capped converters. */
|
|
226
|
+
function fixStops(plan, stop, done, fixed) {
|
|
227
|
+
const { step, x, days } = stop;
|
|
228
|
+
const fedIn = (segment) => segment < step.segment ? lengthOf(plan, segment) : sub(days, edgeOf(plan, step.segment));
|
|
229
|
+
const full = /* @__PURE__ */ new Set();
|
|
230
|
+
for (const [segment, bySegment] of step.shared) for (const [key, limit] of bySegment) if (equals(valueAt(limit.row, x), mul(limit.room, fedIn(segment)))) full.add(`${String(segment)}\u0000${key}`);
|
|
231
|
+
for (const draw of done) {
|
|
232
|
+
const keep = /* @__PURE__ */ new Map();
|
|
233
|
+
const used = /* @__PURE__ */ new Set();
|
|
234
|
+
for (const cell of step.cells) {
|
|
235
|
+
if (cell.draw.need !== draw.need) continue;
|
|
236
|
+
const fed = fedIn(cell.segment);
|
|
237
|
+
const bySegment = /* @__PURE__ */ new Map();
|
|
238
|
+
keep.set(cell.segment, bySegment);
|
|
239
|
+
for (const [key, limit] of deviceUse(cell.block.runs).limits) {
|
|
240
|
+
bySegment.set(key, sign(fed) > 0 ? div(valueAt(limit.row, x), fed) : ZERO);
|
|
241
|
+
if (full.has(`${String(cell.segment)}\u0000${key}`)) for (const converter of limit.converters) used.add(converter);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const { reach } = reachOf(plan.parts, /* @__PURE__ */ new Set([draw.need]));
|
|
245
|
+
const capped = sign(days) > 0 ? [...reach].filter((converter) => converter.perDay !== void 0 && (!(converter.perDay > 0) || used.has(converter))).map((converter) => converter.id).sort() : [];
|
|
246
|
+
fixed.set(draw.need, {
|
|
247
|
+
stop: days,
|
|
248
|
+
segment: step.segment,
|
|
249
|
+
keep,
|
|
250
|
+
atHorizon: stop.atHorizon,
|
|
251
|
+
capped
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** This function gives the sum of the take of each resource of the cells of one need, more than 0 only. */
|
|
256
|
+
function takesOf(cells, need, x) {
|
|
257
|
+
const sums = /* @__PURE__ */ new Map();
|
|
258
|
+
for (const cell of cells) {
|
|
259
|
+
if (cell.draw.need !== need) continue;
|
|
260
|
+
for (const [resource, index] of cell.block.shares) sums.set(resource, add(sums.get(resource) ?? ZERO, x[index] ?? ZERO));
|
|
261
|
+
}
|
|
262
|
+
const out = {};
|
|
263
|
+
for (const [resource, value] of [...sums].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) if (sign(value) > 0) out[resource] = toNumber(value);
|
|
264
|
+
return out;
|
|
265
|
+
}
|
|
266
|
+
/** This function gives the resources of `closure` with a store in the layer whose lots are used up at `x`. They are in the order of their codes. */
|
|
267
|
+
function usedUp(plan, cells, x, closure, stored) {
|
|
268
|
+
return [...closure].filter((resource) => stored.has(resource)).filter((resource) => {
|
|
269
|
+
let taken = ZERO;
|
|
270
|
+
let amount = ZERO;
|
|
271
|
+
for (const lot of plan.lots) {
|
|
272
|
+
if (lot.resource !== resource) continue;
|
|
273
|
+
amount = add(amount, lot.amount);
|
|
274
|
+
for (const cell of cells) taken = add(taken, x[cell.takes.get(lot) ?? -1] ?? ZERO);
|
|
275
|
+
}
|
|
276
|
+
return equals(taken, amount);
|
|
277
|
+
}).sort();
|
|
278
|
+
}
|
|
279
|
+
/** This function tells if the cells of two draws or more of `cells` can use the limited device `key`. */
|
|
280
|
+
function sharedKey(cells, key) {
|
|
281
|
+
return new Set(cells.filter((cell) => deviceUse(cell.block.runs).limits.has(key)).map((cell) => cell.draw.need)).size > 1;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* This function gives the last program of the best endurance with a season. Each draw keeps its first stop. After it, a later
|
|
285
|
+
* harvest can feed the draw again (`again`). The objectives come in this order:
|
|
286
|
+
* - the most fed days after the stops for each level, in the order of the levels.
|
|
287
|
+
* - the earliest fed days.
|
|
288
|
+
* - the smallest sum of the shares of the stocks.
|
|
289
|
+
* - the fewest device-days.
|
|
290
|
+
*
|
|
291
|
+
* In a segment after the stops, the cells of two draws or more that can use one limited device take turns. Their fed days
|
|
292
|
+
* together are not more than the segment, and each one has the device-days of each day that the stops leave. This is the
|
|
293
|
+
* safe side: the cells do not use one device at the same time. Each other cell starts at the start of the segment.
|
|
294
|
+
*/
|
|
295
|
+
function seasonBest(plan, fixed, levels, stored) {
|
|
296
|
+
const program = new Program();
|
|
297
|
+
const cells = [];
|
|
298
|
+
const kept = addFixed(program, plan, fixed, cells);
|
|
299
|
+
const segments = segmentsOf(plan);
|
|
300
|
+
const again = /* @__PURE__ */ new Map();
|
|
301
|
+
const taking = /* @__PURE__ */ new Set();
|
|
302
|
+
for (const draw of plan.draws) {
|
|
303
|
+
const fix = fixed.get(draw.need);
|
|
304
|
+
for (let segment = fix.segment + 1; segment < segments; segment += 1) {
|
|
305
|
+
const fed = program.next();
|
|
306
|
+
program.push(/* @__PURE__ */ new Map([[fed, ONE]]), "<=", lengthOf(plan, segment));
|
|
307
|
+
const cell = addCell(program, plan, draw, segment, fed);
|
|
308
|
+
cells.push(cell);
|
|
309
|
+
again.set(cell, fed);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
for (let segment = 0; segment < segments; segment += 1) {
|
|
313
|
+
const later = [...again.keys()].filter((cell) => cell.segment === segment);
|
|
314
|
+
const { limits, stopped } = deviceUse(later.flatMap((cell) => [...cell.block.runs]));
|
|
315
|
+
for (const column of stopped) program.push(/* @__PURE__ */ new Map([[column, ONE]]), "<=", ZERO);
|
|
316
|
+
const turns = new Set(later.filter((cell) => [...deviceUse(cell.block.runs).limits.keys()].some((key) => sharedKey(later, key))));
|
|
317
|
+
if (turns.size > 0) {
|
|
318
|
+
const row = /* @__PURE__ */ new Map();
|
|
319
|
+
for (const cell of turns) addTo(row, again.get(cell), ONE);
|
|
320
|
+
program.push(row, "<=", lengthOf(plan, segment));
|
|
321
|
+
for (const cell of turns) taking.add(cell);
|
|
322
|
+
}
|
|
323
|
+
for (const [key, limit] of limits) {
|
|
324
|
+
const room = roomOf(plan, kept, segment, key, limit.devices);
|
|
325
|
+
for (const cell of later) {
|
|
326
|
+
const own = deviceUse(cell.block.runs).limits.get(key);
|
|
327
|
+
if (own === void 0) continue;
|
|
328
|
+
const row = new Map(own.row);
|
|
329
|
+
addTo(row, again.get(cell), neg(room));
|
|
330
|
+
program.push(row, "<=", ZERO);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
lotRows(program, plan, cells);
|
|
335
|
+
const objectives = levels.map((level) => {
|
|
336
|
+
const needs = new Set(level.map((draw) => draw.need));
|
|
337
|
+
const row = /* @__PURE__ */ new Map();
|
|
338
|
+
for (const [cell, fed] of again) if (needs.has(cell.draw.need)) addTo(row, fed, ONE);
|
|
339
|
+
return {
|
|
340
|
+
sense: "max",
|
|
341
|
+
coefficients: dense(row, program.count)
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
const early = /* @__PURE__ */ new Map();
|
|
345
|
+
const horizon = edgeOf(plan, segments);
|
|
346
|
+
for (const [cell, fed] of again) addTo(early, fed, sub(horizon, edgeOf(plan, cell.segment)));
|
|
347
|
+
objectives.push({
|
|
348
|
+
sense: "max",
|
|
349
|
+
coefficients: dense(early, program.count)
|
|
350
|
+
});
|
|
351
|
+
objectives.push(leastShares(plan, cells, program.count));
|
|
352
|
+
objectives.push({
|
|
353
|
+
sense: "min",
|
|
354
|
+
coefficients: dense(fewestRow(cells.flatMap((cell) => [...cell.block.runs])), program.count)
|
|
355
|
+
});
|
|
356
|
+
const solved = solveLexicographic(program.constraints(), objectives);
|
|
357
|
+
if (solved.status !== "optimal") throw new Error("The last program of the best endurance with a season has no optimum. The point of the last step is a point of it.");
|
|
358
|
+
const x = solved.x;
|
|
359
|
+
const turn = /* @__PURE__ */ new Map();
|
|
360
|
+
const offset = /* @__PURE__ */ new Map();
|
|
361
|
+
for (const cell of [...taking].sort((a, b) => plan.draws.indexOf(a.draw) - plan.draws.indexOf(b.draw))) {
|
|
362
|
+
const start = offset.get(cell.segment) ?? ZERO;
|
|
363
|
+
turn.set(cell, start);
|
|
364
|
+
offset.set(cell.segment, add(start, x[again.get(cell)] ?? ZERO));
|
|
365
|
+
}
|
|
366
|
+
const needs = {};
|
|
367
|
+
for (const draw of plan.draws) {
|
|
368
|
+
const fix = fixed.get(draw.need);
|
|
369
|
+
const spans = [];
|
|
370
|
+
for (const [cell, fed] of again) {
|
|
371
|
+
if (cell.draw.need !== draw.need) continue;
|
|
372
|
+
const value = x[fed] ?? ZERO;
|
|
373
|
+
if (sign(value) <= 0) continue;
|
|
374
|
+
const start = add(edgeOf(plan, cell.segment), taking.has(cell) ? turn.get(cell) ?? ZERO : ZERO);
|
|
375
|
+
const from = toNumber(start);
|
|
376
|
+
const to = toNumber(add(start, value));
|
|
377
|
+
const last = spans[spans.length - 1];
|
|
378
|
+
if (last !== void 0 && last.to === from) last.to = to;
|
|
379
|
+
else spans.push({
|
|
380
|
+
from,
|
|
381
|
+
to
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
const { closure } = reachOf(plan.parts, /* @__PURE__ */ new Set([draw.need]));
|
|
385
|
+
needs[draw.need] = {
|
|
386
|
+
days: toNumber(fix.stop),
|
|
387
|
+
binding: usedUp(plan, cells, x, closure, stored),
|
|
388
|
+
takes: takesOf(cells, draw.need, x),
|
|
389
|
+
...fix.capped.length === 0 ? {} : { capped: fix.capped },
|
|
390
|
+
...fix.atHorizon ? { atHorizon: true } : {},
|
|
391
|
+
...spans.length === 0 ? {} : { again: spans }
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return { needs };
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* This function gives the joint days of the draws of a plan with a season. The objectives come in this order:
|
|
398
|
+
* - the largest common first stop.
|
|
399
|
+
* - the smallest sum of the shares of the stocks.
|
|
400
|
+
* - the fewest device-days.
|
|
401
|
+
*/
|
|
402
|
+
function seasonJoint(plan, stored) {
|
|
403
|
+
const open = new Set(plan.draws.map((draw) => draw.need));
|
|
404
|
+
const stop = firstStop(plan, /* @__PURE__ */ new Map(), plan.draws, (step) => [leastShares(plan, step.cells, step.program.count), fewestOpen(step, open)]);
|
|
405
|
+
const { step, x } = stop;
|
|
406
|
+
const takes = {};
|
|
407
|
+
for (const draw of plan.draws) takes[draw.need] = takesOf(step.cells, draw.need, x);
|
|
408
|
+
const total = /* @__PURE__ */ new Map();
|
|
409
|
+
for (const cell of step.cells) for (const [converter, index] of cell.block.runs) total.set(converter, add(total.get(converter) ?? ZERO, x[index] ?? ZERO));
|
|
410
|
+
const runs = {};
|
|
411
|
+
for (const [converter, value] of [...total].sort(([a], [b]) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0)) if (sign(value) > 0) runs[converter.id] = toNumber(value);
|
|
412
|
+
const fixed = /* @__PURE__ */ new Map();
|
|
413
|
+
fixStops(plan, stop, plan.draws, fixed);
|
|
414
|
+
const capped = [...new Set([...fixed.values()].flatMap((fix) => fix.capped))].sort();
|
|
415
|
+
return {
|
|
416
|
+
days: toNumber(stop.days),
|
|
417
|
+
atHorizon: stop.atHorizon,
|
|
418
|
+
takes,
|
|
419
|
+
binding: usedUp(plan, step.cells, x, reachOf(plan.parts, open).closure, stored),
|
|
420
|
+
runs,
|
|
421
|
+
capped
|
|
422
|
+
};
|
|
423
|
+
}
|
|
7
424
|
// src/joint.ts
|
|
8
425
|
/**
|
|
9
426
|
* 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.
|
|
@@ -26,20 +443,23 @@ import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/
|
|
|
26
443
|
*
|
|
27
444
|
* The program uses exact rationals, so the result has no error of the method. Only the change back to a number rounds.
|
|
28
445
|
*
|
|
446
|
+
* With a converter with a season, `days` is the largest common first stop of the plan (M2-grow-share). The sowings, the lots and
|
|
447
|
+
* the segments are those of `bestEndurance`. The plan holds the horizon at most (default `SEASON_HORIZON_DAYS`), with `atHorizon`.
|
|
448
|
+
*
|
|
29
449
|
* @param layer - The endurance layer
|
|
30
450
|
* @param caseCuts - The case
|
|
31
451
|
* @param options - The date, and the stack or the parts that are also down
|
|
32
452
|
* @param needs - The codes of the needs of the draws of the set
|
|
33
453
|
* @returns The joint days, the takes of each draw, the binding resources and the runs of each converter
|
|
34
|
-
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`. Or a
|
|
454
|
+
* @throws {RangeError} A code of `needs` is not the need of a draw of the layer, or a date is not `YYYY-MM-DD`. Or the horizon of a layer with a season is not more than 0.
|
|
35
455
|
*/
|
|
36
456
|
function jointDays(layer, caseCuts, options, needs) {
|
|
37
457
|
const known = new Set(layer.draws.map((draw) => draw.need));
|
|
38
458
|
const unknown = needs.filter((need) => !known.has(need));
|
|
39
459
|
if (unknown.length > 0) throw new RangeError(`The needs ${unknown.map((need) => `"${need}"`).join(", ")} are not the needs of draws of the layer.`);
|
|
40
460
|
const stoppedParts = caseStopped(caseCuts, options);
|
|
41
|
-
|
|
42
|
-
const stock = storeAmounts(layer, options.at, stoppedParts);
|
|
461
|
+
const supply = hasSeason(layer, stoppedParts) ? seasonSupply(layer, stoppedParts, options) : void 0;
|
|
462
|
+
const stock = supply?.stock ?? storeAmounts(layer, options.at, stoppedParts);
|
|
43
463
|
const wanted = new Set(needs);
|
|
44
464
|
const plan = caseDraws(layer, caseCuts, stoppedParts).filter((draw) => wanted.has(draw.need));
|
|
45
465
|
const planned = new Set(plan.map((draw) => draw.need));
|
|
@@ -59,6 +479,14 @@ function jointDays(layer, caseCuts, options, needs) {
|
|
|
59
479
|
};
|
|
60
480
|
if (plan.length === 0) return endless;
|
|
61
481
|
const parts = caseParts(layer, stoppedParts, stock, planned);
|
|
482
|
+
if (supply !== void 0) {
|
|
483
|
+
const { atHorizon, ...joint } = seasonJoint(seasonPlan(supply, parts, caseCuts, plan, new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0])).limits].map(([key, limit]) => [key, limit.devices]))), new Set(layer.stores.map((store) => store.resource)));
|
|
484
|
+
return {
|
|
485
|
+
...base,
|
|
486
|
+
...joint,
|
|
487
|
+
...atHorizon ? { atHorizon: true } : {}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
62
490
|
const program = new Program();
|
|
63
491
|
const days = program.next();
|
|
64
492
|
const blocks = plan.map((draw) => {
|
|
@@ -168,16 +596,25 @@ function horizonOf$1(horizon) {
|
|
|
168
596
|
* The programs use exact rationals, so the result has no error of the method. Only the change back to a number rounds.
|
|
169
597
|
* The fewest days of the first level are the joint days (`jointDays`) of the draws of that level.
|
|
170
598
|
*
|
|
599
|
+
* A layer with a converter with a season has the programs of a season (M2-grow-share):
|
|
600
|
+
* - The sowings take their inputs before the draws, as in `enduranceOf`. Each harvest is a lot from its day, and its rest spoils on its spoil day.
|
|
601
|
+
* - The days go in segments that end at each harvest day, at each spoil day and at the horizon (default `SEASON_HORIZON_DAYS`). A segment takes only
|
|
602
|
+
* the lots that are ready and not spoiled in all of it.
|
|
603
|
+
* - `days` is the first stop of each draw, with the same leximin share. The days to a stop are not linear, so each step tries the segments in order.
|
|
604
|
+
* - After the stops, a last program gives the most fed days to each level in order. `again` gives the spans in which a later harvest feeds a draw.
|
|
605
|
+
* In such a span, the runs share the device-days of the whole segment that the stops leave.
|
|
606
|
+
* - The result has the field `harvests`. It has no field `spoiled`: the share of a lot between the draws has no spoil of one draw.
|
|
607
|
+
*
|
|
171
608
|
* @param layer - The endurance layer
|
|
172
609
|
* @param caseCuts - The case
|
|
173
610
|
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
174
611
|
* @returns The endurance of each draw whose supply stops
|
|
175
|
-
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
612
|
+
* @throws {RangeError} A date is not `YYYY-MM-DD`, or the horizon is not more than 0.
|
|
176
613
|
*/
|
|
177
614
|
function bestEndurance(layer, caseCuts, options) {
|
|
178
615
|
const horizon = horizonOf$1(options.horizon);
|
|
179
616
|
const stoppedParts = caseStopped(caseCuts, options);
|
|
180
|
-
if (hasSeason(layer, stoppedParts))
|
|
617
|
+
if (hasSeason(layer, stoppedParts)) return bestSeason(layer, caseCuts, options, stoppedParts);
|
|
181
618
|
const stock = storeAmounts(layer, options.at, stoppedParts);
|
|
182
619
|
const draws = caseDraws(layer, caseCuts, stoppedParts);
|
|
183
620
|
const parts = caseParts(layer, stoppedParts, stock, new Set(draws.map((draw) => draw.need)));
|
|
@@ -278,6 +715,40 @@ function bestEndurance(layer, caseCuts, options) {
|
|
|
278
715
|
needs
|
|
279
716
|
};
|
|
280
717
|
}
|
|
718
|
+
/** This function gives the best endurance of a case with a season (M2-grow-share). */
|
|
719
|
+
function bestSeason(layer, caseCuts, options, stoppedParts) {
|
|
720
|
+
const supply = seasonSupply(layer, stoppedParts, options);
|
|
721
|
+
const draws = caseDraws(layer, caseCuts, stoppedParts);
|
|
722
|
+
const parts = caseParts(layer, stoppedParts, supply.stock, new Set(draws.map((draw) => draw.need)));
|
|
723
|
+
const plan = seasonPlan(supply, parts, caseCuts, draws, new Map([...deviceUse([...parts.cooks, ...parts.makers].map((converter) => [converter, 0])).limits].map(([key, limit]) => [key, limit.devices])));
|
|
724
|
+
const harvests = supply.harvests.length === 0 ? {} : { harvests: supply.harvests };
|
|
725
|
+
if (draws.length === 0) return {
|
|
726
|
+
case: caseCuts.case,
|
|
727
|
+
at: options.at,
|
|
728
|
+
needs: {},
|
|
729
|
+
...harvests
|
|
730
|
+
};
|
|
731
|
+
const levels = levelGroups(layer, draws);
|
|
732
|
+
const fixed = /* @__PURE__ */ new Map();
|
|
733
|
+
for (const level of levels) {
|
|
734
|
+
let open = level;
|
|
735
|
+
while (open.length > 0) {
|
|
736
|
+
const opened = new Set(open.map((draw) => draw.need));
|
|
737
|
+
const stop = firstStop(plan, fixed, open, (step) => [fewestOpen(step, opened)]);
|
|
738
|
+
let done = stop.atHorizon ? open : open.filter((draw) => sign(stop.dual[stop.step.floors.get(draw.need)] ?? ZERO) !== 0);
|
|
739
|
+
if (done.length === 0) done = open;
|
|
740
|
+
fixStops(plan, stop, done, fixed);
|
|
741
|
+
open = open.filter((draw) => !done.includes(draw));
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const { needs } = seasonBest(plan, fixed, levels, new Set(layer.stores.map((store) => store.resource)));
|
|
745
|
+
return {
|
|
746
|
+
case: caseCuts.case,
|
|
747
|
+
at: options.at,
|
|
748
|
+
needs,
|
|
749
|
+
...harvests
|
|
750
|
+
};
|
|
751
|
+
}
|
|
281
752
|
/** This function gives the draws of each level, in the order of `levels`. The draws of a level that is not in `levels` come last, together. */
|
|
282
753
|
function levelGroups(layer, draws) {
|
|
283
754
|
const rank = (draw) => {
|
|
@@ -1386,6 +1857,6 @@ const SAMPLE_ENDURANCE = {
|
|
|
1386
1857
|
asOf: "2025-12-01"
|
|
1387
1858
|
}]
|
|
1388
1859
|
};
|
|
1389
|
-
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, joinEndurance, jointDays, longestStop, minimalStops, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
1860
|
+
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, joinEndurance, jointDays, longestStop, minimalStops, seasonSupply, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
1390
1861
|
|
|
1391
1862
|
//# sourceMappingURL=index.js.map
|