oemof-solph
oemof-solph copied to clipboard
Features/schedule for flow
Added a schedule for Flow
-
Functionality Sometimes it´s important to set a schedule for a flow (e.g. CHP electrical output), e.g. for fulfilling contracts. During optimization flow will be pushed to fulfill the schedule, if possible. If it´s not possible a penalty term will be activated and added to the objective expression for each unit of the difference flow-schedule.
-
Changes made in oemof.solph.network
Parameter added to class Flow:
- schedule Flow has to follow the schedule, but LP won´t be infeasible, if flow can´t fulfill schedule: slack variables will be added (see Changes made in solph.blocks)
- penalty_pos Describes the costs associated with one unit of the deficit of the flow (:= slack_pos) compared to the schedule. Costs will be added to the objective expression.
- penalty_neg Describes the costs associated with one unit of the excessed flow (:= slack_neg). Will be added to the objective expression.
-
Changes made in oemof.solph.blocks
Added Set and Variables to class Flow:
-
SCHEDULE_FLOWS (pyomo.Set) contains all flows with schedules
-
slack_neg (pyomo.Var, within=NonNegativeReals) slack variable for representing excess of flow compared to schedule (see Added constraint to class Flow)
-
slack_pos (pyomo.Var, within=NonNegativeReals) slack variable for representing deficit of flow compared to schedule
Added constraint to class Flow
- flow(i, o, t) - slack_neg(i, o, t) + slack_pos(i, o, t) = schedule(i, o, t)
Term added to objective expression:
- penalty_pos(i, o, t) * slack_pos(i, o, t) + penalty_neg(i, o, t) * slack_neg(i, o, t)
-
-
Changes made in oemof.tests.test_processing New Parameters of class Flow had to be added to the test file as well.
-
Changes made in oemof.tests.constraint_tests Test for scheduled flow was added.
-
Changes made in oemof.tests.lp_files.flow_schedule.lp Created file.
-
Changes made in doc.whatsnew.v0-3-3.rst Created file.
-
Possible Improvements
- Default value for penalty_pos and penalty_neg is 0. This could be improved by setting a reasonable default value, but this acquires mathematical research on how to choose appropriate penalties.
- If it's not possible for the flow to follow the schedule, "non-real" costs will be added to the objective expression. You might not want to interfere the artificial costs (added by the slack variables) with the real costs of the solved LP.
Hello @c-koehl! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
- In the file
src/oemof/solph/blocks.py
:
Line 163:46: W504 line break after binary operator Line 267:53: W504 line break after binary operator Line 268:70: W504 line break after binary operator Line 308:35: W504 line break after binary operator Line 309:37: W504 line break after binary operator Line 312:73: W504 line break after binary operator Line 314:73: W504 line break after binary operator
- In the file
src/oemof/solph/network.py
:
Line 241:37: W504 line break after binary operator Line 242:48: W504 line break after binary operator
Comment last updated at 2022-06-24 14:12:31 UTC
Coverage increased (+0.06%) to 94.894% when pulling 4a7106f1e9aa3749bb21add685fdee8dd297cdb1 on c-koehl:features/schedule_for_flow into 83cfc0b6187906d85ebd0c4ea2788e0091dc82f7 on oemof:dev.
If you're interested, I could also add an example to oemof-examples.
Once you're done with the implementation, select a reviewer who cross-checks the newly added code. Preferably, select someone who already has some context about this
@gplssm I'm done with the implementation, but it seems like I don't have the rights to select a reviewer or labels. I don't know what I'm doing wrong? Also I cannot tell, which reviewer is the best to choose
@gplssm I'm done with the implementation, but it seems like I don't have the rights to select a reviewer or labels. I don't know what I'm doing wrong? Also I cannot tell, which reviewer is the best to choose
I'm not too familiar with permissions granted to individual devs. Maybe @uvchik can help out here.
Meanwhile, I can request a review for you. Did you talk to anyone before/during your implementation of "schedule for flow"? I would prefer to select this person then.
@gplssm I'm done with the implementation, but it seems like I don't have the rights to select a reviewer or labels. I don't know what I'm doing wrong? Also I cannot tell, which reviewer is the best to choose
I'm not too familiar with permissions granted to individual devs. Maybe @uvchik can help out here.
Meanwhile, I can request a review for you. Did you talk to anyone before/during your implementation of "schedule for flow"? I would prefer to select this person then.
@gplssm I actually didn't talk to anyone. I would suggest a reviewer with mathematical optimization knowledge, but I think my procedure is also comprehensible for non mathematicians.
I've requested a review by @simnh because he's quite deep into mathematical modeling in oemof.solph. @simnh please re-request a review by someone else if you can't do it.
@simnh Is this ready to merge?
@c-koehl Do you have a good example. I think it is a good idea to publish an example on oemof-examples to make this feature more visible.
@c-koehl Do you have a good example. I think it is a good idea to publish an example on oemof-examples to make this feature more visible.
Yes I have a jupyter notebook example. I will create a pull request in oemof/oemof-examples.
Codecov Report
Merging #666 into dev will decrease coverage by
0.03%
. The diff coverage is90.90%
.
@@ Coverage Diff @@
## dev #666 +/- ##
==========================================
- Coverage 92.15% 92.12% -0.04%
==========================================
Files 13 13
Lines 1377 1397 +20
Branches 326 333 +7
==========================================
+ Hits 1269 1287 +18
- Misses 62 63 +1
- Partials 46 47 +1
Impacted Files | Coverage Δ | |
---|---|---|
src/oemof/solph/network.py | 97.29% <33.33%> (-2.71%) |
:arrow_down: |
src/oemof/solph/blocks.py | 90.69% <100.00%> (+0.59%) |
:arrow_up: |
src/oemof/solph/components.py | 91.58% <0.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 9a2b0fd...9a2b0fd. Read the comment docs.
I fixed the conflicts caused by the restructuring of oemof.
Please check if everything still works as expected.
@simnh: This PR is related to this example: https://github.com/oemof/oemof-examples/pull/53
I checked the example it works as expected. So I think this is fine to merge. The exmaple can be cleaned up a little (pep8 etc.) However, I will suggest this in the other PR.
I tried to understand this part:
if (
len(self.schedule) != 0 and
((len(self.schedule_cost_pos) == 0 and
not self.schedule_cost_pos[0]) or
(len(self.schedule_cost_neg) == 0 and
not self.schedule_cost_neg[0]))):
raise ValueError("The penalty and schedule attribute need "
"to be used in combination. \n Please set "
"the schedule attribute of the flow.")
My guess:
If schedule
is set by the user, the user should also set schedule_cost_pos
and schedule_cost_neg
.
If len(self.schedule) != 0
is True which is necessary to raise the error the schedule is already set, but in the message it says: "Please set the schedule attribute of the flow.".
If the user have to set the schedule_cost_neg/pos
parameters you should not set a default value, because a default value only makes sense for optional parameter.
I do not know how to un - fail these tests. I am not sure if they were caused by me... Please correct me if I am wrong