mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 00:08:52 -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
|
||||
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)
|
||||
return instance.units_by_name = Dict(g.name => g for g in instance.units)
|
||||
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,
|
||||
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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user