@@ -354,25 +354,39 @@ function check_time_structure(x::AbstractElement, 𝒯)
354354end
355355
356356"""
357- check_profile(fieldname, value::TimeProfile, 𝒯)
357+ check_profile(fieldname, value::TimeProfile, 𝒯::TwoLevel)
358+ check_profile(fieldname, value::StrategicProfile, 𝒯::TwoLevel)
359+ check_profile(fieldname, value::StrategicStochasticProfile, 𝒯::TwoLevel)
358360
359- Check that an individual `TimeProfile` corresponds to the time structure `𝒯`.
360- It currently does not include support for identifying `OperationalScenarios`.
361+ check_profile(fieldname, value::TimeProfile, 𝒯::TwoLevelTree)
362+ check_profile(fieldname, value::StrategicProfile, 𝒯::TwoLevelTree)
363+ check_profile(fieldname, value::StrategicStochasticProfile, 𝒯::TwoLevelTree)
364+
365+ Check that an individual `TimeProfile` corresponds to the time structure `𝒯`. The individual
366+ checks are depending on the profile type and the time structure.
361367"""
368+ function check_profile (fieldname, value:: TimeProfile , 𝒯:: TwoLevel )
369+ 𝒯ᴵⁿᵛ = strategic_periods (𝒯)
370+ for t_inv ∈ 𝒯ᴵⁿᵛ
371+ p_msg = " strategic period $(t_inv. sp) "
372+ check_profile (fieldname, value, t_inv. operational, p_msg)
373+ end
374+ end
362375function check_profile (fieldname, value:: StrategicProfile , 𝒯:: TwoLevel )
363376 𝒯ᴵⁿᵛ = strategic_periods (𝒯)
364377
365378 len_vals = length (value. vals)
366379 len_ts = length (𝒯ᴵⁿᵛ)
367380 if len_vals > len_ts
368- message = " ` is longer than the strategic time structure. \
369- Its last $(len_vals - len_ts) value(s) will be omitted."
381+ message = " ` is longer than the strategic time structure. " *
382+ " Its last $(len_vals - len_ts) value(s) will be omitted."
370383 elseif len_vals < len_ts
371- message = " ` is shorter than the strategic time structure. It will use the last \
372- value for the last $(len_ts - len_vals) strategic period(s)."
384+ message = " ` is shorter than the strategic time structure. It will use the last " *
385+ " value for the last $(len_ts - len_vals) strategic period(s)."
373386 end
374- @assert_or_log len_vals ==
375- len_ts " The `TimeProfile` of field `" * string (fieldname) * message
387+ @assert_or_log (
388+ len_vals == len_ts, " The `TimeProfile` of field `" * string (fieldname) * message
389+ )
376390 for t_inv ∈ 𝒯ᴵⁿᵛ
377391 p_msg = " strategic period $(t_inv. sp) "
378392 check_profile (
@@ -383,13 +397,102 @@ function check_profile(fieldname, value::StrategicProfile, 𝒯::TwoLevel)
383397 )
384398 end
385399end
386- function check_profile (fieldname, value, 𝒯:: TwoLevel )
400+ function check_profile (fieldname, value:: StrategicStochasticProfile , 𝒯:: TwoLevel )
401+ @warn (
402+ " Using `StrategicStochasticProfile` with `TwoLevel` is dangerous, " *
403+ " as it may lead to unexpected behaviour. " *
404+ " In this case, only the profiles of the first scenario are used in the model and " *
405+ " tested." ,
406+ maxlog = 1
407+ )
408+ prof = StrategicProfile ([op_prof[1 ] for op_prof ∈ value. vals])
409+ check_profile (fieldname, prof, 𝒯)
410+ end
411+ function check_profile (fieldname, value:: TimeProfile , 𝒯:: TwoLevelTree )
387412 𝒯ᴵⁿᵛ = strategic_periods (𝒯)
388413 for t_inv ∈ 𝒯ᴵⁿᵛ
389- p_msg = " strategic period $(t_inv. sp) "
414+ p_msg = " branch $(t_inv . branch) in strategic period $(t_inv. sp) "
390415 check_profile (fieldname, value, t_inv. operational, p_msg)
391416 end
392417end
418+ function check_profile (fieldname, value:: StrategicProfile , 𝒯:: TwoLevelTree )
419+ 𝒯ˢˢᶜ = strategic_scenarios (𝒯)
420+ t_inv_vec = []
421+
422+ for ssc ∈ 𝒯ˢˢᶜ
423+ 𝒯ᴵⁿᵛ = strategic_periods (ssc)
424+ len_vals = length (value. vals)
425+ len_ts = length (𝒯ᴵⁿᵛ)
426+ if len_vals > len_ts
427+ message = " ` is longer than strategic scenario $(ssc. scen) . " *
428+ " Its last $(len_vals - len_ts) value(s) will be omitted."
429+ elseif len_vals < len_ts
430+ message = " ` is shorter than strategic scenario $(ssc. scen) . It will use the " *
431+ " last value for the last $(len_ts - len_vals) strategic period(s)."
432+ end
433+ @assert_or_log (
434+ len_vals == len_ts, " The `TimeProfile` of field `" * string (fieldname) * message,
435+ )
436+ for t_inv ∈ 𝒯ᴵⁿᵛ
437+ t_inv ∈ t_inv_vec && continue
438+ push! (t_inv_vec, t_inv)
439+
440+ p_msg = " branch $(t_inv. branch) in strategic period $(t_inv. sp) "
441+ check_profile (
442+ fieldname,
443+ value. vals[minimum ([t_inv. sp, length (value. vals)])],
444+ t_inv. operational,
445+ p_msg,
446+ )
447+ end
448+ end
449+ end
450+ function check_profile (fieldname, value:: StrategicStochasticProfile , 𝒯:: TwoLevelTree )
451+ # Check for the number of strategic periods
452+ len_vals = length (value. vals)
453+ len_ts = n_strat_per (𝒯)
454+ if len_vals > len_ts
455+ message = " ` is longer than the strategic time structure. " *
456+ " Its last $(len_vals - len_ts) value(s) will be omitted."
457+ elseif len_vals < len_ts
458+ message = " ` is shorter than the strategic time structure. It will use the last " *
459+ " value for the last $(len_ts - len_vals) strategic period(s)."
460+ end
461+ @assert_or_log (
462+ len_vals == len_ts,
463+ " The `TimeProfile` of field `" * string (fieldname) * message,
464+ )
465+
466+ # Check each individual branch
467+ for sp ∈ 1 : n_strat_per (𝒯)
468+ pre_msg = " ` in strategic period $(sp) has "
469+ len_vals = length (value. vals[minimum ([sp, length (value. vals)])])
470+ len_branches = n_branches (𝒯, sp)
471+ if len_vals > len_branches
472+ message = pre_msg * " more branches than the time structure. " *
473+ " Its last $(len_vals - len_branches) value(s) will be omitted."
474+ elseif len_vals < len_branches
475+ message = pre_msg * " less branches than the time structure. It will use the " *
476+ " last value for the last $(len_branches - len_vals) branche(s)."
477+ end
478+ @assert_or_log (
479+ len_vals == len_branches,
480+ " The `TimeProfile` of field `" * string (fieldname) * message,
481+ )
482+ end
483+
484+ # Check the sub profiles
485+ for t_inv ∈ strategic_periods (𝒯)
486+ p_msg = " branch $(t_inv. branch) in strategic period $(t_inv. sp) "
487+ sp_prof = value. vals[minimum ([t_inv. sp, length (value. vals)])]
488+ check_profile (
489+ fieldname,
490+ sp_prof[minimum ([t_inv. branch, length (sp_prof)])],
491+ t_inv. operational,
492+ p_msg,
493+ )
494+ end
495+ end
393496
394497"""
395498 check_profile(fieldname, value::TimeProfile, ts::TimeStructure, p_msg)
0 commit comments