@@ -50,6 +50,7 @@ pub struct ConstraintKeys {
5050/// * `variables` - The variables in the problem
5151/// * `model` - The model
5252/// * `assets` - The asset pool
53+ /// * `year` - Current milestone year
5354///
5455/// # Returns:
5556///
@@ -60,9 +61,10 @@ pub fn add_asset_constraints(
6061 variables : & VariableMap ,
6162 model : & Model ,
6263 assets : & AssetPool ,
64+ year : u32 ,
6365) -> ConstraintKeys {
6466 let commodity_balance_keys =
65- add_commodity_balance_constraints ( problem, variables, model, assets) ;
67+ add_commodity_balance_constraints ( problem, variables, model, assets, year ) ;
6668
6769 let capacity_keys =
6870 add_asset_capacity_constraints ( problem, variables, assets, & model. time_slice_info ) ;
@@ -86,14 +88,18 @@ fn add_commodity_balance_constraints(
8688 variables : & VariableMap ,
8789 model : & Model ,
8890 assets : & AssetPool ,
91+ year : u32 ,
8992) -> CommodityBalanceKeys {
9093 // Row offset in problem. This line **must** come before we add more constraints.
9194 let offset = problem. num_rows ( ) ;
9295
9396 let mut keys = Vec :: new ( ) ;
9497 let mut terms = Vec :: new ( ) ;
9598 for ( commodity_id, commodity) in model. commodities . iter ( ) {
96- if commodity. kind != CommodityType :: SupplyEqualsDemand {
99+ if !matches ! (
100+ commodity. kind,
101+ CommodityType :: SupplyEqualsDemand | CommodityType :: ServiceDemand
102+ ) {
97103 continue ;
98104 }
99105
@@ -111,8 +117,17 @@ fn add_commodity_balance_constraints(
111117 }
112118 }
113119
114- // Add constraint
115- problem. add_row ( 0.0 ..=0.0 , terms. drain ( ..) ) ;
120+ // Add constraint. For SED commodities, the RHS is zero and for SVD commodities it
121+ // is the exogenous demand supplied by the user.
122+ let rhs = if commodity. kind == CommodityType :: ServiceDemand {
123+ * commodity
124+ . demand
125+ . get ( & ( region_id. clone ( ) , year, ts_selection. clone ( ) ) )
126+ . unwrap ( )
127+ } else {
128+ 0.0
129+ } ;
130+ problem. add_row ( rhs..=rhs, terms. drain ( ..) ) ;
116131 keys. push ( (
117132 commodity_id. clone ( ) ,
118133 region_id. clone ( ) ,
0 commit comments