Reformat source code

pull/27/head
Alinson S. Xavier 3 years ago
parent d7d2a3fcf6
commit 19e84bac07
Signed by: isoron
GPG Key ID: 0DA8E4B9E1109DCA

@ -88,7 +88,7 @@ function compute_lmp(
# prepare the result dictionary and solve the model
elmp = OrderedDict()
@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
for v in all_variables(approx_model)
@ -111,14 +111,13 @@ function compute_lmp(
return elmp
end
function _aelmp_check_parameters(
method::AELMP,
model::JuMP.Model
)
function _aelmp_check_parameters(method::AELMP, model::JuMP.Model)
# CHECK: model must be solved if allow_offline_participation=false
if !method.allow_offline_participation
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
@ -126,7 +125,7 @@ end
function _modify_instance!(
instance::UnitCommitmentInstance,
model::JuMP.Model,
method::AELMP
method::AELMP,
)
# this function modifies the instance units (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
if unit.min_power[1] != 0
first_cost_segment = unit.cost_segments[1]
pushfirst!(unit.cost_segments, CostSegment(
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]
))
pushfirst!(
unit.cost_segments,
CostSegment(
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],
),
)
unit.min_power = zeros(size(first_cost_segment.mw))
unit.min_power_cost = zeros(size(first_cost_segment.cost))
end
@ -175,12 +178,13 @@ function _modify_instance!(
# 4. other adjustments...
### FIXME in the future
# 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_power = 0
unit.min_uptime = 0
unit.min_downtime = 0
### END FIXME
end
instance.units_by_name = Dict(g.name => g for g in instance.units)
end
return instance.units_by_name = Dict(g.name => g for g in instance.units)
end

@ -82,7 +82,7 @@ function compute_lmp(
@info "Solving the LP..."
JuMP.optimize!(model)
@info "Getting dual values (LMPs)..."
for (key, val) in model[:eq_net_injection]
lmp[key] = dual(val)

@ -22,7 +22,7 @@ Arguments
- `consider_startup_costs`:
If true, the start-up costs are averaged over each unit production; otherwise the production costs stay the same.
"""
Base.@kwdef struct AELMP <: PricingMethod
Base.@kwdef struct AELMP <: PricingMethod
allow_offline_participation::Bool = true
consider_startup_costs::Bool = true
end
end

@ -3,37 +3,33 @@
# Released under the modified BSD license. See COPYING.md for more details.
using UnitCommitment, Cbc, HiGHS, JuMP
import UnitCommitment:
AELMP
import UnitCommitment: AELMP
@testset "aelmp" begin
path = "$FIXTURES/aelmp_simple.json.gz"
# model has to be solved first
instance = UnitCommitment.read(path)
model = UnitCommitment.build_model(
instance=instance,
optimizer=Cbc.Optimizer,
instance = instance,
optimizer = Cbc.Optimizer,
variable_names = true,
)
JuMP.set_silent(model)
UnitCommitment.optimize!(model)
# policy 1: allow offlines; consider startups
aelmp_1 = UnitCommitment.compute_lmp(
model,
AELMP(),
optimizer=HiGHS.Optimizer
)
aelmp_1 =
UnitCommitment.compute_lmp(model, AELMP(), optimizer = HiGHS.Optimizer)
@test aelmp_1["B1", 1] 231.7 atol = 0.1
# policy 2: do not allow offlines; but consider startups
aelmp_2 = UnitCommitment.compute_lmp(
model,
model,
AELMP(
allow_offline_participation=false,
consider_startup_costs=true
allow_offline_participation = false,
consider_startup_costs = true,
),
optimizer=HiGHS.Optimizer
optimizer = HiGHS.Optimizer,
)
@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(
model,
ConventionalLMP(),
optimizer=HiGHS.Optimizer,
optimizer = HiGHS.Optimizer,
)
return lmp
end
@ -48,4 +48,4 @@ end
@test lmp["A", 1] == 50.0
@test lmp["B", 1] == 70.0
@test lmp["C", 1] == 90.0
end
end

Loading…
Cancel
Save