You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using HydroPowerSimulations
using PowerSimulations
using PowerSystemCaseBuilder
using InfrastructureSystems
using StorageSystemsSimulations
using PowerSimulationsDecomposition
using PowerSystems
using PowerGraphics
#using Xpress
using HiGHS
using JuMP
using Logging
using Dates
using DataFrames
sys = build_system(PSISystems, "modified_RTS_GMLC_DA_sys")
sys2 = build_system(PSISystems, "modified_RTS_GMLC_DA_sys")
transform_single_time_series!(sys, Hour(NT), Hour(NT))
transform_single_time_series!(sys2, Hour(NT), Hour(NT))
#transform_single_time_series!(sys, Hour(1), Hour(1))
#transform_single_time_series!(sys2, Hour(1), Hour(1))
#enforced_region = ["1", "2", "3"] # first one is MRTO, second one is M2M coordinator, third one in RT is loopflow under M2M
enforced_region=["1","3","2"]
#enforced_region=["2","3","1"]
ptdf=PTDF(sys)
if use_monitoredline==0
set_device_model!(template_uc,
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),
))
else
set_device_model!(template_uc,
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),))
set_device_model!(template_uc, DeviceModel(MonitoredLine, StaticBranchUnbounded, use_slacks = true))
for b in monitoredlined_line
line = PSY.get_component(Line, sys, b)
PSY.convert_component!(sys, line, MonitoredLine)
end
if use_monitoredline==0
set_device_model!(template_uc2,
DeviceModel(Line, StaticBranch; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),))
l = PSY.get_component(ACBranch, sys2, "A28")
set_rating!(l,limit)
else
set_device_model!(template_uc2,
DeviceModel(Line, StaticBranchUnbounded; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),))
#set_device_model!(template_uc2, MonitoredLine, StaticBranch)
set_device_model!(template_uc2, DeviceModel(MonitoredLine, StaticBranch, use_slacks = true))
for b in monitoredlined_line
line = PSY.get_component(Line, sys2, b)
PSY.convert_component!(sys2, line, MonitoredLine)
end
l = PSY.get_component(MonitoredLine, sys2, "A28")
set_flow_limits!(l,(from_to=limit,to_from=limit))
end
models = SimulationModels(;
decision_models=[
DecisionModel(
template_uc,
sys;
name="UC0",
optimizer=optimizer_with_attributes(
HiGHS.Optimizer,
#Xpress.Optimizer,
#"MIPRELSTOP" => 0.00, # Set the relative mip gap tolerance
#"MAXMEMORYSOFT" => 600000, # Set the maximum amount of memory the solver can use (in MB)
),
system_to_file=false,
optimizer_solve_log_print=false,
direct_mode_optimizer=true,
store_variable_names=true,
calculate_conflict=true,
),
DecisionModel(
MultiRegionProblem,
template_uc2,
sys2;
name="UC_Subsystem",
optimizer=optimizer_with_attributes(
HiGHS.Optimizer,
#Xpress.Optimizer,
#"MIPRELSTOP" => 0.00, # Set the relative mip gap tolerance
#"MAXMEMORYSOFT" => 600000, # Set the maximum amount of memory the solver can use (in MB)
),
system_to_file=false,
initialize_model=true,
optimizer_solve_log_print=true,
direct_mode_optimizer=true,
rebuild_model=false,
store_variable_names=true,
calculate_conflict=true,
),
],
)
In the following code, HVDC variables are created and added to power balance in areaptdf model. But in areasplitptdf, HVDC variables are missing.
======
using Pkg
Pkg.activate(@DIR)
using Revise
#ENV["XPRESSDIR"] = "C:\xpressmp"
#ENV["XPAUTH_PATH"] = "C:\xpressmp\bin"
using HydroPowerSimulations
using PowerSimulations
using PowerSystemCaseBuilder
using InfrastructureSystems
using StorageSystemsSimulations
using PowerSimulationsDecomposition
using PowerSystems
using PowerGraphics
#using Xpress
using HiGHS
using JuMP
using Logging
using Dates
using DataFrames
#include("coordination_EnergyOnly.jl")
#include("GlobalM2M.jl")
#import StatsPlots
#import Plots
include("YC_test_function.jl")
#using Plots
#gr()
const PSY = PowerSystems
const IF = InfrastructureSystems
const PSB = PowerSystemCaseBuilder
NT=5
selected_line=["CA-1", "CB-1", "AB1"]
monitoredlined_line=["A28"]
limit=20
use_monitoredline=1
sys = build_system(PSISystems, "modified_RTS_GMLC_DA_sys")
sys2 = build_system(PSISystems, "modified_RTS_GMLC_DA_sys")
transform_single_time_series!(sys, Hour(NT), Hour(NT))
transform_single_time_series!(sys2, Hour(NT), Hour(NT))
#transform_single_time_series!(sys, Hour(1), Hour(1))
#transform_single_time_series!(sys2, Hour(1), Hour(1))
#enforced_region = ["1", "2", "3"] # first one is MRTO, second one is M2M coordinator, third one in RT is loopflow under M2M
enforced_region=["1","3","2"]
#enforced_region=["2","3","1"]
ptdf=PTDF(sys)
buildsubsystem(sys2, enforced_region, union(selected_line,monitoredlined_line))
exchange_1_2 = AreaInterchange(;
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "2"),
flow_limits=(from_to=99999, to_from=99999),
)
add_component!(sys, exchange_1_2)
exchange_1_3 = AreaInterchange(;
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "3"),
flow_limits=(from_to=99999, to_from=99999),
)
add_component!(sys, exchange_1_3)
exchange_2_3 = AreaInterchange(;
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "2"), to_area=get_component(Area, sys, "3"),
flow_limits=(from_to=99999, to_from=99999),
)
add_component!(sys, exchange_2_3)
exchange_1_2 = AreaInterchange(;
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "2"),
flow_limits=(from_to=99999, to_from=99999),
)
add_component!(sys2, exchange_1_2)
add_component_to_subsystem!(sys2, "a", exchange_1_2)
add_component_to_subsystem!(sys2, "b", exchange_1_2)
exchange_1_3 = AreaInterchange(;
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "3"),
flow_limits=(from_to=99999, to_from=99999),
)
add_component!(sys2, exchange_1_3)
add_component_to_subsystem!(sys2, "a", exchange_1_3)
add_component_to_subsystem!(sys2, "b", exchange_1_3)
exchange_2_3 = AreaInterchange(;
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "2"), to_area=get_component(Area, sys2, "3"),
flow_limits=(from_to=99999, to_from=99999),
)
add_component!(sys2, exchange_2_3)
add_component_to_subsystem!(sys2, "a", exchange_2_3)
add_component_to_subsystem!(sys2, "b", exchange_2_3)
template_uc = ProblemTemplate(NetworkModel(AreaPTDFPowerModel; use_slacks=true))
set_device_model!(template_uc, ThermalStandard, ThermalBasicUnitCommitment)
set_device_model!(template_uc, PowerLoad, StaticPowerLoad)
set_device_model!(template_uc, AreaInterchange, StaticBranch)
set_device_model!(template_uc, TwoTerminalHVDCLine, HVDCTwoTerminalLossless)
if use_monitoredline==0
set_device_model!(template_uc,
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),
))
else
set_device_model!(template_uc,
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),))
end
template_uc2 = MultiProblemTemplate(NetworkModel(SplitAreaPTDFPowerModel; use_slacks=true), ["a", "b"])
set_device_model!(template_uc2, AreaInterchange, StaticBranch)
set_device_model!(template_uc2, ThermalStandard, ThermalBasicUnitCommitment)
set_device_model!(template_uc2, PowerLoad, StaticPowerLoad)
set_device_model!(template_uc2, TwoTerminalHVDCLine, HVDCTwoTerminalLossless)
if use_monitoredline==0
set_device_model!(template_uc2,
DeviceModel(Line, StaticBranch; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),))
l = PSY.get_component(ACBranch, sys2, "A28")
set_rating!(l,limit)
else
set_device_model!(template_uc2,
DeviceModel(Line, StaticBranchUnbounded; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),))
end
models = SimulationModels(;
decision_models=[
DecisionModel(
template_uc,
sys;
name="UC0",
optimizer=optimizer_with_attributes(
HiGHS.Optimizer,
#Xpress.Optimizer,
#"MIPRELSTOP" => 0.00, # Set the relative mip gap tolerance
#"MAXMEMORYSOFT" => 600000, # Set the maximum amount of memory the solver can use (in MB)
),
system_to_file=false,
optimizer_solve_log_print=false,
direct_mode_optimizer=true,
store_variable_names=true,
calculate_conflict=true,
),
DecisionModel(
MultiRegionProblem,
template_uc2,
sys2;
name="UC_Subsystem",
optimizer=optimizer_with_attributes(
HiGHS.Optimizer,
#Xpress.Optimizer,
#"MIPRELSTOP" => 0.00, # Set the relative mip gap tolerance
#"MAXMEMORYSOFT" => 600000, # Set the maximum amount of memory the solver can use (in MB)
),
system_to_file=false,
initialize_model=true,
optimizer_solve_log_print=true,
direct_mode_optimizer=true,
rebuild_model=false,
store_variable_names=true,
calculate_conflict=true,
),
],
)
uc_simulation_ff = Vector{PowerSimulations.AbstractAffectFeedforward}()
FVFF_area_interchange = FixValueFeedforward(;component_type=AreaInterchange,source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],)
push!(uc_simulation_ff, FVFF_area_interchange)
#FVFF_moniterd_line = FixValueFeedforward(;
component_type=MonitoredLine, source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],
#)
#push!(uc_simulation_ff, FVFF_moniterd_line)
#FVFF_line = FixValueFeedforward(;
component_type=Line, source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],
#)
#push!(uc_simulation_ff, FVFF_line)
sequence = SimulationSequence(;
models=models,
feedforwards=Dict(
"UC_Subsystem" => uc_simulation_ff,
),
ini_cond_chronology=InterProblemChronology(),
);
sim = Simulation(;
name="sim",
steps=1,
models=models,
sequence=sequence,
initial_time=DateTime("2020-01-01T00:00:00"),
simulation_folder=mktempdir(),
);
build_out = build!(sim; console_level=Logging.Info, serialize=false)
execute_status = execute!(sim; enable_progress_bar=true);
uc0=models.decision_models[1].internal.container
uc2b=models.decision_models[2].internal.container.subproblems["b"]
uc2a=models.decision_models[2].internal.container.subproblems["a"]
#=
julia> uc0.constraints[PowerSimulations.ConstraintKey{LineFlowBoundConstraint, AreaInterchange}("lb")]["1_3",1]
-FlowActivePowerVariable_Line_{CA-1, 1} - FlowActivePowerVariable_AreaInterchange_{1_3, 1} + FlowActivePowerVariable_TwoTerminalHVDCLine_{DC1, 1} ≥ 0
julia> uc2a.constraints[PowerSimulations.ConstraintKey{LineFlowBoundConstraint, AreaInterchange}("lb")]["1_3",1]
-FlowActivePowerVariable_Line_{CA-1, 1} - FlowActivePowerVariable_AreaInterchange_{1_3, 1} ≥ 0
julia> for (k,v) in uc2a.variables
println(k)
end
InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, MonitoredLine}("")
InfrastructureSystems.Optimization.VariableKey{FlowActivePowerSlackLowerBound, MonitoredLine}("")
InfrastructureSystems.Optimization.VariableKey{SystemBalanceSlackDown, Area}("")
InfrastructureSystems.Optimization.VariableKey{OnVariable, ThermalStandard}("")
InfrastructureSystems.Optimization.VariableKey{StopVariable, ThermalStandard}("")
InfrastructureSystems.Optimization.VariableKey{SystemBalanceSlackUp, Area}("")
InfrastructureSystems.Optimization.VariableKey{FlowActivePowerSlackUpperBound, MonitoredLine}("")
InfrastructureSystems.Optimization.VariableKey{ActivePowerVariable, ThermalStandard}("")
InfrastructureSystems.Optimization.VariableKey{StartVariable, ThermalStandard}("")
InfrastructureSystems.Optimization.VariableKey{PowerSimulations.PieceWiseLinearCostVariable, ThermalStandard}("")
InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")
InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, Line}("")
=#
The text was updated successfully, but these errors were encountered: