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

Time limit for deferrable loads #153

Merged
merged 45 commits into from
Jan 26, 2024

Conversation

michaelpiron
Copy link
Contributor

This pull request introduces a new parameter, allowing the user to specify a time limit for each deferrable load (in MPC optimization).

The new parameter in the optimizer, called def_end_timestep, is defined as "The timestep before which each deferrable load should operate."
The optimizer will get an extra constraint stating that the deferrable load should not consume any energy after the specified timestep. If a value of 0 (or negative) is provided, no extra constraint is added.

Example: "def_end_timestep": [3,0]
This is the case of two deferrable loads, whereby the first load should operate in the first three timesteps of the optimization window. The second load can use the complete optimization window (cf the value of 0).

There's also a check that the available timeframe until def_end_timestep is > the timesteps needed to run the load for the specified operating hours (def_total_hours). If not, the def_end_timestep is updated automatically to respect that constraint.

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

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

Comparison is base (5691360) 89.52% compared to head (04dae29) 89.56%.
Report is 5 commits behind head on master.

Files Patch % Lines
src/emhass/optimization.py 82.75% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #153      +/-   ##
==========================================
+ Coverage   89.52%   89.56%   +0.03%     
==========================================
  Files           6        6              
  Lines        1442     1485      +43     
==========================================
+ Hits         1291     1330      +39     
- Misses        151      155       +4     

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

@michaelpiron michaelpiron marked this pull request as draft January 24, 2024 19:11
@michaelpiron
Copy link
Contributor Author

OK, automated tests have passed. I will continue doing functional testing, therefore changed it into a draft PR

@michaelpiron
Copy link
Contributor Author

michaelpiron commented Jan 26, 2024

Edge cases are working as expected:

Edge case: start > end

image

@davidusb-geek
Copy link
Owner

Ok so this will catch incoherent time windows entered by the user?
If the proposed window is 0 --> 0 it means that no windows is defined for that deferrable load?

@michaelpiron
Copy link
Contributor Author

michaelpiron commented Jan 26, 2024

Ok so this will catch incoherent time windows entered by the user? If the proposed window is 0 --> 0 it means that no windows is defined for that deferrable load?

Correct. I only enforce an extra constraint if the specified def_start_timestep & def_end_timestep are valid, making chances of a successful optimization as high as possible.

More concretely:

  • Start = 0 means: start of the prediction horizon window. No constraint added
  • End = 0 means: end of the prediction horizon window. No constraint added
  • If user specifies a negative value for start or end, the value will be changed to 0. No constraint added
  • If start timestep > end timestep the optimizer will not take it into account. (Both start & end timestep are changed to 0). No constraint added
  • If the number of timesteps between start & end is too short to meet the def_total_hours constraint, a warning message will be shown in the log, warning the user that the optimizer won't find an feasible solution. Constraints for start & end timestep are enforced and optimization continues. I tried to find a logic to automatically make the defined optimization window longer, but there's too many degrees of freedom (put the start earlier? put the end later? a bit of both?)

@michaelpiron
Copy link
Contributor Author

michaelpiron commented Jan 26, 2024

Happy flow

Example of a valid case:
The car needs to charge 2h at nominal power. I specify a timewindow of 7 timesteps = 3.5h (between 17h30 & 21h)
image

Forcing the deferrable load 1 to operate between 17h30 and 21h:
image

Outcome:
image

@michaelpiron
Copy link
Contributor Author

Edge case: timewindow too short

Example case where the defined timewindow for deferrable load 1 is too short to meet the def_total_hours constraint:
The car needed to charge 2h at nominal power. I specified a timewindow of 1 timestep = 0.5h:

Result:
image

image

@michaelpiron michaelpiron marked this pull request as ready for review January 26, 2024 09:47
@michaelpiron
Copy link
Contributor Author

Day-ahead optimization

Day ahead optimization also works with the timewindow constraints.

However, DA optimization doesn't take the timewindow constraints as runtime parameters (just like def_total_hours for example), but rather takes the constraints from the add-on configuration screen:
image

Log of the optimization:
image

Result:
image

@michaelpiron
Copy link
Contributor Author

Edge case: end optimization window deferrable load > prediction horizon

If the user specified a timewindow that goes beyond the prediction horizon, the timewindow is adjusted automatically.
In the case below, the prediction horizon has 26 timesteps.
image

@michaelpiron
Copy link
Contributor Author

Code is ready for review

@davidusb-geek
Copy link
Owner

davidusb-geek commented Jan 26, 2024

Day-ahead optimization

Day ahead optimization also works with the timewindow constraints.

However, DA optimization doesn't take the timewindow constraints as runtime parameters (just like def_total_hours for example), but rather takes the constraints from the add-on configuration screen

In this specific example for day-ahead optimization no constraint was added to the LP problem right?

@michaelpiron
Copy link
Contributor Author

Day-ahead optimization

Day ahead optimization also works with the timewindow constraints.
However, DA optimization doesn't take the timewindow constraints as runtime parameters (just like def_total_hours for example), but rather takes the constraints from the add-on configuration screen

In this specific example for day-ahead optimization no constraint was added to the LP problem right?

There was: deferrable load 1 was only allowed to operate after the first timestep.

@davidusb-geek
Copy link
Owner

davidusb-geek commented Jan 26, 2024

There was: deferrable load 1 was only allowed to operate after the first timestep.

Yes but then what is the meaning of fixing end-timestep to zero? that's the bit I don't get

@michaelpiron
Copy link
Contributor Author

There was: deferrable load 1 was only allowed to operate after the first timestep.

Yes but then what is the meaning of fixing end-timestep to zero? that's the bit I don't get

The zero for def_end_timestep means that we don't impose an end limit, so the endpoint equals the end of the prediction horizon.

I've visualized some cases:
Yellow is the prediction horizon of the optimization. The blue bars are the deferrable load timewindows that correspond to the provided [start, end] timesteps:
image

@michaelpiron
Copy link
Contributor Author

Day-ahead optimization

Here's another example of DA optimization with specified timewindow for deferrable load 1:
EMHASS config:
Deferrable load only allowed between timestep 3 & 9
image

image

image

@davidusb-geek
Copy link
Owner

Ok, understood. Thanks for the clarifications.

@davidusb-geek davidusb-geek merged commit f6dd87f into davidusb-geek:master Jan 26, 2024
13 checks passed
GeoDerp added a commit to GeoDerp/emhass that referenced this pull request Jan 27, 2024
@davidusb-geek
Copy link
Owner

There was: deferrable load 1 was only allowed to operate after the first timestep.

Yes but then what is the meaning of fixing end-timestep to zero? that's the bit I don't get

The zero for def_end_timestep means that we don't impose an end limit, so the endpoint equals the end of the prediction horizon.

I've visualized some cases: Yellow is the prediction horizon of the optimization. The blue bars are the deferrable load timewindows that correspond to the provided [start, end] timesteps: image

It may be a good idea to put this image somewhere in the documentation. We can add a section about using this new feature in the Example configurations page.
What do you think?

@michaelpiron
Copy link
Contributor Author

Hi David, I was thinking the same. Let me see if I can find some time to do this.

@michaelpiron
Copy link
Contributor Author

@davidusb-geek will have some time on Tuesday to work on documentation. Will make a new pull request for that

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