@mark1russell7/stack-endurance 0.8.22 → 0.8.24

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 CHANGED
@@ -71,7 +71,10 @@ A converter with a limit `perDay` more than 0 can take nothing. It is a source,
71
71
  A store can have a `capacity`: the most amount that it holds. A source that gives the resource of the store charges it with the runs that no draw takes on their day. Example: a battery of 6000 Wh takes the energy of a sunny day, and gives it back on a dark day. Since 0.8.21 (M2-solar-charge).
72
72
 
73
73
  - `bestEndurance` and `jointDays` give the charge in each segment of the days. In a segment, the takes are not more than the level at the start of the segment. Also the level at the start plus the charge is not more than the capacity. Thus each order of the takes and the charges in the segment is a plan. This is the safe side.
74
- - The sweep of `enduranceOf` takes one draw at a time, and it gives no charge. There a store with a capacity is a store with no charge. The follow-up M2-solar-charge-sweep adds the charge to the sweep.
74
+ - Since 0.8.23, the sweep of `enduranceOf` gives the charge too (M2-solar-charge-sweep). Each draw that can take the store gets the programs of `bestEndurance` for itself alone, in the order of the levels. Thus one draw gets the days of `bestEndurance`.
75
+ - In the sweep, a draw charges the store as much as it can, the earliest first. Its takes and its charge in each segment then stay as they are.
76
+ - A lower draw takes only the level that the higher draws leave. Its takes keep the takes and the charges of the higher draws possible in each segment. It adds a charge only with the device-days that the higher draws leave.
77
+ - The device-days of a charge count as device-days of its draw for each lower draw. This is the safe side.
75
78
  - Only a source charges a store. A maker with inputs gives no charge, because its inputs keep to the day of the take.
76
79
  - The stores of one resource all have a capacity, or none has one. A store with a capacity has no due date, and its capacity is not less than its amount. The gate refuses the other cases (`endurance-capacity`).
77
80
 
package/build/add-on.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { u as EnduranceLayer } from "./layer-DuGjz7Cl.js";
1
+ import { u as EnduranceLayer } from "./layer-CZZWJtM8.js";
2
2
  import { StackJoiner } from "@mark1russell7/system-stack";
