Skip to content

Commit 005a17d

Browse files
committed
add_fixed_asset_constraints: Ensure these constraints come after others
1 parent f4e740e commit 005a17d

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/simulation/optimisation/constraints.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ pub fn add_asset_constraints(
7575
// need to add different constraints for assets with flexible and non-flexible flows.
7676
//
7777
// See: https://github.com/EnergySystemsModellingLab/MUSE_2.0/issues/360
78-
add_fixed_asset_constraints(problem, variables, assets, &model.time_slice_info);
78+
add_fixed_asset_constraints(
79+
problem,
80+
variables,
81+
assets,
82+
&model.time_slice_info,
83+
&commodity_balance_keys,
84+
&capacity_keys,
85+
);
7986

8087
// Return constraint keys
8188
ConstraintKeys {
@@ -231,7 +238,16 @@ fn add_fixed_asset_constraints(
231238
variables: &VariableMap,
232239
assets: &AssetPool,
233240
time_slice_info: &TimeSliceInfo,
241+
commodity_balance_keys: &CommodityBalanceConstraintKeys,
242+
capacity_keys: &CapacityConstraintKeys,
234243
) {
244+
// Sanity check: we rely on the dual rows corresponding to these constraints being
245+
// immediately after the commodity balance and capacity constraints in `problem`.
246+
assert!(
247+
problem.num_rows() == commodity_balance_keys.len() + capacity_keys.len(),
248+
"Fixed asset constraints must be added immediately after commodity constraints."
249+
);
250+
235251
for asset in assets.iter() {
236252
// Get first PAC. unwrap is safe because all processes have at least one PAC.
237253
let pac1 = asset.iter_pacs().next().unwrap();

0 commit comments

Comments
 (0)