From 6777e5fabf44c29042f30432ba503bb7b89c7294 Mon Sep 17 00:00:00 2001 From: Jun He Date: Thu, 30 Mar 2023 14:28:34 -0400 Subject: [PATCH] Formatted all the code lines --- src/instance/read.jl | 34 +++++++++++++++++++--------- src/lmp/aelmp.jl | 18 +++++---------- src/model/formulations/base/punit.jl | 7 ++---- test/instance/read_test.jl | 2 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/instance/read.jl b/src/instance/read.jl index 98393e7..ad82653 100644 --- a/src/instance/read.jl +++ b/src/instance/read.jl @@ -172,10 +172,16 @@ function _from_json(json; repair = true) # Read production cost curve K = length(dict["Production cost curve (MW)"]) curve_mw = hcat( - [timeseries(dict["Production cost curve (MW)"][k]) for k in 1:K]..., + [ + timeseries(dict["Production cost curve (MW)"][k]) for + k in 1:K + ]..., ) curve_cost = hcat( - [timeseries(dict["Production cost curve (\$)"][k]) for k in 1:K]..., + [ + timeseries(dict["Production cost curve (\$)"][k]) for + k in 1:K + ]..., ) min_power = curve_mw[:, 1] max_power = curve_mw[:, K] @@ -210,14 +216,18 @@ function _from_json(json; repair = true) end # Read and validate initial conditions - initial_power = scalar(dict["Initial power (MW)"], default = nothing) - initial_status = scalar(dict["Initial status (h)"], default = nothing) + initial_power = + scalar(dict["Initial power (MW)"], default = nothing) + initial_status = + scalar(dict["Initial status (h)"], default = nothing) if initial_power === nothing - initial_status === nothing || - error("unit $unit_name has initial status but no initial power") + initial_status === nothing || error( + "unit $unit_name has initial status but no initial power", + ) else - initial_status !== nothing || - error("unit $unit_name has initial power but no initial status") + initial_status !== nothing || error( + "unit $unit_name has initial power but no initial status", + ) initial_status != 0 || error("unit $unit_name has invalid initial status") if initial_status < 0 && initial_power > 1e-3 @@ -234,8 +244,10 @@ function _from_json(json; repair = true) timeseries(dict["Must run?"], default = [false for t in 1:T]), min_power_cost, segments, - scalar(dict["Minimum uptime (h)"], default = 1) * time_multiplier, - scalar(dict["Minimum downtime (h)"], default = 1) * time_multiplier, + scalar(dict["Minimum uptime (h)"], default = 1) * + time_multiplier, + scalar(dict["Minimum downtime (h)"], default = 1) * + time_multiplier, scalar(dict["Ramp up limit (MW)"], default = 1e6), scalar(dict["Ramp down limit (MW)"], default = 1e6), scalar(dict["Startup limit (MW)"], default = 1e6), @@ -257,7 +269,7 @@ function _from_json(json; repair = true) unit_name, bus, timeseries(dict["Maximum power (MW)"]), - timeseries(dict["Cost (\$/MW)"]) + timeseries(dict["Cost (\$/MW)"]), ) push!(bus.profiled_units, pu) push!(profiled_units, pu) diff --git a/src/lmp/aelmp.jl b/src/lmp/aelmp.jl index 93041da..0601a62 100644 --- a/src/lmp/aelmp.jl +++ b/src/lmp/aelmp.jl @@ -124,28 +124,22 @@ function _aelmp_check_parameters( ) end end - all_units = instance.units; + all_units = instance.units # CHECK: model cannot handle non-fast-starts (MISO Phase I: can ONLY solve fast-starts) - if any(u -> u.min_uptime > 1 || u.min_downtime > 1, all_units) + if any(u -> u.min_uptime > 1 || u.min_downtime > 1, all_units) error( "The minimum up/down time of all generators must be 1. AELMP only supports fast-starts.", ) end if any(u -> u.initial_power > 0, all_units) - error( - "The initial power of all generators must be 0.", - ) + error("The initial power of all generators must be 0.") end if any(u -> u.initial_status >= 0, all_units) - error( - "The initial status of all generators must be negative.", - ) + error("The initial status of all generators must be negative.") end # CHECK: model does not support startup costs (in time series) if any(u -> length(u.startup_categories) > 1, all_units) - error( - "The method does NOT support time-varying start-up costs.", - ) + error("The method does NOT support time-varying start-up costs.") end end @@ -204,7 +198,7 @@ function _modify_instance!( first_startup_cost = 0.0 # zero out the start up cost end unit.startup_categories = - StartupCategory[StartupCategory(0, first_startup_cost)] + StartupCategory[StartupCategory(0, first_startup_cost)] end return instance.units_by_name = Dict(g.name => g for g in instance.units) end diff --git a/src/model/formulations/base/punit.jl b/src/model/formulations/base/punit.jl index 81e86cc..367a17b 100644 --- a/src/model/formulations/base/punit.jl +++ b/src/model/formulations/base/punit.jl @@ -2,11 +2,8 @@ # Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved. # Released under the modified BSD license. See COPYING.md for more details. -function _add_profiled_unit!( - model::JuMP.Model, - pu::ProfiledUnit, -)::Nothing - punits = _init(model, :profiled_units) +function _add_profiled_unit!(model::JuMP.Model, pu::ProfiledUnit)::Nothing + punits = _init(model, :prod_profiled) net_injection = _init(model, :expr_net_injection) for t in 1:model[:instance].time # Decision variable diff --git a/test/instance/read_test.jl b/test/instance/read_test.jl index 0ef0cc7..2966be8 100644 --- a/test/instance/read_test.jl +++ b/test/instance/read_test.jl @@ -237,4 +237,4 @@ end @test profiled_unit.cost == [50.0 for t in 1:4] @test profiled_unit.capacity == [120.0 for t in 1:4] @test instance.profiled_units_by_name["g8"].name == "g8" -end \ No newline at end of file +end