mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 08:18:51 -06:00
read and repair scenario
This commit is contained in:
@@ -58,7 +58,7 @@ instance = UnitCommitment.read("/path/to/input.json.gz")
|
||||
|
||||
function _repair_scenario_name_and_probability(
|
||||
scenarios::Vector{UnitCommitmentScenario},
|
||||
path::Vector{String}
|
||||
path::Vector{String},
|
||||
)::Vector{UnitCommitmentScenario}
|
||||
number_of_scenarios = length(scenarios)
|
||||
probs = [sc.probability for sc in scenarios]
|
||||
@@ -68,7 +68,9 @@ function _repair_scenario_name_and_probability(
|
||||
total_weight = sum(probs)
|
||||
catch e
|
||||
if isa(e, MethodError)
|
||||
error("If any of the scenarios is assigned a weight, then all scenarios must be assigned weights.")
|
||||
error(
|
||||
"If any of the scenarios is assigned a weight, then all scenarios must be assigned weights.",
|
||||
)
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -76,7 +78,8 @@ function _repair_scenario_name_and_probability(
|
||||
end
|
||||
|
||||
for (sc_path, sc) in zip(path, scenarios)
|
||||
sc.name !== "" || (sc.name = first(split(last(split(sc_path, "/")), ".")))
|
||||
sc.name !== "" ||
|
||||
(sc.name = first(split(last(split(sc_path, "/")), ".")))
|
||||
sc.probability = (sc.probability / total_weight)
|
||||
end
|
||||
return scenarios
|
||||
|
||||
@@ -30,9 +30,7 @@ test_approx(x, y) = @test isapprox(x, y, atol = 1e-3)
|
||||
|
||||
randomize!(
|
||||
sc,
|
||||
XavQiuAhm2021.Randomization(
|
||||
randomize_load_profile = false,
|
||||
),
|
||||
XavQiuAhm2021.Randomization(randomize_load_profile = false),
|
||||
rng = MersenneTwister(42),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user