3
3
  /**
4
4
  * This function gives the endurance add-on.
package/build/add-on.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as checkEndurance, t as joinEndurance } from "./join-OKGUUCVQ.js";
1
+ import { r as checkEndurance, t as joinEndurance } from "./join-CxA4Td_Z.js";
2
2
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
3
3
  import { parseEndurance } from "./schema.js";
4
4
  // src/add-on.ts
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as Season, a as DirectUse, c as ENDURANCE_SCHEMA, d as Gift, f as Harvest, g as Resource, h as Prior, i as CutBound, l as Endurance, m as MonthDay, n as Converter, o as Draw, p as IsoDate, r as Cut, s as DrawEndurance, t as CaseCuts, u as EnduranceLayer, v as Store, y as Survival } from "./layer-DuGjz7Cl.js";
1
+ import { _ as Season, a as DirectUse, c as ENDURANCE_SCHEMA, d as Gift, f as Harvest, g as Resource, h as Prior, i as CutBound, l as Endurance, m as MonthDay, n as Converter, o as Draw, p as IsoDate, r as Cut, s as DrawEndurance, t as CaseCuts, u as EnduranceLayer, v as Store, y as Survival } from "./layer-CZZWJtM8.js";
2
2
  import { CutBound as CutBound$1, Fault, LayerParse, LayerPiece, PathOptions, Stack, curveFault, survivalAt } from "@mark1russell7/system-stack";
3
3
  /**
4
4
  * This function tells if a converter is a source (M2-solar): it takes nothing, and it has a limit `perDay` more than 0.
@@ -131,6 +131,9 @@ export declare function hasSeason(layer: EnduranceLayer, stoppedParts: ReadonlyS
131
131
  * - 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
132
132
  * draw uses them. With shares `monthly`, the device-days of a day are the devices times the share of its month. Each
133
133
  * span also ends at the start of a month, and a draw can hold again from the start of a month.
134
+ * - A store with a capacity that a source charges (M2-solar-charge-sweep) takes a charge. Each draw that can take it gets the
135
+ * programs of `bestEndurance` for itself alone, in the order of the levels. Thus one draw gets the days of `bestEndurance`.
136
+ * A lower draw takes only the level that the higher draws leave. It charges the store only with the device-days that they leave.
134
137
  *
135
138
  * 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.
136
139
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts","../src/sensitivity.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,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;;;;;;;;wBAmMxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,OAAO;;;;;;wBAOF,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;;;;;wBAkB9F,UAAU,OAAO,gBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2C/C,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBCrf7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;WAEA;;;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AM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,gBAAgB;;WAEhB,QAAQ,SAAS;;;iBAIX;WACN;WACA,IAAI;;WAEJ;;WAEA,MAAM;;WAEN,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2GZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB"}
1
+ {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts","../src/sensitivity.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,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;;;;;;;;wBAmMxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,OAAO;;;;;;wBAOF,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;;;;;wBAkB9F,UAAU,OAAO,gBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8C/C,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAA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Q;;WAER,OAAO;;WAEP,QAAQ;;WAER,aAAa;;WAEb,YAAY;;;iBAIN;WACN;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,SAAS;;;iBAIH;;;;;WAKN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,gBAAgB;;WAEhB,QAAQ,SAAS;;;iBAIX;WACN;WACA,IAAI;;WAEJ;;WAEA,MAAM;;WAEN,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2GZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
- import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as deviceKey, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as drawBlock, k as caseParts, l as drawDemand, m as monthEdges, 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 shareOf, w as seasonBest, x as fewestOpen, y as sowDays, z as isSource } from "./join-OKGUUCVQ.js";
2
+ import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as deviceKey, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as drawBlock, k as caseParts, l as drawDemand, m as monthEdges, 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 shareOf, w as seasonBest, x as fewestOpen, y as sowDays, z as isSource } from "./join-CxA4Td_Z.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";
@@ -282,6 +282,12 @@ function reachOf(parts, needs) {
282
282
  };
283
283
  }
284
284
  // src/seasonal.ts
285
+ /** This function gives the least of a list of rationals, or `none` for an empty list. */
286
+ function leastOf(values, none) {
287
+ let low;
288
+ for (const value of values) if (low === void 0 || sign(sub(value, low)) < 0) low = value;
289
+ return low ?? none;
290
+ }
285
291
  /**
286
292
  * This function gives the capacity of each resource whose stores have a capacity (M2-solar-charge). A store whose part is
287
293
  * in `stoppedParts` has no capacity. A store with a due date has no charge: the gate refuses a capacity with a due date.
@@ -298,8 +304,11 @@ function storeCapacities(layer, stoppedParts) {
298
304
  /**
299
305
  * This function gives the parts of the programs of a case with a season. `parts` are the parts of the case with the
300
306
  * stock after the sowings (`seasonSupply`).
307
+ *
308
+ * @param rests - The rest of each store with a capacity that the higher draws of the sweep leave (M2-solar-charge-sweep).
309
+ * A segment gets the least rest of the spans that it touches. This is the safe side.
301
310
  */
