Skip to content

Commit d1d2b3a

Browse files
committed
[WIP] Rolling horizon
1 parent 70d35a1 commit d1d2b3a

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/model-preparation.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ function add_expression_terms_over_clustered_year_constraints!(
276276
cases = [(expr_key = :outgoing, asset_match = :from_asset)]
277277
if is_storage_level
278278
push!(cases, (expr_key = :incoming, asset_match = :to_asset))
279-
attach_coefficient!(cons, :inflows_profile_aggregation, zeros(num_rows))
280279
end
281280

282281
for case in cases
@@ -643,34 +642,35 @@ function prepare_profiles_structure(connection)
643642
profile_name = row.profile_name
644643
year = row.commission_year
645644
storage_inflows = row.storage_inflows
646-
over_clustered_year[(profile_name, year)] = ProfileWithRollingHorizon(
647-
Float64[
648-
row.value for row in DuckDB.query(
649-
connection,
650-
"""
651-
WITH cte_profile_rp AS (
652-
SELECT
653-
'$asset' AS asset,
654-
$year AS year,
655-
profiles_rep_periods.rep_period,
656-
profiles_rep_periods.timestep,
657-
profiles_rep_periods.value,
658-
FROM profiles_rep_periods
659-
WHERE profile_name = '$profile_name' AND year = $year
660-
)
645+
values = Float64[
646+
row.value for row in DuckDB.query(
647+
connection,
648+
"""
649+
WITH cte_profile_rp AS (
661650
SELECT
662-
rp_map.period,
663-
SUM(cte_profile_rp.value * rp_map.weight * $storage_inflows) AS value,
664-
FROM cte_profile_rp
665-
LEFT JOIN rep_periods_mapping AS rp_map
666-
ON cte_profile_rp.year = rp_map.year
667-
AND cte_profile_rp.rep_period = rp_map.rep_period
668-
GROUP BY rp_map.period
669-
ORDER BY rp_map.period
670-
""",
651+
'$asset' AS asset,
652+
$year AS year,
653+
profiles_rep_periods.rep_period,
654+
profiles_rep_periods.timestep,
655+
profiles_rep_periods.value,
656+
FROM profiles_rep_periods
657+
WHERE profile_name = '$profile_name' AND year = $year
671658
)
672-
],
673-
)
659+
SELECT
660+
rp_map.period,
661+
SUM(cte_profile_rp.value * rp_map.weight * $storage_inflows) AS value,
662+
FROM cte_profile_rp
663+
LEFT JOIN rep_periods_mapping AS rp_map
664+
ON cte_profile_rp.year = rp_map.year
665+
AND cte_profile_rp.rep_period = rp_map.rep_period
666+
GROUP BY rp_map.period
667+
ORDER BY rp_map.period
668+
""",
669+
)
670+
]
671+
if length(values) > 0
672+
over_clustered_year[(profile_name, year)] = ProfileWithRollingHorizon(values)
673+
end
674674
end
675675

676676
return ProfileLookup(rep_period, over_clustered_year)

0 commit comments

Comments
 (0)