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

Adjust indexing for content of InvestStorageBlock #1038

Closed
wants to merge 5 commits into from
Closed
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
10 changes: 5 additions & 5 deletions src/oemof/solph/components/_generic_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ def _create(self, group=None):

# ######################### Variables ################################
self.storage_content = Var(
self.INVESTSTORAGES, m.TIMESTEPS, within=NonNegativeReals
self.INVESTSTORAGES, m.TIMEPOINTS, within=NonNegativeReals
)

def _storage_investvar_bound_rule(block, n, p):
Expand Down Expand Up @@ -1527,13 +1527,13 @@ def _storage_balance_first_rule(block, n):

def _storage_balance_rule(block, n, p, t):
"""
Rule definition for the storage balance of every storage n
for every time step but the first.
Rule definition for the storage balance of every storage n and
every timestep.
"""
expr = 0
expr += block.storage_content[n, t]
expr += block.storage_content[n, t + 1]
expr += (
-block.storage_content[n, t - 1]
-block.storage_content[n, t]
* (1 - n.loss_rate[t]) ** m.timeincrement[t]
)
expr += (
Expand Down
97 changes: 49 additions & 48 deletions tests/lp_files/connect_investment.lp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

min
objective:
+500 InvestmentFlowBlock_invest(Bus1_Sink_0)
+123 InvestmentFlowBlock_invest(Source_Bus1_0)
+500 InvestmentFlowBlock_invest(Bus1_Sink_0)
+145 GenericInvestmentStorageBlock_invest(storage_0)

s.t.

c_e__equate_InvestmentFlowBlock_invest(Source_Bus1_0)_InvestmentFlowBlock_invest(Bus1_Sink_0)__:
-1 InvestmentFlowBlock_invest(Bus1_Sink_0)
+2 InvestmentFlowBlock_invest(Source_Bus1_0)
-1 InvestmentFlowBlock_invest(Bus1_Sink_0)
= 0

c_e__equate_InvestmentFlowBlock_invest(Source_Bus1_0)_GenericInvestmentStorageBlock_invest(storage_0)__:
Expand Down Expand Up @@ -39,25 +39,40 @@ c_e_BusBlock_balance(Bus1_0_2)_:
-1 flow(Bus1_Sink_0_2)
= 0

c_e_InvestmentFlowBlock_total_rule(Source_Bus1_0)_:
-1 InvestmentFlowBlock_invest(Source_Bus1_0)
+1 InvestmentFlowBlock_total(Source_Bus1_0)
= 0

c_e_InvestmentFlowBlock_total_rule(storage_Bus1_0)_:
+1 InvestmentFlowBlock_total(storage_Bus1_0)
-1 InvestmentFlowBlock_invest(storage_Bus1_0)
= 0

c_e_InvestmentFlowBlock_total_rule(Bus1_storage_0)_:
+1 InvestmentFlowBlock_total(Bus1_storage_0)
-1 InvestmentFlowBlock_invest(Bus1_storage_0)
= 0

c_e_InvestmentFlowBlock_total_rule(Bus1_Sink_0)_:
-1 InvestmentFlowBlock_invest(Bus1_Sink_0)
+1 InvestmentFlowBlock_total(Bus1_Sink_0)
= 0

c_e_InvestmentFlowBlock_total_rule(Source_Bus1_0)_:
-1 InvestmentFlowBlock_invest(Source_Bus1_0)
+1 InvestmentFlowBlock_total(Source_Bus1_0)
= 0
c_u_InvestmentFlowBlock_max(Source_Bus1_0_0)_:
+1 flow(Source_Bus1_0_0)
-1 InvestmentFlowBlock_total(Source_Bus1_0)
<= 0

c_e_InvestmentFlowBlock_total_rule(Bus1_storage_0)_:
+1 InvestmentFlowBlock_total(Bus1_storage_0)
-1 InvestmentFlowBlock_invest(Bus1_storage_0)
= 0
c_u_InvestmentFlowBlock_max(Source_Bus1_0_1)_:
+1 flow(Source_Bus1_0_1)
-1 InvestmentFlowBlock_total(Source_Bus1_0)
<= 0

c_u_InvestmentFlowBlock_max(Source_Bus1_0_2)_:
+1 flow(Source_Bus1_0_2)
-1 InvestmentFlowBlock_total(Source_Bus1_0)
<= 0

c_u_InvestmentFlowBlock_max(storage_Bus1_0_0)_:
+1 flow(storage_Bus1_0_0)
Expand All @@ -74,36 +89,6 @@ c_u_InvestmentFlowBlock_max(storage_Bus1_0_2)_:
-1 InvestmentFlowBlock_total(storage_Bus1_0)
<= 0

c_u_InvestmentFlowBlock_max(Bus1_Sink_0_0)_:
+1 flow(Bus1_Sink_0_0)
-1 InvestmentFlowBlock_total(Bus1_Sink_0)
<= 0

c_u_InvestmentFlowBlock_max(Bus1_Sink_0_1)_:
+1 flow(Bus1_Sink_0_1)
-1 InvestmentFlowBlock_total(Bus1_Sink_0)
<= 0

c_u_InvestmentFlowBlock_max(Bus1_Sink_0_2)_:
+1 flow(Bus1_Sink_0_2)
-1 InvestmentFlowBlock_total(Bus1_Sink_0)
<= 0

c_u_InvestmentFlowBlock_max(Source_Bus1_0_0)_:
+1 flow(Source_Bus1_0_0)
-1 InvestmentFlowBlock_total(Source_Bus1_0)
<= 0

c_u_InvestmentFlowBlock_max(Source_Bus1_0_1)_:
+1 flow(Source_Bus1_0_1)
-1 InvestmentFlowBlock_total(Source_Bus1_0)
<= 0

c_u_InvestmentFlowBlock_max(Source_Bus1_0_2)_:
+1 flow(Source_Bus1_0_2)
-1 InvestmentFlowBlock_total(Source_Bus1_0)
<= 0

c_u_InvestmentFlowBlock_max(Bus1_storage_0_0)_:
+1 flow(Bus1_storage_0_0)
-1 InvestmentFlowBlock_total(Bus1_storage_0)
Expand All @@ -119,6 +104,21 @@ c_u_InvestmentFlowBlock_max(Bus1_storage_0_2)_:
-1 InvestmentFlowBlock_total(Bus1_storage_0)
<= 0

c_u_InvestmentFlowBlock_max(Bus1_Sink_0_0)_:
+1 flow(Bus1_Sink_0_0)
-1 InvestmentFlowBlock_total(Bus1_Sink_0)
<= 0

c_u_InvestmentFlowBlock_max(Bus1_Sink_0_1)_:
+1 flow(Bus1_Sink_0_1)
-1 InvestmentFlowBlock_total(Bus1_Sink_0)
<= 0

c_u_InvestmentFlowBlock_max(Bus1_Sink_0_2)_:
+1 flow(Bus1_Sink_0_2)
-1 InvestmentFlowBlock_total(Bus1_Sink_0)
<= 0

c_e_GenericInvestmentStorageBlock_total_storage_rule(storage_0)_:
-1 GenericInvestmentStorageBlock_invest(storage_0)
+1 GenericInvestmentStorageBlock_total(storage_0)
Expand All @@ -139,15 +139,15 @@ c_e_GenericInvestmentStorageBlock_balance_first(storage)_:
c_e_GenericInvestmentStorageBlock_balance(storage_0_1)_:
+1 flow(storage_Bus1_0_1)
-1 flow(Bus1_storage_0_1)
-1 GenericInvestmentStorageBlock_storage_content(storage_0)
+1 GenericInvestmentStorageBlock_storage_content(storage_1)
+1 GenericInvestmentStorageBlock_storage_content(storage_2)
-1 GenericInvestmentStorageBlock_storage_content(storage_1)
= 0

c_e_GenericInvestmentStorageBlock_balance(storage_0_2)_:
+1 flow(storage_Bus1_0_2)
-1 flow(Bus1_storage_0_2)
-1 GenericInvestmentStorageBlock_storage_content(storage_1)
+1 GenericInvestmentStorageBlock_storage_content(storage_2)
-1 GenericInvestmentStorageBlock_storage_content(storage_2)
+1 GenericInvestmentStorageBlock_storage_content(storage_3)
= 0

c_e_GenericInvestmentStorageBlock_balanced_cstr(storage)_:
Expand Down Expand Up @@ -181,8 +181,8 @@ c_u_GenericInvestmentStorageBlock_max_storage_content(storage_0_2)_:
<= 0

bounds
0 <= InvestmentFlowBlock_invest(Bus1_Sink_0) <= +inf
0 <= InvestmentFlowBlock_invest(Source_Bus1_0) <= +inf
0 <= InvestmentFlowBlock_invest(Bus1_Sink_0) <= +inf
0 <= GenericInvestmentStorageBlock_invest(storage_0) <= +inf
0 <= flow(Source_Bus1_0_0) <= +inf
0 <= flow(storage_Bus1_0_0) <= +inf
Expand All @@ -196,15 +196,16 @@ bounds
0 <= flow(storage_Bus1_0_2) <= +inf
0 <= flow(Bus1_storage_0_2) <= +inf
0 <= flow(Bus1_Sink_0_2) <= +inf
0 <= InvestmentFlowBlock_total(Source_Bus1_0) <= +inf
0 <= InvestmentFlowBlock_total(storage_Bus1_0) <= +inf
0 <= InvestmentFlowBlock_invest(storage_Bus1_0) <= +inf
0 <= InvestmentFlowBlock_total(Bus1_Sink_0) <= +inf
0 <= InvestmentFlowBlock_total(Source_Bus1_0) <= +inf
0 <= InvestmentFlowBlock_total(Bus1_storage_0) <= +inf
0 <= InvestmentFlowBlock_invest(Bus1_storage_0) <= +inf
0 <= InvestmentFlowBlock_total(Bus1_Sink_0) <= +inf
0 <= GenericInvestmentStorageBlock_total(storage_0) <= +inf
0 <= GenericInvestmentStorageBlock_init_content(storage) <= +inf
0 <= GenericInvestmentStorageBlock_storage_content(storage_0) <= +inf
0 <= GenericInvestmentStorageBlock_storage_content(storage_1) <= +inf
0 <= GenericInvestmentStorageBlock_storage_content(storage_2) <= +inf
0 <= GenericInvestmentStorageBlock_storage_content(storage_1) <= +inf
0 <= GenericInvestmentStorageBlock_storage_content(storage_3) <= +inf
end
Loading
Loading