-
Notifications
You must be signed in to change notification settings - Fork 36
Rolling horizon #1327
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
Merged
Merged
Rolling horizon #1327
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6368f90
Change rep_period profiles to handle rolling horizon
abelsiqueira 54d7a97
Implement high-level run_rolling_horizon function with placeholders
abelsiqueira 7add735
Create rolling horizon parameters
abelsiqueira e9c8ff6
Implement update of rolling horizon parameters
abelsiqueira 9acdc3b
Test adding rolling horizon parameters
abelsiqueira aef2825
Add functions for validation and data preparation for rolling horizon
abelsiqueira 0ee290b
Add unit tests for rolling horizon
abelsiqueira e3bb910
Update the storage constraint to use the rolling initial storage level
abelsiqueira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """ | ||
| add_scalar_rolling_horizon_parameter!(model, variables, connection, param_table_name) | ||
| Create the rolling horizon Parameters for the table `param_table_name`. | ||
| This assumes that the table named `param_table_name` has a column | ||
| `original_value` and uses that as initial value for the variable. | ||
| The container is saved in the `model[key]` and the `TulipaVariable` for the | ||
| parameter is stored in `variables[key]`, where `key = Symbol(param_table_name)`. | ||
| """ | ||
| function add_scalar_rolling_horizon_parameter!(model, variables, connection, param_table_name) | ||
| initial_value = | ||
| [row.original_value::Float64 for row in DuckDB.query(connection, "FROM $param_table_name")] | ||
| num_rows = length(initial_value) | ||
| param = TulipaVariable(connection, param_table_name) | ||
| param.container = @variable(model, [1:num_rows] in JuMP.Parameter.(initial_value)) | ||
|
|
||
| key = Symbol(param_table_name) | ||
| model[key] = param.container | ||
| variables[key] = param | ||
| return param | ||
| end | ||
|
|
||
| """ | ||
| add_rolling_horizon_parameters!(connection, model, variables, profiles, window_length) | ||
| Create Parameters to handle rolling horizon. | ||
| The profile parameters are attached to `profiles.rep_period`. | ||
| The other parameters are the ones that have initial value (currently only initial_storage_level). | ||
| These must be filtered from the corresponding indices table when time_block_start = 1. | ||
| The corresponding parameters is saved in the variables and in the model. | ||
| """ | ||
| function add_rolling_horizon_parameters!(connection, model, variables, profiles, window_length) | ||
| # Profiles | ||
| for (_, profile_object) in profiles.rep_period | ||
| profile_object.rolling_horizon_variables = | ||
| @variable(model, [1:window_length] in JuMP.Parameter(0.0)) | ||
| end | ||
|
|
||
| # Scalar rolling horizon parameters | ||
| # These need a table filtering where time_block_start = 1, and the current | ||
| # strategy is to create a table `param_NAME` and call | ||
| # add_scalar_rolling_horizon_parameter!. | ||
|
|
||
| ## initial_storage_level | ||
| DuckDB.query( | ||
| connection, | ||
| """ | ||
| DROP SEQUENCE IF EXISTS id; | ||
| CREATE SEQUENCE id START 1; | ||
| CREATE OR REPLACE TABLE param_initial_storage_level AS | ||
| SELECT | ||
| nextval('id') as id, | ||
| var.asset, | ||
| var.year, | ||
| var.rep_period, | ||
| var.id as var_storage_id, | ||
| asset_milestone.initial_storage_level as original_value | ||
| FROM var_storage_level_rep_period as var | ||
| LEFT JOIN asset_milestone | ||
| ON var.asset = asset_milestone.asset | ||
| AND var.year = asset_milestone.milestone_year | ||
| WHERE time_block_start = 1; | ||
| DROP SEQUENCE id; | ||
| """, | ||
| ) | ||
| add_scalar_rolling_horizon_parameter!( | ||
| model, | ||
| variables, | ||
| connection, | ||
| "param_initial_storage_level", | ||
| ) | ||
|
|
||
| return | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datejada, here I changed the defaults
profilesstructure to hold in parallel the values (as before) and the rolling horizon parameters (initially empty)