mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 08:18:51 -06:00
stochastic extension
This commit is contained in:
@@ -8,20 +8,21 @@ using UnitCommitment, Cbc, JuMP
|
||||
# Load instance
|
||||
instance = UnitCommitment.read("$FIXTURES/case118-initcond.json.gz")
|
||||
optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
||||
for sc in instance.scenarios
|
||||
# All units should have unknown initial conditions
|
||||
for g in sc.units
|
||||
@test g.initial_power === nothing
|
||||
@test g.initial_status === nothing
|
||||
end
|
||||
|
||||
# All units should have unknown initial conditions
|
||||
for g in instance.units
|
||||
@test g.initial_power === nothing
|
||||
@test g.initial_status === nothing
|
||||
end
|
||||
# Generate initial conditions
|
||||
UnitCommitment.generate_initial_conditions!(sc, optimizer)
|
||||
|
||||
# Generate initial conditions
|
||||
UnitCommitment.generate_initial_conditions!(instance, optimizer)
|
||||
|
||||
# All units should now have known initial conditions
|
||||
for g in instance.units
|
||||
@test g.initial_power !== nothing
|
||||
@test g.initial_status !== nothing
|
||||
# All units should now have known initial conditions
|
||||
for g in sc.units
|
||||
@test g.initial_power !== nothing
|
||||
@test g.initial_status !== nothing
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Check that initial conditions are feasible
|
||||
|
||||
@@ -10,60 +10,78 @@ using Random
|
||||
using UnitCommitment, Cbc, JuMP
|
||||
|
||||
get_instance() = UnitCommitment.read_benchmark("matpower/case118/2017-02-01")
|
||||
system_load(instance) = sum(b.load for b in instance.buses)
|
||||
system_load(sc) = sum(b.load for b in sc.buses)
|
||||
test_approx(x, y) = @test isapprox(x, y, atol = 1e-3)
|
||||
|
||||
@testset "XavQiuAhm2021" begin
|
||||
@testset "cost and load share" begin
|
||||
instance = get_instance()
|
||||
for sc in instance.scenarios
|
||||
# Check original costs
|
||||
unit = sc.units[10]
|
||||
test_approx(unit.min_power_cost[1], 825.023)
|
||||
test_approx(unit.cost_segments[1].cost[1], 36.659)
|
||||
test_approx(unit.startup_categories[1].cost[1], 7570.42)
|
||||
|
||||
# Check original costs
|
||||
unit = instance.units[10]
|
||||
test_approx(unit.min_power_cost[1], 825.023)
|
||||
test_approx(unit.cost_segments[1].cost[1], 36.659)
|
||||
test_approx(unit.startup_categories[1].cost[1], 7570.42)
|
||||
# Check original load share
|
||||
bus = sc.buses[1]
|
||||
prev_system_load = system_load(sc)
|
||||
test_approx(bus.load[1] / prev_system_load[1], 0.012)
|
||||
|
||||
# Check original load share
|
||||
bus = instance.buses[1]
|
||||
prev_system_load = system_load(instance)
|
||||
test_approx(bus.load[1] / prev_system_load[1], 0.012)
|
||||
randomize!(
|
||||
sc,
|
||||
method = XavQiuAhm2021.Randomization(
|
||||
randomize_load_profile = false,
|
||||
),
|
||||
rng = MersenneTwister(42),
|
||||
)
|
||||
|
||||
randomize!(
|
||||
instance,
|
||||
method = XavQiuAhm2021.Randomization(
|
||||
randomize_load_profile = false,
|
||||
),
|
||||
rng = MersenneTwister(42),
|
||||
)
|
||||
# Check randomized costs
|
||||
test_approx(unit.min_power_cost[1], 831.977)
|
||||
test_approx(unit.cost_segments[1].cost[1], 36.968)
|
||||
test_approx(unit.startup_categories[1].cost[1], 7634.226)
|
||||
|
||||
# Check randomized costs
|
||||
test_approx(unit.min_power_cost[1], 831.977)
|
||||
test_approx(unit.cost_segments[1].cost[1], 36.968)
|
||||
test_approx(unit.startup_categories[1].cost[1], 7634.226)
|
||||
# Check randomized load share
|
||||
curr_system_load = system_load(sc)
|
||||
test_approx(bus.load[1] / curr_system_load[1], 0.013)
|
||||
|
||||
# Check randomized load share
|
||||
curr_system_load = system_load(instance)
|
||||
test_approx(bus.load[1] / curr_system_load[1], 0.013)
|
||||
|
||||
# System load should not change
|
||||
@test prev_system_load ≈ curr_system_load
|
||||
# System load should not change
|
||||
@test prev_system_load ≈ curr_system_load
|
||||
end
|
||||
end
|
||||
|
||||
@testset "load profile" begin
|
||||
instance = get_instance()
|
||||
for sc in instance.scenarios
|
||||
# Check original load profile
|
||||
@test round.(system_load(sc), digits = 1)[1:8] ≈ [
|
||||
3059.5,
|
||||
2983.2,
|
||||
2937.5,
|
||||
2953.9,
|
||||
3073.1,
|
||||
3356.4,
|
||||
4068.5,
|
||||
4018.8,
|
||||
]
|
||||
|
||||
# Check original load profile
|
||||
@test round.(system_load(instance), digits = 1)[1:8] ≈
|
||||
[3059.5, 2983.2, 2937.5, 2953.9, 3073.1, 3356.4, 4068.5, 4018.8]
|
||||
randomize!(
|
||||
sc;
|
||||
method = XavQiuAhm2021.Randomization(),
|
||||
rng = MersenneTwister(42),
|
||||
)
|
||||
|
||||
randomize!(
|
||||
instance,
|
||||
XavQiuAhm2021.Randomization(),
|
||||
rng = MersenneTwister(42),
|
||||
)
|
||||
|
||||
# Check randomized load profile
|
||||
@test round.(system_load(instance), digits = 1)[1:8] ≈
|
||||
[4854.7, 4849.2, 4732.7, 4848.2, 4948.4, 5231.1, 5874.8, 5934.8]
|
||||
# Check randomized load profile
|
||||
@test round.(system_load(sc), digits = 1)[1:8] ≈ [
|
||||
4854.7,
|
||||
4849.2,
|
||||
4732.7,
|
||||
4848.2,
|
||||
4948.4,
|
||||
5231.1,
|
||||
5874.8,
|
||||
5934.8,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,29 +10,31 @@ using UnitCommitment, LinearAlgebra, Cbc, JuMP, JSON, GZip
|
||||
|
||||
# Should update all time-dependent fields
|
||||
@test modified.time == 2
|
||||
@test length(modified.power_balance_penalty) == 2
|
||||
@test length(modified.reserves_by_name["r1"].amount) == 2
|
||||
for u in modified.units
|
||||
@test length(u.max_power) == 2
|
||||
@test length(u.min_power) == 2
|
||||
@test length(u.must_run) == 2
|
||||
@test length(u.min_power_cost) == 2
|
||||
for s in u.cost_segments
|
||||
@test length(s.mw) == 2
|
||||
@test length(s.cost) == 2
|
||||
for sc in modified.scenarios
|
||||
@test length(sc.power_balance_penalty) == 2
|
||||
@test length(sc.reserves_by_name["r1"].amount) == 2
|
||||
for u in sc.units
|
||||
@test length(u.max_power) == 2
|
||||
@test length(u.min_power) == 2
|
||||
@test length(u.must_run) == 2
|
||||
@test length(u.min_power_cost) == 2
|
||||
for s in u.cost_segments
|
||||
@test length(s.mw) == 2
|
||||
@test length(s.cost) == 2
|
||||
end
|
||||
end
|
||||
for b in sc.buses
|
||||
@test length(b.load) == 2
|
||||
end
|
||||
for l in sc.lines
|
||||
@test length(l.normal_flow_limit) == 2
|
||||
@test length(l.emergency_flow_limit) == 2
|
||||
@test length(l.flow_limit_penalty) == 2
|
||||
end
|
||||
for ps in sc.price_sensitive_loads
|
||||
@test length(ps.demand) == 2
|
||||
@test length(ps.revenue) == 2
|
||||
end
|
||||
end
|
||||
for b in modified.buses
|
||||
@test length(b.load) == 2
|
||||
end
|
||||
for l in modified.lines
|
||||
@test length(l.normal_flow_limit) == 2
|
||||
@test length(l.emergency_flow_limit) == 2
|
||||
@test length(l.flow_limit_penalty) == 2
|
||||
end
|
||||
for ps in modified.price_sensitive_loads
|
||||
@test length(ps.demand) == 2
|
||||
@test length(ps.revenue) == 2
|
||||
end
|
||||
# Should be able to build model without errors
|
||||
optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
||||
|
||||
Reference in New Issue
Block a user