@mark1russell7/stack-endurance 0.8.22 → 0.8.23

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-BXx4xoUc.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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M;;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,cAAc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;;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-BXx4xoUc.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
  */
@@ -662,8 +756,12 @@ function sharedKey(cells, key) {
662
756
  * 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
757
  * 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
758
  * safe side: the cells do not use one device at the same time. Each other cell starts at the start of the segment.
759
+ *
760
+ * @param fill - True for the sweep of `enduranceOf` (M2-solar-charge-sweep). Then the last objective is the most charge, the
761
+ * earliest first, and the result gives the rest of each store with a capacity. A store with a capacity is binding if the
762
+ * takes of the segment of the stop use all the level at its start.
665
763
  */
666
- function seasonBest(plan, fixed, levels, stored) {
764
+ function seasonBest(plan, fixed, levels, stored, fill = false) {
667
765
  const program = new Program();
668
766
  const cells = [];
669
767
  const kept = addFixed(program, plan, fixed, cells);
@@ -730,9 +828,18 @@ function seasonBest(plan, fixed, levels, stored) {
730
828
  sense: "min",
731
829
  coefficients: dense(fewestRow(cells.flatMap((cell) => [...cell.block.runs])), program.count)
732
830
  });
831
+ if (fill) objectives.push(mostCharge(plan, charges, program.count));
733
832
  const solved = solveLexicographic(program.constraints(), objectives);
734
833
  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
834
  const x = solved.x;
835
+ const rests = fill ? restsOf(plan, cells, x, charges) : void 0;
836
+ const charged = new Set(plan.charges.map((charge) => charge.resource));
837
+ const bound = (closure, segment) => {
838
+ const used = usedUp(plan, cells, x, closure, stored, charges);
839
+ if (rests === void 0) return used;
840
+ const empty = [...charged].filter((resource) => closure.has(resource) && stored.has(resource) && sign(rests.get(resource)?.[segment]?.take ?? ONE) <= 0);
841
+ return [...used.filter((resource) => !charged.has(resource)), ...empty].sort();
842
+ };
736
843
  const turn = /* @__PURE__ */ new Map();
737
844
  const offset = /* @__PURE__ */ new Map();
738
845
  for (const cell of [...taking].sort((a, b) => plan.draws.indexOf(a.draw) - plan.draws.indexOf(b.draw))) {
@@ -761,7 +868,7 @@ function seasonBest(plan, fixed, levels, stored) {
761
868
  const { closure } = reachOf(plan.parts, /* @__PURE__ */ new Set([draw.need]));
762
869
  needs[draw.need] = {
763
870
  days: toNumber(fix.stop),
764
- binding: fix.atHorizon ? [] : usedUp(plan, cells, x, closure, stored, charges),
871
+ binding: fix.atHorizon ? [] : bound(closure, fix.segment),
765
872
  takes: takesOf(cells, draw.need, x),
766
873
  ...fix.capped.length === 0 ? {} : { capped: fix.capped },
767
874
  ...fix.atHorizon ? { atHorizon: true } : {},
@@ -788,7 +895,9 @@ function seasonBest(plan, fixed, levels, stored) {
788
895
  return {
789
896
  needs,
790
897
  taken,
791
- perDay
898
+ perDay,
899
+ rests,
900
+ chargeDays: fill ? chargeDaysOf(plan, charges, x) : void 0
792
901
  };
793
902
  }
794
903
  /**
@@ -824,12 +933,20 @@ function seasonJoint(plan, stored) {
824
933
  * with a season (M2-grow-share-sweep). The take order cannot give the share of the device-days.
825
934
  * Thus the programs of `bestEndurance` give it for this one draw: the first stop, then the most fed days after it (`again`).
826
935
  *
827
- * @param stock - The stocks that the higher draws leave.
936
+ * 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).
937
+ * - 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.
938
+ * - 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.
939
+ * - 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.
940
+ * - The device-days of the charge are a part of the device-days of the draw (`perDay`). Thus a lower draw cannot use them.
941
+ *
942
+ * @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
943
  * @param lots - The rest of each harvest lot that the higher draws leave.
829
944
  * @param room - The device-days of each day that the higher draws leave, by the key of the device, before the shares `monthly`.
830
945
  * @param start - The first day of the event, for the months of the shares.
946
+ * @param capacities - The capacity of each resource whose stores have a capacity (`storeCapacities`).
947
+ * @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
948
  */
832
- function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, room, start) {
949
+ function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, room, start, capacities = /* @__PURE__ */ new Map(), rests = /* @__PURE__ */ new Map()) {
833
950
  const supply = {
834
951
  stock: new Map(stock),
835
952
  harvests: [],
@@ -837,20 +954,29 @@ function seasonDraw(layer, stoppedParts, caseCuts, draw, stock, lots, horizon, r
837
954
  horizon,
838
955
  start
839
956
  };
840
- const plan = seasonPlan(supply, caseParts(layer, stoppedParts, supply.stock, /* @__PURE__ */ new Set([draw.need])), caseCuts, [draw], room);
957
+ const plan = seasonPlan(supply, caseParts(layer, stoppedParts, supply.stock, /* @__PURE__ */ new Set([draw.need])), caseCuts, [draw], room, capacities, rests);
841
958
  const fixed = /* @__PURE__ */ new Map();
842
959
  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)));
960
+ const filled = plan.charges.length > 0;
961
+ const tail = (step) => filled ? [leastShares(plan, step.cells, step.program.count), fewestOpen(step, open)] : [fewestOpen(step, open)];
962
+ fixStops(plan, firstStop(plan, fixed, [draw], tail), [draw], fixed);
963
+ const best = seasonBest(plan, fixed, [[draw]], new Set(layer.stores.map((store) => store.resource)), filled);
845
964
  const left = new Map(stock);
846
965
  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);
966
+ const chargedLots = new Set(plan.charges.map((charge) => charge.lot));
967
+ for (const [lot, amount] of best.taken) {
968
+ if (chargedLots.has(lot)) continue;
969
+ if (lot.origin === void 0) left.set(lot.resource, Math.max(0, (left.get(lot.resource) ?? 0) - amount));
970
+ else rest[lot.origin] = Math.max(0, (rest[lot.origin] ?? 0) - amount);
971
+ }
972
+ const perDay = new Map(best.perDay.get(draw.need) ?? []);
973
+ for (const [key, each] of best.chargeDays ?? /* @__PURE__ */ new Map()) perDay.set(key, (perDay.get(key) ?? 0) + each);
849
974
  return {
850
975
  need: best.needs[draw.need],
851
976
  stock: left,
852
977
  lots: rest,
853
- perDay: best.perDay.get(draw.need) ?? /* @__PURE__ */ new Map()
978
+ perDay,
979
+ rests: best.rests ?? /* @__PURE__ */ new Map()
854
980
  };
855
981
  }
856
982
  // src/share.ts
@@ -1326,6 +1452,9 @@ function hasSeason(layer, stoppedParts) {
1326
1452
  * - 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
1453
  * draw uses them. With shares `monthly`, the device-days of a day are the devices times the share of its month. Each
1328
1454
  * span also ends at the start of a month, and a draw can hold again from the start of a month.
1455
+ * - A store with a capacity that a source charges (M2-solar-charge-sweep) takes a charge. Each draw that can take it gets the
1456
+ * programs of `bestEndurance` for itself alone, in the order of the levels. Thus one draw gets the days of `bestEndurance`.
1457
+ * 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
1458
  *
1330
1459
  * 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
1460
  *
@@ -1353,6 +1482,9 @@ function enduranceOf(layer, caseCuts, options) {
1353
1482
  const horizon = supply?.horizon ?? 1e400;
1354
1483
  const harvests = supply?.harvests ?? [];
1355
1484
  const later = (supply?.lots ?? []).map((lot) => ({ ...lot }));
1485
+ const capacities = storeCapacities(layer, stoppedParts);
1486
+ const chargedResources = new Set([...capacities.keys()].filter((resource) => (makers.get(resource) ?? []).some(isSource)));
1487
+ const rests = /* @__PURE__ */ new Map();
1356
1488
  const needs = {};
1357
1489
  for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {
1358
1490
  const ways = waysOf(layer, draw.need, stoppedParts, makers);
@@ -1383,16 +1515,18 @@ function enduranceOf(layer, caseCuts, options) {
1383
1515
  };
1384
1516
  };
1385
1517
  const shares = sharesDevice(reach);
1386
- if (shares && seasonal) {
1518
+ const charging = [...closure].some((resource) => chargedResources.has(resource));
1519
+ if ((shares || charging) && seasonal) {
1387
1520
  const lots = later.map((lot) => ({
1388
1521
  resource: lot.resource,
1389
1522
  day: lot.day,
1390
1523
  spoils: lot.spoils,
1391
1524
  amount: lot.amount
1392
1525
  }));
1393
- const held = seasonDraw(layer, stoppedParts, caseCuts, draw, resourcesOnly(before), lots, horizon, room, begin);
1526
+ const held = seasonDraw(layer, stoppedParts, caseCuts, draw, resourcesOnly(before), lots, horizon, room, begin, capacities, rests);
1394
1527
  needs[draw.need] = held.need;
1395
1528
  for (const [key, each] of held.perDay) used.set(key, (used.get(key) ?? 0) + each);
1529
+ for (const [resource, rest] of held.rests) rests.set(resource, rest);
1396
1530
  before = held.stock;
1397
1531
  for (const [index, amount] of held.lots.entries()) later[index].amount = amount;
1398
1532
  continue;
@@ -1904,4 +2038,4 @@ function joinEndurance(pieces) {
1904
2038
  }
1905
2039
  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
2040
 
1907
- //# sourceMappingURL=join-OKGUUCVQ.js.map
2041
+ //# sourceMappingURL=join-BXx4xoUc.js.map