Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Feb 3, 2024
1 parent da7be8c commit 3700340
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 5 deletions.
3 changes: 3 additions & 0 deletions test/DCOPF/Fuels_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Time_Index,natural_gas,coal,nuclear,None
0,0.05306,0.05306,0.05306,0.05306
1,0.05306,0.05306,0.05306,0.05306
4 changes: 4 additions & 0 deletions test/DCOPF/Generators_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
region,cluster,Resource,Resource_Type,MGA,R_ID,Zone,THERM,Commit,STOR,HYDRO,FLEX,MUST_RUN,VRE,LDS,Num_VRE_Bins,CapRes_1,ESR_1,ESR_2,Min_Share,Max_Share,Existing_Cap_MW,Existing_Charge_Cap_MW,Existing_Cap_MWh,New_Build,Cap_Size,Min_Cap_MW,Max_Cap_MW,Min_Charge_Cap_MW,Max_Charge_Cap_MW,Min_Cap_MWh,Max_Cap_MWh,Inv_Cost_per_MWyr,Fixed_OM_Cost_per_MWyr,Inv_Cost_per_MWhyr,Fixed_OM_Cost_per_MWhyr,Inv_Cost_Charge_per_MWyr,Fixed_OM_Cost_Charge_per_MWyr,Var_OM_Cost_per_MWh,Var_OM_Cost_per_MWh_In,Start_Cost_per_MW,Start_Fuel_MMBTU_per_MW,Heat_Rate_MMBTU_per_MWh,Fuel,Min_Power,Self_Disch,Eff_Up,Eff_Down,Hydro_Energy_to_Power_Ratio,Min_Duration,Max_Duration,Max_Flexible_Demand_Advance,Max_Flexible_Demand_Delay,Flexible_Demand_Energy_Eff,Ramp_Up_Percentage,Ramp_Dn_Percentage,Up_Time,Down_Time,Reg_Max,Rsv_Max,Reg_Cost,Rsv_Cost,MinCapTag_1,MinCapTag_2,MinCapTag_3
BUS1,1,z1_natural_gas,natural_gas,1,1,1,1,1,0,0,0,0,0,0,0,0.93,0,0,0,0,250,0,0,0,250,10,0,0,-1,0,-1,0,5,0,0,0,0,0.1,0,0,0,0.1,natural_gas,0.04,0,1,1,1,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0
BUS2,1,z2_natural_gas,natural_gas,1,2,2,1,1,0,0,0,0,0,0,0,0.93,0,0,0,0,300,0,0,0,300,10,0,0,-1,0,-1,0,1.2,0,0,0,0,0.1,0,0,0,0.1,natural_gas,0.033333333,0,1,1,1,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0
BUS3,1,z3_natural_gas,natural_gas,1,3,3,1,1,0,0,0,0,0,0,0,0.93,0,0,0,0,270,0,0,0,270,10,0,0,-1,0,-1,0,1,0,0,0,0,0.1,0,0,0,0.1,natural_gas,0.037037037,0,1,1,1,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0
3 changes: 3 additions & 0 deletions test/DCOPF/Generators_variability.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Time_Index,z1_natural_gas,z2_natural_gas,z3_natural_gas
0,1,1,1
1,1,1,1
5 changes: 5 additions & 0 deletions test/DCOPF/Load_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Voll,Demand_Segment,Cost_of_Demand_Curtailment_per_MW,Max_Demand_Curtailment,$/MWh,Rep_Periods,Timesteps_per_Rep_Period,Sub_Weights,Time_Index,Load_MW_z1,Load_MW_z2,Load_MW_z3,Load_MW_z4,Load_MW_z5,Load_MW_z6,Load_MW_z7,Load_MW_z8,Load_MW_z9
2000000,1,1,1,2000,1,1,1,1,0,0,0,0,90,0,100,0,125
,2,0.9,0.04,1800,,,,,,,,,,,,,
,3,0.55,0.024,1100,,,,,,,,,,,,,
,4,0.2,0.003,400,,,,,,,,,,,,,
10 changes: 10 additions & 0 deletions test/DCOPF/Network.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
,Network_zones,Network_Lines,z1,z2,z3,z4,z5,z6,z7,z8,z9,Line_Max_Flow_MW,transmission_path_name,distance_mile,Line_Loss_Percentage,Line_Max_Reinforcement_MW,Line_Reinforcement_Cost_per_MWyr,DerateCapRes_1,CapRes_1,CapRes_Excl_1,Angle_Limit_Deg,Line_Voltage_kV,Line_Resistance_ohms,Line_Reactance_ohms,Line_Impedance_ohms
BUS1,z1,1,1,0,0,-1,0,0,0,0,0,250,BUS1_to_BUS4,0.5,0.015,500,12000,0.95,0,0,45,345,0,68.5584,68.5584
BUS2,z2,2,0,0,0,1,-1,0,0,0,0,250,BUS4_to_BUS5,0.5,0.015,500,12000,0.95,0,0,45,345,20.23425,109.503,111.3567774
BUS3,z3,3,0,0,0,0,1,-1,0,0,0,150,BUS5_to_BUS6,0.5,0.015,500,12000,0.95,0,0,45,345,46.41975,202.3425,207.5988451
BUS4,z4,4,0,0,1,0,0,-1,0,0,0,300,BUS3_to_BUS6,0.5,0.015,500,12000,0.95,0,0,45,345,0,69.74865,69.74865
BUS5,z5,5,0,0,0,0,0,1,-1,0,0,150,BUS6_to_BUS7,0.5,0.015,500,12000,0.95,0,0,45,345,14.163975,119.9772,120.810375
BUS6,z6,6,0,0,0,0,0,0,1,-1,0,250,BUS7_to_BUS8,0.5,0.015,500,12000,0.95,0,0,45,345,10.117125,85.698,86.293125
BUS7,z7,7,0,-1,0,0,0,0,0,1,0,250,BUS8_to_BUS2,0.5,0.015,500,12000,0.95,0,0,45,345,0,74.390625,74.390625
BUS8,z8,8,0,0,0,0,0,0,0,1,-1,250,BUS8_to_BUS9,0.5,0.015,500,12000,0.95,0,0,45,345,38.088,191.63025,195.3787308
BUS9,z9,9,0,0,0,-1,0,0,0,0,1,250,BUS9_to_BUS4,0.5,0.015,500,12000,0.95,0,0,45,345,11.9025,101.17125,101.868991
11 changes: 11 additions & 0 deletions test/DCOPF/highs_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# HiGHS Solver Parameters
# Common solver settings
Feasib_Tol: 1.0e-05 # Primal feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
Optimal_Tol: 1.0e-05 # Dual feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
TimeLimit: 1.0e23 # Time limit # [type: double, advanced: false, range: [0, inf], default: inf]
Pre_Solve: choose # Presolve option: "off", "choose" or "on" # [type: string, advanced: false, default: "choose"]
Method: ipm #HiGHS-specific solver settings # Solver option: "simplex", "choose" or "ipm" # [type: string, advanced: false, default: "choose"]

