Skip to content

Commit ab03905

Browse files
authored
Merge branch 'main' into add-optional-decommission-year-for-assets
2 parents 56d16a9 + 1c696c0 commit ab03905

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

src/simulation/investment.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ fn flatten_preset_demands_for_year(
189189
}
190190

191191
/// Update demand map with flows from a set of assets
192+
///
193+
/// Non-primary output flows are ignored. This way, demand profiles aren't affected by production
194+
/// of side-products from other assets. The result is that all commodity demands must be met by
195+
/// assets with that commodity as their primary output. Effectively, agents do not see production of
196+
/// side-products from other assets when making investment decisions.
197+
///
198+
/// TODO: this is a very flawed approach. The proper solution might be for agents to consider
199+
/// multiple commodities simultaneously, but that would require substantial work to implement.
192200
fn update_demand_map(demand: &mut AllDemandMap, flows: &FlowMap, assets: &[AssetRef]) {
193201
for ((asset, commodity_id, time_slice), flow) in flows {
194202
if assets.contains(asset) {
@@ -198,11 +206,19 @@ fn update_demand_map(demand: &mut AllDemandMap, flows: &FlowMap, assets: &[Asset
198206
time_slice.clone(),
199207
);
200208

201-
// Note: we use the negative of the flow as input flows are negative in the flow map.
202-
demand
203-
.entry(key)
204-
.and_modify(|value| *value -= *flow)
205-
.or_insert(-*flow);
209+
// Only consider input flows and output flows from the primary output commodity
210+
// (excluding secondary outputs)
211+
if (flow < &Flow(0.0))
212+
|| asset
213+
.primary_output()
214+
.is_some_and(|p| &p.commodity.id == commodity_id)
215+
{
216+
// Note: we use the negative of the flow as input flows are negative in the flow map.
217+
demand
218+
.entry(key)
219+
.and_modify(|value| *value -= *flow)
220+
.or_insert(-*flow);
221+
}
206222
}
207223
}
208224
}

0 commit comments

Comments
 (0)