@@ -95,6 +95,8 @@ pub struct Asset {
9595 capacity : Capacity ,
9696 /// The year the asset was/will be commissioned
9797 commission_year : u32 ,
98+ /// The year the asset was/will be decommissioned
99+ max_decommission_year : u32 ,
98100}
99101
100102impl Asset {
@@ -111,6 +113,7 @@ impl Asset {
111113 region_id,
112114 capacity,
113115 commission_year,
116+ None ,
114117 )
115118 }
116119
@@ -125,12 +128,13 @@ impl Asset {
125128 }
126129
127130 /// Create a new future asset
128- pub fn new_future (
131+ pub fn new_future_with_max_decommission (
129132 agent_id : AgentID ,
130133 process : Rc < Process > ,
131134 region_id : RegionID ,
132135 capacity : Capacity ,
133136 commission_year : u32 ,
137+ max_decommission_year : Option < u32 > ,
134138 ) -> Result < Self > {
135139 check_capacity_valid_for_asset ( capacity) ?;
136140 Self :: new_with_state (
@@ -139,26 +143,27 @@ impl Asset {
139143 region_id,
140144 capacity,
141145 commission_year,
146+ max_decommission_year,
142147 )
143148 }
144149
145- /// Create a new decommissioned asset TODO
146- // pub fn new_decommissioned (
147- // agent_id: AgentID,
148- // process: Rc<Process>,
149- // region_id: RegionID,
150- // capacity: Capacity,
151- // commission_year: u32,
152- // max_decommission_year: u32,
153- // ) -> Result<Self> {
154- // Self::new_with_state(
155- // AssetState::Decommissioned { agent_id, decommission_year: max_decommission_year } ,
156- // process ,
157- // region_id ,
158- // capacity ,
159- // commission_year ,
160- // )
161- // }
150+ /// Create a new future asset
151+ pub fn new_future (
152+ agent_id : AgentID ,
153+ process : Rc < Process > ,
154+ region_id : RegionID ,
155+ capacity : Capacity ,
156+ commission_year : u32 ,
157+ ) -> Result < Self > {
158+ Self :: new_future_with_max_decommission (
159+ agent_id ,
160+ process ,
161+ region_id ,
162+ capacity ,
163+ commission_year ,
164+ None ,
165+ )
166+ }
162167
163168 /// Create a new selected asset
164169 ///
@@ -178,6 +183,7 @@ impl Asset {
178183 region_id,
179184 capacity,
180185 commission_year,
186+ None ,
181187 )
182188 }
183189
@@ -188,6 +194,7 @@ impl Asset {
188194 region_id : RegionID ,
189195 capacity : Capacity ,
190196 commission_year : u32 ,
197+ max_decommission_year : Option < u32 > ,
191198 ) -> Result < Self > {
192199 check_region_year_valid_for_process ( & process, & region_id, commission_year) ?;
193200 ensure ! ( capacity >= Capacity ( 0.0 ) , "Capacity must be non-negative" ) ;
@@ -232,6 +239,13 @@ impl Asset {
232239 } ) ?
233240 . clone ( ) ;
234241
242+ let max_decommission_year =
243+ max_decommission_year. unwrap_or ( commission_year + process_parameter. lifetime ) ;
244+ ensure ! (
245+ max_decommission_year >= commission_year,
246+ "Max decommission year must be after/same as commission year"
247+ ) ;
248+
235249 Ok ( Self {
236250 state,
237251 process,
@@ -241,6 +255,7 @@ impl Asset {
241255 region_id,
242256 capacity,
243257 commission_year,
258+ max_decommission_year,
244259 } )
245260 }
246261
@@ -256,7 +271,7 @@ impl Asset {
256271
257272 /// The last year in which this asset should be decommissioned
258273 pub fn max_decommission_year ( & self ) -> u32 {
259- self . commission_year + self . process_parameter . lifetime
274+ self . max_decommission_year
260275 }
261276
262277 /// Get the activity limits for this asset in a particular time slice
0 commit comments