mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 16:28:51 -06:00
Reformat source code
This commit is contained in:
@@ -88,7 +88,7 @@ function compute_lmp(
|
|||||||
# prepare the result dictionary and solve the model
|
# prepare the result dictionary and solve the model
|
||||||
elmp = OrderedDict()
|
elmp = OrderedDict()
|
||||||
@info "Solving the approximation model."
|
@info "Solving the approximation model."
|
||||||
approx_model = build_model(instance=instance, variable_names=true)
|
approx_model = build_model(instance = instance, variable_names = true)
|
||||||
|
|
||||||
# relax the binary constraint, and relax integrality
|
# relax the binary constraint, and relax integrality
|
||||||
for v in all_variables(approx_model)
|
for v in all_variables(approx_model)
|
||||||
@@ -111,14 +111,13 @@ function compute_lmp(
|
|||||||
return elmp
|
return elmp
|
||||||
end
|
end
|
||||||
|
|
||||||
function _aelmp_check_parameters(
|
function _aelmp_check_parameters(method::AELMP, model::JuMP.Model)
|
||||||
method::AELMP,
|
|
||||||
model::JuMP.Model
|
|
||||||
)
|
|
||||||
# CHECK: model must be solved if allow_offline_participation=false
|
# CHECK: model must be solved if allow_offline_participation=false
|
||||||
if !method.allow_offline_participation
|
if !method.allow_offline_participation
|
||||||
if isnothing(model) || !has_values(model)
|
if isnothing(model) || !has_values(model)
|
||||||
error("A solved UC model is required if allow_offline_participation=false.")
|
error(
|
||||||
|
"A solved UC model is required if allow_offline_participation=false.",
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -126,7 +125,7 @@ end
|
|||||||
function _modify_instance!(
|
function _modify_instance!(
|
||||||
instance::UnitCommitmentInstance,
|
instance::UnitCommitmentInstance,
|
||||||
model::JuMP.Model,
|
model::JuMP.Model,
|
||||||
method::AELMP
|
method::AELMP,
|
||||||
)
|
)
|
||||||
# this function modifies the instance units (generators)
|
# this function modifies the instance units (generators)
|
||||||
# 1. remove (if NOT allowing) the offline generators
|
# 1. remove (if NOT allowing) the offline generators
|
||||||
@@ -152,10 +151,14 @@ function _modify_instance!(
|
|||||||
# min_power & min_costs are vectors with dimension T
|
# min_power & min_costs are vectors with dimension T
|
||||||
if unit.min_power[1] != 0
|
if unit.min_power[1] != 0
|
||||||
first_cost_segment = unit.cost_segments[1]
|
first_cost_segment = unit.cost_segments[1]
|
||||||
pushfirst!(unit.cost_segments, CostSegment(
|
pushfirst!(
|
||||||
|
unit.cost_segments,
|
||||||
|
CostSegment(
|
||||||
ones(size(first_cost_segment.mw)) * unit.min_power[1],
|
ones(size(first_cost_segment.mw)) * unit.min_power[1],
|
||||||
ones(size(first_cost_segment.cost)) * unit.min_power_cost[1] / unit.min_power[1]
|
ones(size(first_cost_segment.cost)) *
|
||||||
))
|
unit.min_power_cost[1] / unit.min_power[1],
|
||||||
|
),
|
||||||
|
)
|
||||||
unit.min_power = zeros(size(first_cost_segment.mw))
|
unit.min_power = zeros(size(first_cost_segment.mw))
|
||||||
unit.min_power_cost = zeros(size(first_cost_segment.cost))
|
unit.min_power_cost = zeros(size(first_cost_segment.cost))
|
||||||
end
|
end
|
||||||
@@ -175,12 +178,13 @@ function _modify_instance!(
|
|||||||
# 4. other adjustments...
|
# 4. other adjustments...
|
||||||
### FIXME in the future
|
### FIXME in the future
|
||||||
# MISO Phase I: can ONLY solve fast-starts, force all startup time to be 0
|
# MISO Phase I: can ONLY solve fast-starts, force all startup time to be 0
|
||||||
unit.startup_categories = StartupCategory[StartupCategory(0, first_startup_cost)]
|
unit.startup_categories =
|
||||||
|
StartupCategory[StartupCategory(0, first_startup_cost)]
|
||||||
unit.initial_status = -100
|
unit.initial_status = -100
|
||||||
unit.initial_power = 0
|
unit.initial_power = 0
|
||||||
unit.min_uptime = 0
|
unit.min_uptime = 0
|
||||||
unit.min_downtime = 0
|
unit.min_downtime = 0
|
||||||
### END FIXME
|
### END FIXME
|
||||||
end
|
end
|
||||||
instance.units_by_name = Dict(g.name => g for g in instance.units)
|
return instance.units_by_name = Dict(g.name => g for g in instance.units)
|
||||||
end
|
end
|
||||||
@@ -3,37 +3,33 @@
|
|||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using UnitCommitment, Cbc, HiGHS, JuMP
|
using UnitCommitment, Cbc, HiGHS, JuMP
|
||||||
import UnitCommitment:
|
import UnitCommitment: AELMP
|
||||||
AELMP
|
|
||||||
|
|
||||||
@testset "aelmp" begin
|
@testset "aelmp" begin
|
||||||
path = "$FIXTURES/aelmp_simple.json.gz"
|
path = "$FIXTURES/aelmp_simple.json.gz"
|
||||||
# model has to be solved first
|
# model has to be solved first
|
||||||
instance = UnitCommitment.read(path)
|
instance = UnitCommitment.read(path)
|
||||||
model = UnitCommitment.build_model(
|
model = UnitCommitment.build_model(
|
||||||
instance=instance,
|
instance = instance,
|
||||||
optimizer=Cbc.Optimizer,
|
optimizer = Cbc.Optimizer,
|
||||||
variable_names = true,
|
variable_names = true,
|
||||||
)
|
)
|
||||||
JuMP.set_silent(model)
|
JuMP.set_silent(model)
|
||||||
UnitCommitment.optimize!(model)
|
UnitCommitment.optimize!(model)
|
||||||
|
|
||||||
# policy 1: allow offlines; consider startups
|
# policy 1: allow offlines; consider startups
|
||||||
aelmp_1 = UnitCommitment.compute_lmp(
|
aelmp_1 =
|
||||||
model,
|
UnitCommitment.compute_lmp(model, AELMP(), optimizer = HiGHS.Optimizer)
|
||||||
AELMP(),
|
|
||||||
optimizer=HiGHS.Optimizer
|
|
||||||
)
|
|
||||||
@test aelmp_1["B1", 1] ≈ 231.7 atol = 0.1
|
@test aelmp_1["B1", 1] ≈ 231.7 atol = 0.1
|
||||||
|
|
||||||
# policy 2: do not allow offlines; but consider startups
|
# policy 2: do not allow offlines; but consider startups
|
||||||
aelmp_2 = UnitCommitment.compute_lmp(
|
aelmp_2 = UnitCommitment.compute_lmp(
|
||||||
model,
|
model,
|
||||||
AELMP(
|
AELMP(
|
||||||
allow_offline_participation=false,
|
allow_offline_participation = false,
|
||||||
consider_startup_costs=true
|
consider_startup_costs = true,
|
||||||
),
|
),
|
||||||
optimizer=HiGHS.Optimizer
|
optimizer = HiGHS.Optimizer,
|
||||||
)
|
)
|
||||||
@test aelmp_2["B1", 1] ≈ 274.3 atol = 0.1
|
@test aelmp_2["B1", 1] ≈ 274.3 atol = 0.1
|
||||||
end
|
end
|
||||||
@@ -17,7 +17,7 @@ function solve_lmp_testcase(path::String)
|
|||||||
lmp = UnitCommitment.compute_lmp(
|
lmp = UnitCommitment.compute_lmp(
|
||||||
model,
|
model,
|
||||||
ConventionalLMP(),
|
ConventionalLMP(),
|
||||||
optimizer=HiGHS.Optimizer,
|
optimizer = HiGHS.Optimizer,
|
||||||
)
|
)
|
||||||
return lmp
|
return lmp
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user