-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor: Move future and decommissioned assets out of AssetPool
#1114
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
Changes from all commits
2275795
c57ef89
22d6990
0371da8
89409d8
09a2b31
7c5644d
e3a7bc8
d748010
6fb8f7f
112976b
ae12d93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,16 +22,13 @@ pub use prices::CommodityPrices; | |
| /// # Arguments: | ||
| /// | ||
| /// * `model` - The model to run | ||
| /// * `assets` - The asset pool | ||
| /// * `output_path` - The folder to which output files will be written | ||
| /// * `debug_model` - Whether to write additional information (e.g. duals) to output files | ||
| pub fn run( | ||
| model: &Model, | ||
| mut assets: AssetPool, | ||
| output_path: &Path, | ||
| debug_model: bool, | ||
| ) -> Result<()> { | ||
| pub fn run(model: &Model, output_path: &Path, debug_model: bool) -> Result<()> { | ||
| let mut writer = DataWriter::create(output_path, &model.model_path, debug_model)?; | ||
| let mut user_assets = model.user_assets.clone(); | ||
| let mut asset_pool = AssetPool::new(); // active assets | ||
| let mut decommissioned = Vec::new(); | ||
|
|
||
| // Iterate over milestone years | ||
| let mut year_iter = model.iter_years().peekable(); | ||
|
|
@@ -40,10 +37,10 @@ pub fn run( | |
| info!("Milestone year: {year}"); | ||
|
|
||
| // Commission assets for base year | ||
| assets.update_for_year(year); | ||
| asset_pool.commission_new(year, &mut user_assets); | ||
|
|
||
| // Write assets to file | ||
| writer.write_assets(assets.iter_all())?; | ||
| writer.write_assets(asset_pool.iter())?; | ||
alexdewar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Gather candidates for the next year, if any | ||
| let next_year = year_iter.peek().copied(); | ||
|
|
@@ -56,7 +53,7 @@ pub fn run( | |
| // Run dispatch optimisation | ||
| info!("Running dispatch optimisation..."); | ||
| let (flow_map, mut prices) = | ||
| run_dispatch_for_year(model, assets.as_slice(), &candidates, year, &mut writer)?; | ||
| run_dispatch_for_year(model, asset_pool.as_slice(), &candidates, year, &mut writer)?; | ||
|
|
||
| // Write results of dispatch optimisation to file | ||
| writer.write_flows(year, &flow_map)?; | ||
|
|
@@ -65,13 +62,14 @@ pub fn run( | |
| while let Some(year) = year_iter.next() { | ||
| info!("Milestone year: {year}"); | ||
|
|
||
| // Commission new assets and decommission those whose lifetime has passed. We do this | ||
| // *before* agent investment, to prevent agents from selecting assets that are being | ||
| // decommissioned in this milestone year. | ||
| assets.update_for_year(year); | ||
| // Decommission assets whose lifetime has passed | ||
| asset_pool.decommission_old(year, &mut decommissioned); | ||
|
|
||
| // Commission user-defined assets for this year | ||
| asset_pool.commission_new(year, &mut user_assets); | ||
|
|
||
| // Take all the active assets as a list of existing assets | ||
| let existing_assets = assets.take(); | ||
| let existing_assets = asset_pool.take(); | ||
|
|
||
| // Iterative loop to "iron out" prices via repeated investment and dispatch | ||
| let mut ironing_out_iter = 0; | ||
|
|
@@ -121,14 +119,18 @@ pub fn run( | |
| }; | ||
|
|
||
| // Add selected_assets to the active pool | ||
| assets.extend(selected_assets); | ||
| asset_pool.extend(selected_assets); | ||
|
|
||
| // Decommission unused assets | ||
| assets.mothball_unretained(existing_assets, year); | ||
| assets.decommission_mothballed(year, model.parameters.mothball_years); | ||
| asset_pool.mothball_unretained(existing_assets, year); | ||
| asset_pool.decommission_mothballed( | ||
| year, | ||
| model.parameters.mothball_years, | ||
| &mut decommissioned, | ||
| ); | ||
|
|
||
| // Write assets | ||
| writer.write_assets(assets.iter_all())?; | ||
| writer.write_assets(decommissioned.iter().chain(asset_pool.iter()))?; | ||
|
|
||
| // Gather candidates for the next year, if any | ||
| let next_year = year_iter.peek().copied(); | ||
|
|
@@ -141,7 +143,7 @@ pub fn run( | |
| // Run dispatch optimisation | ||
| info!("Running final dispatch optimisation for year {year}..."); | ||
| let (flow_map, new_prices) = | ||
| run_dispatch_for_year(model, assets.as_slice(), &candidates, year, &mut writer)?; | ||
| run_dispatch_for_year(model, asset_pool.as_slice(), &candidates, year, &mut writer)?; | ||
|
|
||
| // Write results of dispatch optimisation to file | ||
| writer.write_flows(year, &flow_map)?; | ||
|
|
||
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.
The
decommissionedVec is never cleared between milestone years, causing decommissioned assets to accumulate across all years. When assets are written at line 133, all previously decommissioned assets from earlier years will be written again, creating duplicate entries in the output. The Vec should be cleared after writing assets to file (after line 133) to ensure each year only writes the assets that were decommissioned in that specific year.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.
Yes, but that's by design! We write all decommissioned assets to file.