@@ -67,7 +67,7 @@ pub fn add_asset_constraints(
6767 add_commodity_balance_constraints ( problem, variables, model, assets, year) ;
6868
6969 let capacity_keys =
70- add_asset_capacity_constraints ( problem, variables, assets , & model. time_slice_info ) ;
70+ add_asset_capacity_constraints ( problem, variables, & model. time_slice_info , assets ) ;
7171
7272 // Return constraint keys
7373 ConstraintKeys {
@@ -103,26 +103,27 @@ fn add_commodity_balance_constraints(
103103
104104/// Add asset-level capacity and availability constraints.
105105///
106- /// For every asset at every time slice, the sum of the commodity flows for assets must not exceed
107- /// the capacity limits, which are a product of the annual capacity, time slice length and process
108- /// availability.
109- ///
110- /// See description in [the dispatch optimisation documentation][1].
111- ///
112- /// [1]: https://energysystemsmodellinglab.github.io/MUSE_2.0/dispatch_optimisation.html#asset-level-capacity-and-availability-constraints
106+ /// This ensures that assets do not exceed their specified capacity and availability for each time
107+ /// slice.
113108fn add_asset_capacity_constraints (
114109 problem : & mut Problem ,
115- _variables : & VariableMap ,
116- _assets : & AssetPool ,
117- _time_slice_info : & TimeSliceInfo ,
110+ variables : & VariableMap ,
111+ time_slice_info : & TimeSliceInfo ,
112+ assets : & AssetPool ,
118113) -> CapacityKeys {
119114 // Row offset in problem. This line **must** come before we add more constraints.
120115 let offset = problem. num_rows ( ) ;
121116
122- let keys = Vec :: new ( ) ;
117+ let mut keys = Vec :: new ( ) ;
118+ for asset in assets. iter ( ) {
119+ for time_slice in time_slice_info. iter_ids ( ) {
120+ let var = variables. get ( asset, time_slice) ;
121+ let limits = asset. get_activity_limits ( time_slice) ;
123122
124- // **TODO:** Add capacity/availability constraints:
125- // https://github.com/EnergySystemsModellingLab/MUSE_2.0/issues/579
123+ problem. add_row ( limits, [ ( var, 1.0 ) ] ) ;
124+ keys. push ( ( asset. clone ( ) , time_slice. clone ( ) ) )
125+ }
126+ }
126127
127128 CapacityKeys { offset, keys }
128129}
0 commit comments