@@ -15,12 +15,17 @@ pub type CommodityBalanceConstraintKeys = Vec<(CommodityID, RegionID, TimeSliceS
1515/// Indicates the asset ID and time slice covered by each capacity constraint
1616pub type CapacityConstraintKeys = Vec < ( AssetID , TimeSliceID ) > ;
1717
18+ /// Indicates the asset ID, commodity ID and time slice for each fixed asset constraint
19+ pub type FixedAssetConstraintKeys = Vec < ( AssetID , CommodityID , TimeSliceID ) > ;
20+
1821/// The keys for different constraints
1922pub struct ConstraintKeys {
2023 /// Keys for commodity balance constraints
2124 pub commodity_balance_keys : CommodityBalanceConstraintKeys ,
2225 /// Keys for capacity constraints
2326 pub capacity_keys : CapacityConstraintKeys ,
27+ /// Keys for fixed asset constraints
28+ pub fixed_asset_keys : FixedAssetConstraintKeys ,
2429}
2530
2631impl ConstraintKeys {
@@ -33,6 +38,11 @@ impl ConstraintKeys {
3338 pub fn capacity_keys_offset ( & self ) -> usize {
3439 self . commodity_balance_keys . len ( )
3540 }
41+
42+ /// Start offset for capacity constraints
43+ pub fn fixed_asset_keys_offset ( & self ) -> usize {
44+ self . capacity_keys_offset ( ) + self . capacity_keys . len ( )
45+ }
3646}
3747
3848/// Add asset-level constraints
@@ -75,7 +85,7 @@ pub fn add_asset_constraints(
7585 // need to add different constraints for assets with flexible and non-flexible flows.
7686 //
7787 // See: https://github.com/EnergySystemsModellingLab/MUSE_2.0/issues/360
78- add_fixed_asset_constraints (
88+ let fixed_asset_keys = add_fixed_asset_constraints (
7989 problem,
8090 variables,
8191 assets,
@@ -88,6 +98,7 @@ pub fn add_asset_constraints(
8898 ConstraintKeys {
8999 commodity_balance_keys,
90100 capacity_keys,
101+ fixed_asset_keys,
91102 }
92103}
93104
@@ -240,14 +251,15 @@ fn add_fixed_asset_constraints(
240251 time_slice_info : & TimeSliceInfo ,
241252 commodity_balance_keys : & CommodityBalanceConstraintKeys ,
242253 capacity_keys : & CapacityConstraintKeys ,
243- ) {
254+ ) -> FixedAssetConstraintKeys {
244255 // Sanity check: we rely on the dual rows corresponding to these constraints being
245256 // immediately after the commodity balance and capacity constraints in `problem`.
246257 assert ! (
247258 problem. num_rows( ) == commodity_balance_keys. len( ) + capacity_keys. len( ) ,
248259 "Fixed asset constraints must be added immediately after commodity constraints."
249260 ) ;
250261
262+ let mut keys = FixedAssetConstraintKeys :: new ( ) ;
251263 for asset in assets. iter ( ) {
252264 // Get first PAC. unwrap is safe because all processes have at least one PAC.
253265 let pac1 = asset. iter_pacs ( ) . next ( ) . unwrap ( ) ;
@@ -264,7 +276,12 @@ fn add_fixed_asset_constraints(
264276 // We are enforcing that (var / flow) - (pac_var / pac_flow) = 0
265277 let var = variables. get ( asset. id , & flow. commodity . id , time_slice) ;
266278 problem. add_row ( 0.0 ..=0.0 , [ ( var, 1.0 / flow. flow ) , pac_term] ) ;
279+
280+ // Keep track of the order in which constraints were added
281+ keys. push ( ( asset. id , flow. commodity . id . clone ( ) , time_slice. clone ( ) ) ) ;
267282 }
268283 }
269284 }
285+
286+ keys
270287}
0 commit comments