302
- function seasonPlan(supply, parts, caseCuts, draws, devices, capacities = /* @__PURE__ */ new Map()) {
311
+ function seasonPlan(supply, parts, caseCuts, draws, devices, capacities = /* @__PURE__ */ new Map(), rests = /* @__PURE__ */ new Map()) {
303
312
  const total = new Map(supply.stock);
304
313
  const harvests = supply.lots.map((lot, origin) => ({
305
314
  ...lot,
@@ -337,11 +346,19 @@ function seasonPlan(supply, parts, caseCuts, draws, devices, capacities = /* @__
337
346
  ])].sort((a, b) => a - b);
338
347
  const charges = charged.map((resource) => {
339
348
  const lot = lots.find((item) => item.resource === resource && item.origin === void 0);
349
+ const capacity = exact(Math.max(capacities.get(resource) ?? 0, toNumber(lot.amount)));
350
+ const rest = rests.get(resource) ?? [];
351
+ const spans = edges.slice(0, -1).map((from, index) => rest.filter((item) => item.from < (edges[index + 1] ?? 1e400) && item.to > from));
352
+ const take = spans.map((list) => leastOf(list.map((item) => item.take), lot.amount));
353
+ const fill = spans.map((list) => leastOf(list.map((item) => item.fill), sub(capacity, lot.amount)));
340
354
  return {
341
355
  resource,
342
- capacity: exact(Math.max(capacities.get(resource) ?? 0, toNumber(lot.amount))),
356
+ capacity,
343
357
  lot,
344
- sources: sourcesOf(resource)
358
+ sources: sourcesOf(resource),
359
+ take,
360
+ fill,
361
+ higher: rest.length > 0
345
362
  };
346
363
  });
347
364
  return {
@@ -418,14 +435,21 @@ function lotRows(program, plan, cells) {
418
435
  * - The takes of a segment are not more than the level at its start.
419
436
  * - The level at the start of a segment plus its charge is not more than the capacity.
420
437
  * Thus each order of the takes and the charges in a segment is a plan. The caller adds the charge columns to the rows of the device-days.
438
+ *
439
+ * With no higher draws, the right side of the takes is the amount of the lot. The right side of the charge is the capacity less that amount.
440
+ * With higher draws (M2-solar-charge-sweep), the right sides are the rest that they leave (`PlanCharge.take` and `fill`).
441
+ * Then each segment has the row of its charge, and two more rows keep the level after `through` in the rest of the later segments.
421
442
  */
422
443
  function addCharges(program, plan, cells, through) {
423
444
  const pairs = /* @__PURE__ */ new Map();
424
445
  const gifts = /* @__PURE__ */ new Map();
446
+ const segments = /* @__PURE__ */ new Map();
425
447
  for (const charge of plan.charges) {
426
448
  const level = /* @__PURE__ */ new Map();
427
449
  const given = /* @__PURE__ */ new Map();
450
+ const each = [];
428
451
  gifts.set(charge.resource, given);
452
+ segments.set(charge.resource, each);
429
453
  for (let segment = 0; segment < through; segment += 1) {
430
454
  const takes = /* @__PURE__ */ new Map();
431
455
  for (const cell of cells) {
@@ -434,28 +458,98 @@ function addCharges(program, plan, cells, through) {
434
458
  }
435
459
  const most = new Map(takes);
436
460
  for (const [column, value] of level) addTo(most, column, neg(value));
437
- program.push(most, "<=", charge.lot.amount);
461
+ program.push(most, "<=", charge.take[segment] ?? charge.lot.amount);
462
+ const full = new Map(level);
463
+ const own = /* @__PURE__ */ new Map();
464
+ each.push(own);
438
465
  if (segment + 1 < through) {
439
- const full = new Map(level);
440
466
  for (const source of charge.sources) {
441
467
  const column = program.next();
442
468
  pairs.set(segment, [...pairs.get(segment) ?? [], [source, column]]);
443
- const each = exact(source.gives.amount);
444
- addTo(full, column, each);
445
- addTo(level, column, each);
446
- addTo(given, column, each);
469
+ const amount = exact(source.gives.amount);
470
+ addTo(full, column, amount);
471
+ addTo(level, column, amount);
472
+ addTo(given, column, amount);
473
+ addTo(own, column, amount);
447
474
  }
448
- program.push(full, "<=", sub(charge.capacity, charge.lot.amount));
449
- }
475
+ program.push(full, "<=", charge.fill[segment] ?? sub(charge.capacity, charge.lot.amount));
476
+ } else if (charge.higher) program.push(full, "<=", charge.fill[segment] ?? ZERO);
450
477
  for (const [column, value] of takes) addTo(level, column, neg(value));
451
478
  }
479
+ if (charge.higher && through < segmentsOf(plan)) {
480
+ const less = /* @__PURE__ */ new Map();
481
+ for (const [column, value] of level) addTo(less, column, neg(value));
482
+ program.push(less, "<=", leastOf(charge.take.slice(through), ZERO));
483
+ program.push(new Map(level), "<=", leastOf(charge.fill.slice(through), ZERO));
484
+ }
452
485
  }
453
486
  return {
454
487
  pairs,
455
- gifts
488
+ gifts,
489
+ segments
456
490
  };
457
491
  }
458
492
  /**
493
+ * This function gives the most charge, the earliest first, as an objective (M2-solar-charge-sweep). The weight of the charge of
494
+ * a segment is the days from its start to the horizon. Thus the store keeps the highest level that it can for the lower draws.
495
+ */
496
+ function mostCharge(plan, charges, count) {
497
+ const most = /* @__PURE__ */ new Map();
498
+ const horizon = edgeOf(plan, segmentsOf(plan));
499
+ for (const rows of charges.segments.values()) rows.forEach((row, segment) => {
500
+ for (const [column, value] of row) addTo(most, column, mul(value, sub(horizon, edgeOf(plan, segment))));
501
+ });
502
+ return {
503
+ sense: "max",
504
+ coefficients: dense(most, count)
505
+ };
506
+ }
507
+ /**
508
+ * This function gives the rest of each store with a capacity in each segment (M2-solar-charge-sweep). It is the rest that the
509
+ * draws of a plan and the higher draws leave. The takes and the charges of the plan come out of the rest that the plan got.
510
+ */
511
+ function restsOf(plan, cells, x, charges) {
512
+ const out = /* @__PURE__ */ new Map();
513
+ for (const charge of plan.charges) {
514
+ const rows = charges.segments.get(charge.resource) ?? [];
515
+ let added = ZERO;
516
+ const list = [];
517
+ for (let segment = 0; segment < segmentsOf(plan); segment += 1) {
518
+ let taken = ZERO;
519
+ for (const cell of cells) if (cell.segment === segment) taken = add(taken, x[cell.takes.get(charge.lot) ?? -1] ?? ZERO);
520
+ const row = rows[segment];
521
+ const given = row === void 0 ? ZERO : valueAt(row, x);
522
+ const take = add(sub(charge.take[segment] ?? charge.lot.amount, taken), added);
523
+ const fill = sub(sub(charge.fill[segment] ?? ZERO, given), added);
524
+ list.push({
525
+ from: plan.edges[segment] ?? 0,
526
+ to: plan.edges[segment + 1] ?? 0,
527
+ take,
528
+ fill
529
+ });
530
+ added = add(added, sub(given, taken));
531
+ }
532
+ out.set(charge.resource, list);
533
+ }
534
+ return out;
535
+ }
536
+ /**
537
+ * This function gives the most device-days of one day that the charges of a plan use, by the key of the device (M2-solar-charge-sweep).
538
+ * The value comes before the shares `monthly`. The charge of a segment can come in equal parts on each of its days.
539
+ */
540
+ function chargeDaysOf(plan, charges, x) {
541
+ const out = /* @__PURE__ */ new Map();
542
+ for (const [segment, list] of charges.pairs) {
543
+ const length = toNumber(lengthOf(plan, segment));
544
+ if (!(length > 0)) continue;
545
+ for (const [key, limit] of deviceUse(list).limits) {
546
+ const share = shareIn(plan, segment, key);
547
+ if (share > 0) out.set(key, Math.max(out.get(key) ?? 0, toNumber(valueAt(limit.row, x)) / length / share));
548
+ }
549
+ }
550
+ return out;
551
+ }
552
+ /**
459
553
  * 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
460
554
  * 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.
461
555
  */
@@ -562,9 +656,14 @@ function firstStop(plan, fixed, open, tail = () => []) {
562
656
  const days = solved.values[0] ?? ZERO;
563
657
  const end = edgeOf(plan, segment + 1);
564
658
  if (segment + 1 < segments && equals(days, end)) continue;
565
- const full = tail(step).length === 0 ? solved : solveLexicographic(step.program.constraints(), [most, ...tail(step)]);
659
+ const later = tail(step);
660
+ const full = later.length === 0 ? solved : solveLexicographic([...step.program.constraints(), {
661
+ coefficients: most.coefficients,
662
+ relation: "=",
663
+ rhs: days
664
+ }], later);
566
665
  if (full.status !== "optimal") throw new Error("The step of a season has no optimum for its later objectives.");
567
- const first = full.stages[0]?.result;
666
+ const first = solved.stages[0]?.result;
568
667
  return {
569
668
  step,
570
669
  x: full.x,
@@ -662,8 +761,12 @@ function sharedKey(cells, key) {
662
761
  * In a segment after the stops, the cells of two draws or more that can use one limited device take turns. Their fed days
663
762
  * together are not more than the segment, and each one has the device-days of each day that the stops leave. This is the
664
763
  * safe side: the cells do not use one device at the same time. Each other cell starts at the start of the segment.
764
+ *
765
+ * @param fill - True for the sweep of `enduranceOf` (M2-solar-charge-sweep). Then the last objective is the most charge, the
766
+ * earliest first, and the result gives the rest of each store with a capacity. A store with a capacity is binding if the
767
+ * takes of the segment of the stop use all the level at its start.
665
768
  */
666
- function seasonBest(plan, fixed, levels, stored) {
769
+ function seasonBest(plan, fixed, levels, stored, fill = false) {
667
770
  const program = new Program();
668
771
  const cells = [];
669
772
  const kept = addFixed(program, plan, fixed, cells);
@@ -730,9 +833,18 @@ function seasonBest(plan, fixed, levels, stored) {
730
833
  sense: "min",
731
834
  coefficients: dense(fewestRow(cells.flatMap((cell) => [...cell.block.runs])), program.count)
732
835
  });
836
+ if (fill) objectives.push(mostCharge(plan, charges, program.count));
733
837
  const solved = solveLexicographic(program.constraints(), objectives);
734
838
  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.");
735
839
  const x = solved.x;
840
+ const rests = fill ? restsOf(plan, cells, x, charges) : void 0;
841
+ const charged = new Set(plan.charges.map((charge) => charge.resource));
842
+ const bound = (closure, segment) => {
843
+ const used = usedUp(plan, cells, x, closure, stored, charges);
844
+ if (rests === void 0) return used;
845
+ const empty = [...charged].filter((resource) => closure.has(resource) && stored.has(resource) && sign(rests.get(resource)?.[segment]?.take ?? ONE) <= 0);
846
+ return [...used.filter((resource) => !charged.has(resource)), ...empty].sort();
847
+ };
736
848
  const turn = /* @__PURE__ */ new Map();
737
849
  const offset = /* @__PURE__ */ new Map();
738
850
  for (const cell of [...taking].sort((a, b) => plan.draws.indexOf(a.draw) - plan.draws.indexOf(b.draw))) {
@@ -761,7 +873,7 @@ function seasonBest(plan, fixed, levels, stored) {
761
873
  const { closure } = reachOf(plan.parts, /* @__PURE__ */ new Set([draw.need]));
762
874
  needs[draw.need] = {
763
875
  days: toNumber(fix.stop),
764
- binding: fix.atHorizon ? [] : usedUp(plan, cells, x, closure, stored, charges),
876
+ binding: fix.atHorizon ? [] : bound(closure, fix.segment),
765
877
  takes: takesOf(cells, draw.need, x),
766
878
  ...fix.capped.length === 0 ? {} : { capped: fix.capped },
767
879
  ...fix.atHorizon ? { atHorizon: true } : {},
@@ -788,7 +900,9 @@ function seasonBest(plan, fixed, levels, stored) {
788
900
  return {
789
901
  needs,
790
902
  taken,
791
- perDay
903
+ perDay,
904
+ rests,
905
+ chargeDays: fill ? chargeDaysOf(plan, charges, x) : void 0
792
906
  };
793
907
  }
794
908
  /**
@@ -824,12 +938,20 @@ function seasonJoint(plan, stored) {
824
938
  * with a season (M2-grow-share-sweep). The take order cannot give the share of the device-days.
825
939
  * Thus the programs of `bestEndurance` give it for this one draw: the first stop, then the most fed days after it (`again`).
826
940
  *
827
- * @param stock - The stocks that the higher draws leave.
941
+ * The function also gives the endurance of a draw that can take a store with a capacity that a source charges (M2-solar-charge-sweep).
942
+ * - The takes of the store come from the rest that the higher draws leave (`rests`). Thus the takes and the charges of the higher draws stay possible.
943
+ * - The first stop takes the fewest stocks, thus the draw keeps the most runs of a source and the most level for the lower draws.
944
+ * - The last program charges the store as much as it can, the earliest first. The draw gives the rest that it leaves to the lower draws.
945
+ * - The device-days of the charge are a part of the device-days of the draw (`perDay`). Thus a lower draw cannot use them.
946
+ *
947
+ * @param stock - The stocks that the higher draws leave. The stock of a store with a charge is its amount on day 0, because the rest gives the takes of the higher draws.
828
948
  * @param lots - The rest of each harvest lot that the higher draws leave.
829
949
  * @param room - The device-days of each day that the higher draws leave, by the key of the device, before the shares `monthly`.
830
950
  * @param start - The first day of the event, for the months of the shares.
951
+ * @param capacities - The capacity of each resource whose stores have a capacity (`storeCapacities`).
952
+ * @param rests - The rest of each store with a capacity that the higher draws leave. With no rest, the store has its amount and its capacity.
831
953
  */
832
- function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, room, start) {
954
+ function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, room, start, capacities = /* @__PURE__ */ new Map(), rests = /* @__PURE__ */ new Map()) {
833
955
  const supply = {
834
956
  stock: new Map(stock),
835
957
  harvests: [],
@@ -837,20 +959,29 @@ function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, r
837
959
  horizon,
838
960
  start
839
961
  };
840
- const plan = seasonPlan(supply, caseParts(layer, stoppedParts, supply.stock, /* @__PURE__ */ new Set([draw.need])), caseCuts, [draw], room);
962
+ const plan = seasonPlan(supply, caseParts(layer, stoppedParts, supply.stock, /* @__PURE__ */ new Set([draw.need])), caseCuts, [draw], room, capacities, rests);
841
963
  const fixed = /* @__PURE__ */ new Map();
842
964
  const open = /* @__PURE__ */ new Set([draw.need]);
843
- fixStops(plan, firstStop(plan, fixed, [draw], (step) => [fewestOpen(step, open)]), [draw], fixed);
844
- const best = seasonBest(plan, fixed, [[draw]], new Set(layer.stores.map((store) => store.resource)));
965
+ const filled = plan.charges.length > 0;
966
+ const tail = (step) => filled ? [leastShares(plan, step.cells, step.program.count), fewestOpen(step, open)] : [fewestOpen(step, open)];
967
+ fixStops(plan, firstStop(plan, fixed, [draw], tail), [draw], fixed);
968
+ const best = seasonBest(plan, fixed, [[draw]], new Set(layer.stores.map((store) => store.resource)), filled);
845
969
  const left = new Map(stock);
846
970
  const rest = lots.map((lot) => lot.amount);
847
- for (const [lot, amount] of best.taken) if (lot.origin === void 0) left.set(lot.resource, Math.max(0, (left.get(lot.resource) ?? 0) - amount));
848
- else rest[lot.origin] = Math.max(0, (rest[lot.origin] ?? 0) - amount);
971
+ const chargedLots = new Set(plan.charges.map((charge) => charge.lot));
972
+ for (const [lot, amount] of best.taken) {
973
+ if (chargedLots.has(lot)) continue;
974
+ if (lot.origin === void 0) left.set(lot.resource, Math.max(0, (left.get(lot.resource) ?? 0) - amount));
975
+ else rest[lot.origin] = Math.max(0, (rest[lot.origin] ?? 0) - amount);
976
+ }
977
+ const perDay = new Map(best.perDay.get(draw.need) ?? []);
978
+ for (const [key, each] of best.chargeDays ?? /* @__PURE__ */ new Map()) perDay.set(key, (perDay.get(key) ?? 0) + each);
849
979
  return {
850
980
  need: best.needs[draw.need],
851
981
  stock: left,
852
982
  lots: rest,
853
- perDay: best.perDay.get(draw.need) ?? /* @__PURE__ */ new Map()
983
+ perDay,
984
+ rests: best.rests ?? /* @__PURE__ */ new Map()
854
985
  };
855
986
  }
856
987
  // src/share.ts
@@ -1326,6 +1457,9 @@ function hasSeason(layer, stoppedParts) {
1326
1457
  * - 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
1327
1458
  * draw uses them. With shares `monthly`, the device-days of a day are the devices times the share of its month. Each
1328
1459
  * span also ends at the start of a month, and a draw can hold again from the start of a month.
1460
+ * - A store with a capacity that a source charges (M2-solar-charge-sweep) takes a charge. Each draw that can take it gets the
1461
+ * programs of `bestEndurance` for itself alone, in the order of the levels. Thus one draw gets the days of `bestEndurance`.
1462
+ * A lower draw takes only the level that the higher draws leave. It charges the store only with the device-days that they leave.
1329
1463
  *
1330
1464
  * 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.
1331
1465
  *
@@ -1353,6 +1487,9 @@ function enduranceOf(layer, caseCuts, options) {
1353
1487
  const horizon = supply?.horizon ?? 1e400;
1354
1488
  const harvests = supply?.harvests ?? [];
1355
1489
  const later = (supply?.lots ?? []).map((lot) => ({ ...lot }));
1490
+ const capacities = storeCapacities(layer, stoppedParts);
1491
+ const chargedResources = new Set([...capacities.keys()].filter((resource) => (makers.get(resource) ?? []).some(isSource)));
1492
+ const rests = /* @__PURE__ */ new Map();
1356
1493
  const needs = {};
1357
1494
  for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {
1358
1495
  const ways = waysOf(layer, draw.need, stoppedParts, makers);
@@ -1383,16 +1520,18 @@ function enduranceOf(layer, caseCuts, options) {
1383
1520
  };
1384
1521
  };
1385
1522
  const shares = sharesDevice(reach);
1386
- if (shares && seasonal) {
1523
+ const charging = [...closure].some((resource) => chargedResources.has(resource));
1524
+ if ((shares || charging) && seasonal) {
1387
1525
  const lots = later.map((lot) => ({
1388
1526
  resource: lot.resource,
1389
1527
  day: lot.day,
1390
1528
  spoils: lot.spoils,
1391
1529
  amount: lot.amount
1392
1530
  }));
1393
- const held = seasonDraw(layer, stoppedParts, caseCuts, draw, resourcesOnly(before), lots, horizon, room, begin);
1531
+ const held = seasonDraw(layer, stoppedParts, caseCuts, draw, resourcesOnly(before), lots, horizon, room, begin, capacities, rests);
1394
1532
  needs[draw.need] = held.need;
1395
1533
  for (const [key, each] of held.perDay) used.set(key, (used.get(key) ?? 0) + each);
1534
+ for (const [resource, rest] of held.rests) rests.set(resource, rest);
1396
1535
  before = held.stock;
1397
1536
  for (const [index, amount] of held.lots.entries()) later[index].amount = amount;
1398
1537
  continue;
@@ -1904,4 +2043,4 @@ function joinEndurance(pieces) {
1904
2043
  }
1905
2044
  export { deviceUse as A, fixStops as C, storeCapacities as D, seasonPlan as E, addTo as F, dense as I, exact as L, fewestRow as M, reachOf as N, Program as O, valueAt as P, deviceKey as R, 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, drawBlock as j, caseParts 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, isSource as z };
1906
2045
 
1907
- //# sourceMappingURL=join-OKGUUCVQ.js.map
2046
+ //# sourceMappingURL=join-CxA4Td_Z.js.map