Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate Mipgap in the meta results #1143

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Authors
* Jonathan Amme
* Julian Endres
* Lluis Millet
* Lena Rosin
* Lennart Schürmann
* Martin Soethe
* Marie-Claire Gering
Expand Down
4 changes: 4 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,8 @@ authors:
family-names: Gering
given-names: Marie-Claire
alias: "@MaGering"
-
family-names: Rosin
given-names: Lena
alias: "@leroum"
...
2 changes: 2 additions & 0 deletions docs/whatsnew/v0-5-6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Bug fixes
#########

* Update required Pyomo version to allow working with numpy >= 2.0.0.
* Mipgap is calculated in the meta results

Known issues
############
Expand All @@ -15,3 +16,4 @@ Contributors
############

* Patrik Schönfeldt
* Lena Rosin
7 changes: 7 additions & 0 deletions src/oemof/solph/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@
meta_res[k1][k2] = msg.format(
type(om.es.results[k1][0][k2])
)
try:
meta_res["problem"]["MIPGap"] = (
meta_res["problem"]["Upper bound"]
- meta_res["problem"]["Lower bound"]
) / meta_res["problem"]["Lower bound"]
except KeyError:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.
pass

return meta_res

Expand Down
13 changes: 13 additions & 0 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ def setup_class(cls):
cls.mod = Model(cls.es)
cls.mod.solve()

def test_mipgap(self):
"""Test that one can access the MIPGap."""
meta = processing.meta_results(self.om)
assert "MIPGap" in meta["problem"], (
'No "MIPGap" in `meta_results`.'
" Maybe you're using solver other than cbc or gurobi?"
)
assert meta["problem"]["MIPGap"] == 0, (
"Incorrect MIPGap value."
"\nExpected: `0`"
f"\nGot: `{meta['problem']['MIPGap']}`"
)

def test_flows_with_none_exclusion(self):
b_el2 = self.es.groups["b_el2"]
demand = self.es.groups["demand_el"]
Expand Down
Loading