Skip to content

Commit 7353bcd

Browse files
authored
Merge pull request #883 from EnergySystemsModellingLab/give-all-assets-an-agent-id
Give candidate assets an agent ID
2 parents 144ced3 + 70f0916 commit 7353bcd

3 files changed

Lines changed: 21 additions & 26 deletions

File tree

src/asset.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ pub struct AssetID(u32);
4545
/// `commission_future` or `commission_candidate` respectively.
4646
///
4747
/// `Commissioned` assets can be decommissioned by calling `decommission`.
48-
#[derive(
49-
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize, strum::Display,
50-
)]
48+
#[derive(Clone, Debug, PartialEq, strum::Display)]
5149
pub enum AssetState {
5250
/// The asset has been commissioned
5351
Commissioned {

src/simulation.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,11 @@ pub fn run(
4747

4848
// Gather candidates for the next year, if any
4949
let next_year = year_iter.peek().copied();
50-
let mut candidates = next_year
51-
.map(|next_year| {
52-
candidate_assets_for_year(
53-
&model.processes,
54-
next_year,
55-
model.parameters.candidate_asset_capacity,
56-
)
57-
})
58-
.unwrap_or_default();
50+
let mut candidates = candidate_assets_for_next_year(
51+
&model.processes,
52+
next_year,
53+
model.parameters.candidate_asset_capacity,
54+
);
5955

6056
// Run dispatch optimisation
6157
info!("Running dispatch optimisation...");
@@ -158,15 +154,11 @@ pub fn run(
158154

159155
// Gather candidates for the next year, if any
160156
let next_year = year_iter.peek().copied();
161-
candidates = next_year
162-
.map(|next_year| {
163-
candidate_assets_for_year(
164-
&model.processes,
165-
next_year,
166-
model.parameters.candidate_asset_capacity,
167-
)
168-
})
169-
.unwrap_or_default();
157+
candidates = candidate_assets_for_next_year(
158+
&model.processes,
159+
next_year,
160+
model.parameters.candidate_asset_capacity,
161+
);
170162

171163
// Run dispatch optimisation
172164
info!("Running final dispatch optimisation for year {year}...");
@@ -218,23 +210,27 @@ fn run_dispatch_for_year(
218210
}
219211

220212
/// Create candidate assets for all potential processes in a specified year
221-
fn candidate_assets_for_year(
213+
fn candidate_assets_for_next_year(
222214
processes: &ProcessMap,
223-
year: u32,
215+
next_year: Option<u32>,
224216
candidate_asset_capacity: Capacity,
225217
) -> Vec<AssetRef> {
226218
let mut candidates = Vec::new();
219+
let Some(next_year) = next_year else {
220+
return candidates;
221+
};
222+
227223
for process in processes
228224
.values()
229-
.filter(move |process| process.active_for_year(year))
225+
.filter(move |process| process.active_for_year(next_year))
230226
{
231227
for region_id in &process.regions {
232228
candidates.push(
233229
Asset::new_candidate(
234230
Rc::clone(process),
235231
region_id.clone(),
236232
candidate_asset_capacity,
237-
year,
233+
next_year,
238234
)
239235
.unwrap()
240236
.into(),

src/simulation/investment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ fn select_best_assets(
381381
);
382382

383383
let mut round = 0;
384+
let objective_type = &agent.objectives[&year];
384385
while is_any_remaining_demand(&demand) {
385386
ensure!(
386387
!opt_assets.is_empty(),
@@ -402,7 +403,7 @@ fn select_best_assets(
402403
asset,
403404
max_capacity,
404405
commodity,
405-
&agent.objectives[&year],
406+
objective_type,
406407
reduced_costs,
407408
&demand,
408409
)?;

0 commit comments

Comments
 (0)