-
Notifications
You must be signed in to change notification settings - Fork 4
Equalise equivalent assets in dispatch #1477
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a81b05
Add constraint to force equal utilisation of identical assets
tsmbland 0dc2c19
Update docs
tsmbland 24716fc
Simplify docs
tsmbland c101c81
Update results
tsmbland 06d87e3
Smarter asset grouping
tsmbland 35c6a53
Revert "Smarter asset grouping"
tsmbland ec00c6a
Merge branch 'main' into asset_equalisation
tsmbland 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,13 @@ use super::VariableMap; | |
| use crate::asset::{AssetCapacity, AssetIterator, AssetRef}; | ||
| use crate::commodity::{CommodityID, CommodityType}; | ||
| use crate::model::Model; | ||
| use crate::process::ProcessID; | ||
| use crate::region::RegionID; | ||
| use crate::time_slice::{Season, TimeSliceInfo, TimeSliceSelection}; | ||
| use crate::units::{Flow, MoneyPerCapacityPerYear, UnitType, Year}; | ||
| use highs::RowProblem as Problem; | ||
| use indexmap::IndexMap; | ||
| use std::collections::HashSet; | ||
|
|
||
| /// Corresponding variables for a constraint along with the row offset in the solution | ||
| pub struct KeysWithOffset<T> { | ||
|
|
@@ -106,6 +108,8 @@ where | |
|
|
||
| add_utilisation_peak_constraints(problem, model, assets.clone(), variables); | ||
|
|
||
| add_equal_utilisation_constraints(problem, variables, &model.time_slice_info, assets.clone()); | ||
|
tsmbland marked this conversation as resolved.
|
||
|
|
||
| // Return constraint keys | ||
| ConstraintKeys { | ||
| commodity_balance_keys, | ||
|
|
@@ -470,6 +474,65 @@ where | |
| ActivityKeys { offset, keys } | ||
| } | ||
|
|
||
| /// Add constraints requiring assets of the same process in the same region to have equal | ||
| /// utilisation in each time slice. | ||
| /// | ||
| /// Flexible-capacity assets are excluded because their maximum activity depends on a decision | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, OK, you cannot merge them since they might actually not be equivalent. But, if they were, would it make sense to merge them? |
||
| /// variable. The constraints added here are not included in [`ConstraintKeys`], as their duals | ||
| /// are not currently used. | ||
| fn add_equal_utilisation_constraints<'a, I>( | ||
| problem: &mut Problem, | ||
| variables: &VariableMap, | ||
| time_slice_info: &TimeSliceInfo, | ||
| assets: I, | ||
| ) where | ||
| I: Iterator<Item = &'a AssetRef> + 'a, | ||
| { | ||
| // Identify flexible-capacity assets so we can exclude them from the constraints | ||
| let flexible_assets: HashSet<_> = variables | ||
| .iter_capacity_vars() | ||
| .map(|(asset, _)| asset) | ||
| .collect(); | ||
|
|
||
| // Group together assets with the same process and region | ||
| let mut assets_by_process: IndexMap<(RegionID, ProcessID), Vec<&AssetRef>> = IndexMap::new(); | ||
| for asset in assets.filter(|asset| !flexible_assets.contains(asset)) { | ||
| assets_by_process | ||
| .entry((asset.region_id().clone(), asset.process_id().clone())) | ||
| .or_default() | ||
| .push(asset); | ||
| } | ||
|
|
||
| // For each group of assets, add constraints to force equal utilisation in each time slice | ||
| // This is done by anchoring each asset to the first asset in the group (-> (n-1) constraints | ||
| // for a group of n assets) | ||
| for assets in assets_by_process.into_values() { | ||
| let Some((reference_asset, others)) = assets.split_first() else { | ||
| continue; | ||
| }; | ||
|
|
||
| let reference_max = reference_asset.max_activity().value(); | ||
|
|
||
| for asset in others { | ||
| let asset_max = asset.max_activity().value(); | ||
|
|
||
| for time_slice in time_slice_info.iter_ids() { | ||
| // Constraint: (act_a * max_b) - (act_b * max_a) = 0 | ||
| problem.add_row( | ||
| 0.0..=0.0, | ||
| [ | ||
| (variables.get_activity_var(asset, time_slice), reference_max), | ||
| ( | ||
| variables.get_activity_var(reference_asset, time_slice), | ||
| -asset_max, | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
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
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.
Maybe a weird question, but wouldn't it make sense to merge these assets?