Skip to content

Saving the operation cost of every period when each period is solved separately - #240

Merged
erikfilias merged 3 commits into
masterfrom
fix/cost-summary-saved-stage-costs
Nov 26, 2026
Merged

erikfilias merged 3 commits into
masterfrom
fix/cost-summary-saved-stage-costs

Conversation

@erikfilias

@erikfilias erikfilias commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #237.

Problem

When the investment decisions are ignored and no RES or emission target is imposed, openTEPES solves each period and scenario separately. After each solve, the constraints of that period are deactivated; however, its operation cost variables (vTotalGCost, vTotalCCost, vTotalNCost, vTotalRElecCost and the others) remain in the total system cost eTotalTCost. The subsequent solve then sets them to zero. Since the cost summary and total_cost_meur in the run status are evaluated after the last solve, both report the cost of the last period only. With a RES or emission target, each period is solved over all its stages at once, and the same loss occurs.

Commit 43af8bc stores the values in mTEPES.pStageCostValues, but no result writer reads them.

Observed behaviour

Case 9n7y, each period reduced to 24 h in each of two stages (st1, st2), solved with HiGHS. Total system cost (MEUR):

Joint solve (with investment) One solve per stage One solve per period (RES target kept)
Sum of the costs reported after each solve 10 353.87 10 843.52 10 843.52
Cost summary, master 10 353.87 1030.98 1810.62
total_cost_meur, master 10 353.87 1030.98 1810.62

The economic result files are correct. They are computed from the operation variables (output, charge and flows), which do not enter the objective and thus retain the values of their own solve. With one solve per period, their total over the seven periods is 10 843.5 MEUR.

Solution

restore_stage_costs, called once all solves are complete, writes the values stored in pStageCostValues back to the variables and sets vTotalSCost to the right-hand side of eTotalTCost. As a result, every reader of these variables (the cost summary, the run status and any user script) obtains the cost of every period without modification. The storing loop of 43af8bc is kept as it was, and it now also stores the hydrogen source cost and the AC current and voltage penalties, all of which also enter the total system cost.

The alternative proposed in the issue, i.e., reading pStageCostValues.get(key, var()) in the cost summary, was not adopted. It requires the same change in every reader. Moreover, it returns outdated values after any later re-solve of the full model (the AC restoration, resolve and lshaped), as these do not call ProblemSolving.

After the change

The same three cases:

Joint solve One solve per stage One solve per period (RES target kept)
Cost summary 10 353.87 10 843.52 10 843.52
total_cost_meur 10 353.87 10 843.52 10 843.52
vTotalSCost 10 353.87 10 843.52 10 843.52

The joint solve is unchanged to the last digit.

Notes

  • The new module tests/test_stage_costs.py contains two solve tests (about 6 s). The first fails on master, where the cost summary reports a generation cost of 0.0 MEUR for 2020 to 2045; the second checks that a joint solve is reported as before.
  • The stored values are written back only if at least one differs from its variable. Consequently, nothing changes after a joint solve or after the stage decomposition, which does not call ProblemSolving; the vTotalSCost set by the stage decomposition is also retained.
  • The console summary after the last solve still reports 0.0 MEUR for the earlier periods. It weights each period by pScenProb, which the stage loop sets to 0.0 once the period is solved. This affects the console output only.
  • With several scenarios solved separately, vTotalSCost and total_cost_meur weight the scenarios by their input probabilities, as the solves do. In contrast, the cost summary sums them with probability 1.0, as set at the end of StageIterativeSolving. This difference exists on master and is not addressed here.
  • The hydrogen source cost (vTotalH2SrcCost) enters the total system cost but has no row in the cost summary. It is stored and written back as the other cost variables are; the missing row is addressed in a separate pull request.

When the investment decisions are ignored, each period is solved alone and its
constraints are deactivated afterwards. Its cost variables stay in the total
system cost, so every later solve set them to zero, and the cost summary and the
run status reported only the last period.

ProblemSolving now keeps the cost values of every block that was active in a
solve, and the stage loop puts them back, with the total system cost, once all
solves are done. A joint solve gives the same results as before.

Closes #237.
@erikfilias erikfilias changed the title Keep the cost of every period when each period is solved alone Retain the Operation Cost of Every Period When Each Period Is Solved Separately Nov 26, 2026
@erikfilias erikfilias changed the title Retain the Operation Cost of Every Period When Each Period Is Solved Separately Saving the operation cost of every period when each period is solved separately Nov 26, 2026
…to it

save_stage_costs is removed. The loop of 43af8bc already stores every
period when each period is solved alone, which is the only case where the
values are restored. It now also stores the hydrogen source cost and the AC
penalties. The joint solve test checks that the results are unchanged.
@erikfilias
erikfilias merged commit 9a7e15a into master Nov 26, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cost summary loses earlier periods when each period is solved separately

1 participant