Skip to content

Commit 44f63a7

Browse files
committed
Reimplement iter_commodity_flows_for_assets
Closes #593.
1 parent 0cd3aa1 commit 44f63a7

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/simulation/optimisation.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl VariableMap {
4848
/// The solution to the dispatch optimisation problem
4949
pub struct Solution<'a> {
5050
solution: highs::Solution,
51-
_variables: VariableMap,
51+
variables: VariableMap,
5252
time_slice_info: &'a TimeSliceInfo,
5353
constraint_keys: ConstraintKeys,
5454
}
@@ -61,13 +61,21 @@ impl Solution<'_> {
6161
///
6262
/// # Returns
6363
///
64-
/// An iterator of tuples containing an asset ID, commodity, time slice and flow.
64+
/// An iterator of tuples containing an asset, commodity, time slice and flow.
6565
pub fn iter_commodity_flows_for_assets(
6666
&self,
6767
) -> impl Iterator<Item = (&AssetRef, &CommodityID, &TimeSliceID, f64)> {
68-
// **TODO:** Need to calculate flows by multiplying coeffs by asset activity:
69-
// https://github.com/EnergySystemsModellingLab/MUSE_2.0/issues/593
70-
std::iter::empty()
68+
// The decision variables represent assets' activity levels, not commodity flows. We
69+
// multiply this value by the flow coeffs to get commodity flows.
70+
self.variables
71+
.0
72+
.keys()
73+
.zip(self.solution.columns())
74+
.flat_map(|((asset, time_slice), activity)| {
75+
asset
76+
.iter_flows()
77+
.map(move |flow| (asset, &flow.commodity.id, time_slice, activity * flow.coeff))
78+
})
7179
}
7280

7381
/// Keys and dual values for commodity balance constraints.
@@ -139,7 +147,7 @@ pub fn perform_dispatch_optimisation<'a>(
139147
match solution.status() {
140148
HighsModelStatus::Optimal => Ok(Solution {
141149
solution: solution.get_solution(),
142-
_variables: variables,
150+
variables,
143151
time_slice_info: &model.time_slice_info,
144152
constraint_keys,
145153
}),

0 commit comments

Comments
 (0)