Skip to content

Commit

Permalink
Add unittests for lower integral limit
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Aug 2, 2024
1 parent aa736eb commit 1705996
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
23 changes: 23 additions & 0 deletions tests/constraint_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,29 @@ def test_flow_without_emission_for_emission_constraint_no_error(self):

self.compare_lp_files("emission_limit_no_error.lp", my_om=om)

def test_flow_without_emission_for_emission_constraint_lower(self):
"""Test that no error is thrown if no flows are explicitly passed"""
bel = solph.buses.Bus(label="electricityBus")
source1 = solph.components.Source(
label="source1",
outputs={
bel: solph.flows.Flow(
nominal_value=100,
custom_attributes={"emission_factor": 0.8},
)
},
)
source2 = solph.components.Source(
label="source2", outputs={bel: solph.flows.Flow(nominal_value=100)}
)
self.energysystem.add(bel, source1, source2)
om = self.get_om()
solph.constraints.generic_integral_limit(
om, keyword="emission_factor", lower_limit=777
)

self.compare_lp_files("emission_limit_lower.lp", my_om=om)

def test_equate_variables_constraint(self):
"""Testing the equate_variables function in the constraint module."""
bus1 = solph.buses.Bus(label="Bus1")
Expand Down
38 changes: 38 additions & 0 deletions tests/lp_files/emission_limit_lower.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
\* Source Pyomo model name=Model *\

min
objective:
+0 ONE_VAR_CONSTANT

s.t.

c_l_integral_limit_emission_factor_lower_limit_:
+0.8 flow(source1_electricityBus_0)
+0.8 flow(source1_electricityBus_1)
+0.8 flow(source1_electricityBus_2)
>= 777

c_e_BusBlock_balance(electricityBus_0)_:
+1 flow(source1_electricityBus_0)
+1 flow(source2_electricityBus_0)
= 0

c_e_BusBlock_balance(electricityBus_1)_:
+1 flow(source1_electricityBus_1)
+1 flow(source2_electricityBus_1)
= 0

c_e_BusBlock_balance(electricityBus_2)_:
+1 flow(source1_electricityBus_2)
+1 flow(source2_electricityBus_2)
= 0

bounds
1 <= ONE_VAR_CONSTANT <= 1
0 <= flow(source1_electricityBus_0) <= 100
0 <= flow(source1_electricityBus_1) <= 100
0 <= flow(source1_electricityBus_2) <= 100
0 <= flow(source2_electricityBus_0) <= 100
0 <= flow(source2_electricityBus_1) <= 100
0 <= flow(source2_electricityBus_2) <= 100
end
11 changes: 7 additions & 4 deletions tests/test_constraints_module.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest

import pandas as pd

from oemof import solph


def test_special():
def test_integral_limit_wrapper():
date_time_index = pd.date_range("1/1/2012", periods=5, freq="h")
energysystem = solph.EnergySystem(
timeindex=date_time_index,
Expand All @@ -22,9 +24,10 @@ def test_special():
flow_with_keyword = {
(src1, bel): flow1,
}
solph.constraints.generic_integral_limit(
model, "my_factor", flow_with_keyword, limit=777
)
with pytest.warns(FutureWarning):
solph.constraints.generic_integral_limit(
model, "my_factor", flow_with_keyword, limit=777
)


def test_something_else():
Expand Down

0 comments on commit 1705996

Please sign in to comment.