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

Update optimization.py #135

Merged
merged 2 commits into from
Dec 15, 2023
Merged

Update optimization.py #135

merged 2 commits into from
Dec 15, 2023

Conversation

michaelpiron
Copy link
Contributor

@michaelpiron michaelpiron commented Dec 11, 2023

Implemented changes:

  • Inverted the objective formulas in the case of "grid cost" cost function
  • Changed the cost calculation to be consistent with the objective formula, in case of "grid cost" cost function (the cost calculation didn't distinguish between set_total_pv_sell = TRUE vs FALSE, whereas the objective function did).

To resolve following issue:

While looking at the code in order to understand the functioning of EMHASS, I noticed an inconsistency in the objective formulas.
The profit cost function shows this:

if self.costfun == 'profit':
if self.optim_conf['set_total_pv_sell']:
objective = plp.lpSum(-0.001*self.timeStep*(unit_load_cost[i]*(P_load[i] + P_def_sum[i]) + \
unit_prod_price[i]*P_grid_neg[i])
for i in set_I)
else:
objective = plp.lpSum(-0.001*self.timeStep*(unit_load_cost[i]*P_grid_pos[i] + \
unit_prod_price[i]*P_grid_neg[i])
for i in set_I)

which looks correct, and is consistent with the EMHASS documentation:

  • In the case of an energy contract where the totality of the PV produced energy is injected into the grid, the grid offtake volume equals = P_load + P_deferrable_sum
  • Else (only the excess of PV produced energy is injected), the grid offtake equals = P_grid_pos

However, the "grid cost" cost function seems to have the formulas inverted, which is unexpected:

elif self.costfun == 'cost':
if self.optim_conf['set_total_pv_sell']:
objective = plp.lpSum(-0.001*self.timeStep*unit_load_cost[i]*P_grid_pos[i]
for i in set_I)
else:
objective = plp.lpSum(-0.001*self.timeStep*unit_load_cost[i]*(P_load[i] + P_def_sum[i])
for i in set_I)

Therefore, I wonder if the objective formulas in "Grid cost" cost function shouldn't be inverted.

Inverted the objective formulas in the case of "grid cost" cost function
@michaelpiron michaelpiron marked this pull request as draft December 11, 2023 17:04
@michaelpiron
Copy link
Contributor Author

For the sake of clarity: I didn't test these changes, as I don't have my dev space/container set up yet.
I hope someone else can test this. On the other hand, the proposed changes are limited.

@michaelpiron michaelpiron marked this pull request as ready for review December 11, 2023 17:18
Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (bec6f76) 88.16% compared to head (d77c4f6) 88.11%.

Files Patch % Lines
src/emhass/optimization.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
- Coverage   88.16%   88.11%   -0.06%     
==========================================
  Files           6        6              
  Lines        1420     1422       +2     
==========================================
+ Hits         1252     1253       +1     
- Misses        168      169       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@davidusb-geek davidusb-geek merged commit 4aa01ad into davidusb-geek:master Dec 15, 2023
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants