Repository navigation
Saving the operation cost of every period when each period is solved separately - #240
Merged
Merged
Conversation
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.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,vTotalRElecCostand the others) remain in the total system costeTotalTCost. The subsequent solve then sets them to zero. Since the cost summary andtotal_cost_meurin 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):total_cost_meur, masterThe 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 inpStageCostValuesback to the variables and setsvTotalSCostto the right-hand side ofeTotalTCost. 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,resolveandlshaped), as these do not callProblemSolving.After the change
The same three cases:
total_cost_meurvTotalSCostThe joint solve is unchanged to the last digit.
Notes
tests/test_stage_costs.pycontains 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.ProblemSolving; thevTotalSCostset by the stage decomposition is also retained.pScenProb, which the stage loop sets to 0.0 once the period is solved. This affects the console output only.vTotalSCostandtotal_cost_meurweight 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 ofStageIterativeSolving. This difference exists on master and is not addressed here.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.