Skip to content

Commit

Permalink
Fix gradient test
Browse files Browse the repository at this point in the history
This functionality had no unit test, thus the constreaint test was not
fixed in the last commit.
  • Loading branch information
p-snft committed Jun 12, 2024
1 parent 89cf222 commit 86e63f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/oemof/solph/flows/_simple_flow_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _positive_gradient_flow_rule(model):
"""Rule definition for positive gradient constraint."""
for inp, out in self.POSITIVE_GRADIENT_FLOWS:
for index in range(1, len(m.TIMESTEPS) + 1):
if m.TIMESTEPS.at(index)[1] > 0:
if m.TIMESTEPS.at(index) > 0:
lhs = (
m.flow[
inp,
Expand All @@ -269,7 +269,7 @@ def _positive_gradient_flow_rule(model):
]
)
rhs = self.positive_gradient[
inp, out, m.TIMESTEPS.at(index)[1]
inp, out, m.TIMESTEPS.at(index)
]
self.positive_gradient_constr.add(
(inp, out, m.TIMESTEPS.at(index)),
Expand Down
52 changes: 26 additions & 26 deletions tests/lp_files/source_with_gradient.lp
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@

min
objective:
+23 flow(powerplant_electricityBus_0_0)
+23 flow(powerplant_electricityBus_0_1)
+23 flow(powerplant_electricityBus_0_2)
+23 flow(powerplant_electricityBus_0)
+23 flow(powerplant_electricityBus_1)
+23 flow(powerplant_electricityBus_2)

s.t.

c_e_BusBlock_balance(electricityBus_0_0)_:
+1 flow(powerplant_electricityBus_0_0)
c_e_BusBlock_balance(electricityBus_0)_:
+1 flow(powerplant_electricityBus_0)
= 0

c_e_BusBlock_balance(electricityBus_0_1)_:
+1 flow(powerplant_electricityBus_0_1)
c_e_BusBlock_balance(electricityBus_1)_:
+1 flow(powerplant_electricityBus_1)
= 0

c_e_BusBlock_balance(electricityBus_0_2)_:
+1 flow(powerplant_electricityBus_0_2)
c_e_BusBlock_balance(electricityBus_2)_:
+1 flow(powerplant_electricityBus_2)
= 0

c_e_SimpleFlowBlock_positive_gradient_constr(powerplant_electricityBus_0_0)_:
c_e_SimpleFlowBlock_positive_gradient_constr(powerplant_electricityBus_0)_:
+1 SimpleFlowBlock_positive_gradient(powerplant_electricityBus_0)
= 0

c_u_SimpleFlowBlock_positive_gradient_constr(powerplant_electricityBus_0_1)_:
-1 flow(powerplant_electricityBus_0_0)
+1 flow(powerplant_electricityBus_0_1)
c_u_SimpleFlowBlock_positive_gradient_constr(powerplant_electricityBus_1)_:
-1 flow(powerplant_electricityBus_0)
+1 flow(powerplant_electricityBus_1)
-1 SimpleFlowBlock_positive_gradient(powerplant_electricityBus_1)
<= 0

c_u_SimpleFlowBlock_positive_gradient_constr(powerplant_electricityBus_0_2)_:
-1 flow(powerplant_electricityBus_0_1)
+1 flow(powerplant_electricityBus_0_2)
c_u_SimpleFlowBlock_positive_gradient_constr(powerplant_electricityBus_2)_:
-1 flow(powerplant_electricityBus_1)
+1 flow(powerplant_electricityBus_2)
-1 SimpleFlowBlock_positive_gradient(powerplant_electricityBus_2)
<= 0

c_e_SimpleFlowBlock_negative_gradient_constr(powerplant_electricityBus_0_0)_:
c_e_SimpleFlowBlock_negative_gradient_constr(powerplant_electricityBus_0)_:
+1 SimpleFlowBlock_negative_gradient(powerplant_electricityBus_0)
= 0

c_u_SimpleFlowBlock_negative_gradient_constr(powerplant_electricityBus_0_1)_:
+1 flow(powerplant_electricityBus_0_0)
-1 flow(powerplant_electricityBus_0_1)
c_u_SimpleFlowBlock_negative_gradient_constr(powerplant_electricityBus_1)_:
+1 flow(powerplant_electricityBus_0)
-1 flow(powerplant_electricityBus_1)
-1 SimpleFlowBlock_negative_gradient(powerplant_electricityBus_1)
<= 0

c_u_SimpleFlowBlock_negative_gradient_constr(powerplant_electricityBus_0_2)_:
+1 flow(powerplant_electricityBus_0_1)
-1 flow(powerplant_electricityBus_0_2)
c_u_SimpleFlowBlock_negative_gradient_constr(powerplant_electricityBus_2)_:
+1 flow(powerplant_electricityBus_1)
-1 flow(powerplant_electricityBus_2)
-1 SimpleFlowBlock_negative_gradient(powerplant_electricityBus_2)
<= 0

bounds
0 <= flow(powerplant_electricityBus_0_0) <= 999
0 <= flow(powerplant_electricityBus_0_1) <= 999
0 <= flow(powerplant_electricityBus_0_2) <= 999
0 <= flow(powerplant_electricityBus_0) <= 999
0 <= flow(powerplant_electricityBus_1) <= 999
0 <= flow(powerplant_electricityBus_2) <= 999
0 <= SimpleFlowBlock_positive_gradient(powerplant_electricityBus_0) <= 29.97
0 <= SimpleFlowBlock_positive_gradient(powerplant_electricityBus_1) <= 29.97
0 <= SimpleFlowBlock_positive_gradient(powerplant_electricityBus_2) <= 29.97
Expand Down

0 comments on commit 86e63f8

Please sign in to comment.