# run the crossover routine for ipx
# [type: string, advanced: "on", range: {"off", "on"}, default: "off"]
run_crossover: "off"
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ end
@testset "Multi Stage" begin
include("test_multistage.jl")
end

@testset "DCOPF" begin
include("test_DCOPF.jl")
end
end
35 changes: 35 additions & 0 deletions test/test_DCOPF.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module TestDCOPF

using Test

include(joinpath(@__DIR__, "utilities.jl"))

obj_true = 395.171391
test_path = "DCOPF"

# Define test inputs
genx_setup = Dict(
"Trans_Loss_Segments" => 0,
"StorageLosses" => 0,
"DC_OPF" => 1,
)

# Run the case and get the objective value and tolerance
EP, _, _ = redirect_stdout(devnull) do
run_genx_case_testing(test_path, genx_setup)
end
obj_test = objective_value(EP)
optimal_tol_rel = get_attribute(EP, "ipm_optimality_tolerance")
optimal_tol = optimal_tol_rel * obj_test # Convert to absolute tolerance

# Test the objective value
test_result = @test obj_test obj_true atol = optimal_tol

println("obj_test: ", obj_test)

# Round objective value and tolerance. Write to test log.
obj_test = round_from_tol!(obj_test, optimal_tol)
optimal_tol = round_from_tol!(optimal_tol, optimal_tol)
write_testlog(test_path, obj_test, optimal_tol, test_result)

end # module TestDCOPF
14 changes: 9 additions & 5 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ Base.showerror(io::IO, e::CSVFileNotFound) = print(io, e.filefullpath, " not fou

function run_genx_case_testing(
test_path::AbstractString,
genx_setup::Dict,
test_setup::Dict,
optimizer::Any = HiGHS.Optimizer,
)
@assert genx_setup["MultiStage"] [0, 1]
# Merge the genx_setup with the default settings
settings = GenX.default_settings()
merge!(settings, test_setup)

@assert settings["MultiStage"] [0, 1]
# Create a ConsoleLogger that prints any log messages with level >= Warn to stderr
warnerror_logger = ConsoleLogger(stderr, Logging.Warn)

EP, inputs, OPTIMIZER = with_logger(warnerror_logger) do
if genx_setup["MultiStage"] == 0
run_genx_case_simple_testing(test_path, genx_setup, optimizer)
if settings["MultiStage"] == 0
run_genx_case_simple_testing(test_path, settings, optimizer)
else
run_genx_case_multistage_testing(test_path, genx_setup, optimizer)
run_genx_case_multistage_testing(test_path, settings, optimizer)
end
end
return EP, inputs, OPTIMIZER
Expand Down

0 comments on commit 3700340

Please sign in to comment.