|
1 | | -# Copyright 2016-2023 Blue Marble Analytics LLC. |
| 1 | +# Copyright 2016-2025 Blue Marble Analytics LLC. |
| 2 | +# Copyright 2026 Sylvan Energy Analytics LLC. |
2 | 3 | # |
3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 5 | # you may not use this file except in compliance with the License. |
@@ -179,7 +180,10 @@ def add_model_components( |
179 | 180 | ], |
180 | 181 | ) |
181 | 182 |
|
182 | | - m.OPR_PRJS_IN_TMP = Set(m.TMPS, initialize=op_gens_by_tmp) |
| 183 | + m.OPR_PRJS_IN_TMP = Set( |
| 184 | + m.TMPS, |
| 185 | + initialize=op_gens_by_tmp, |
| 186 | + ) |
183 | 187 |
|
184 | 188 | # Expressions |
185 | 189 | ########################################################################### |
@@ -281,18 +285,18 @@ def fuel_storage_capacity_rule(mod, prj, prd): |
281 | 285 | ############################################################################### |
282 | 286 |
|
283 | 287 |
|
284 | | -# TODO: the creation of the OPR_PRJS_IN_TMPS is by far |
285 | | -# the most time-consuming step in instantiating the problem; is there |
286 | | -# any way to speed it up? It is perhaps inefficient to iterate over all |
287 | | -# (g, t) for every timepoint, but how do we get around having to do that? |
288 | | -# Also, this is a more general problem with all the indexed sets, |
289 | | -# but the larger timepoints-based sets are more of a problem |
290 | | -def op_gens_by_tmp(mod, tmp): |
| 288 | +def op_gens_by_tmp(mod): |
291 | 289 | """ |
292 | | - Figure out which generators are operational in each timepoins. |
| 290 | + Figure out which generators are operational in each timepoint. |
293 | 291 | """ |
294 | | - gens = list(g for (g, t) in mod.PRJ_OPR_TMPS if t == tmp) |
295 | | - return gens |
| 292 | + tmp_to_projects = {} |
| 293 | + for g, tmp in mod.PRJ_OPR_TMPS: |
| 294 | + tmp_to_projects.setdefault(tmp, set()).add(g) |
| 295 | + |
| 296 | + for tmp in tmp_to_projects: |
| 297 | + tmp_to_projects[tmp] = list(tmp_to_projects[tmp]) |
| 298 | + |
| 299 | + return tmp_to_projects |
296 | 300 |
|
297 | 301 |
|
298 | 302 | def operational_periods_by_project(prj, project_operational_periods): |
|
0 commit comments