-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeterministicProblem.jl
More file actions
181 lines (158 loc) · 5.88 KB
/
DeterministicProblem.jl
File metadata and controls
181 lines (158 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# To run: julia --project DeterministicProblem.jl true true true true true true
include("src/Unit_commitment.jl")
plotlyjs()
## Local
using Xpress
solver = optimizer_with_attributes(Xpress.Optimizer, "MIPRELSTOP" => 0.01) # MIPRELSTOP was 0.0001
## Eagle
# using Gurobi
# solver = optimizer_with_attributes(Gurobi.Optimizer, "MIPGap" => 0.01)
use_storage = isempty(ARGS) ? true : parse(Bool, ARGS[1])
use_storage_reserves = isempty(ARGS) ? true : parse(Bool, ARGS[2])
use_solar_reg = isempty(ARGS) ? true : parse(Bool, ARGS[3])
use_solar_spin = isempty(ARGS) ? true : parse(Bool, ARGS[4])
use_must_run = isempty(ARGS) ? true : parse(Bool, ARGS[5])
use_nuclear = isempty(ARGS) ? true : parse(Bool, ARGS[6])
scenarios = 31
## Jose
# system_file_path = "/Users/jdlara/cache/blue_texas/"
## Kate
system_file_path = "data/"
system_da = System(
joinpath(system_file_path, "DA_sys_" * string(scenarios) * "_scenarios.json");
time_series_read_only = true,
)
template_dauc = OperationsProblemTemplate(CopperPlatePowerModel)
set_device_model!(template_dauc, RenewableDispatch, RenewableFullDispatch)
set_device_model!(template_dauc, PowerLoad, StaticPowerLoad)
# Use FixedOutput instead of HydroDispatchRunOfRiver to get consistent results because model might decide to curtail wind vs. hydro (same cost)
set_device_model!(template_dauc, HydroDispatch, FixedOutput)
set_service_model!(template_dauc, ServiceModel(VariableReserve{ReserveUp}, RangeReserve))
set_service_model!(template_dauc, ServiceModel(VariableReserve{ReserveDown}, RangeReserve))
set_device_model!(template_dauc, GenericBattery, BookKeepingwReservation)
set_device_model!(template_dauc, ThermalMultiStart, ThermalMultiStartUnitCommitment)
# ignore HA for now
# set_device_model!(template_ed, ThermalMultiStart, ThermalRampLimited)
optional_title =
(use_storage ? " stor" : "") *
(use_storage_reserves ? " storres" : "") *
(use_solar_reg ? " solreg" : "") *
(use_solar_spin ? " solspin" : "")
scenario_plot_dict = Dict{String, Vector{Int64}}(
"2018-03-15T00:00:00" => [30, 29],
"2018-03-27T00:00:00" => [31, 13],
"2018-04-15T00:00:00" => [27, 30],
"2018-05-17T00:00:00" => [31, 19],
"2018-07-22T00:00:00" => [1, 5],
"2018-07-24T00:00:00" => [30, 13],
"2018-08-15T00:00:00" => [3, 29],
"2018-09-21T00:00:00" => [28, 23],
"2018-09-24T00:00:00" => [28, 14],
"2018-10-08T00:00:00" => [31, 23],
"2018-11-09T00:00:00" => [3, 18],
"2018-12-07T00:00:00" => [3, 24],
"2018-12-26T00:00:00" => [25, 13],
)
# days_per_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
# for month in 1:12
# for d in 1:days_per_month[month]
# initial_time = "2018-" * (month < 10 ? "0" * string(month) : string(month)) *
# "-" * string(d) * "T00:00:00"
# Solve the DAY BEFORE to get initial conditions
for initial_time in keys(scenario_plot_dict)
output_path =
"./results/" *
string(scenarios) *
" scenarios/Deterministic/" *
split(initial_time, "T")[1] *
optional_title *
"/"
# if !isdir(output_path)
# mkpath(output_path)
# end
apply_manual_data_updates!(
system_da,
use_nuclear,
joinpath(system_file_path, "initial_on_" * split(initial_time, "T")[1] * ".csv"),
)
UC = OperationsProblem(
BasecaseUnitCommitmentCC,
template_dauc,
system_da,
optimizer = solver,
initial_time = DateTime(initial_time) - Day(1),
optimizer_log_print = true,
balance_slack_variables = false,
)
UC.ext["cc_restrictions"] =
JSON.parsefile(joinpath(system_file_path, "cc_restrictions.json"))
UC.ext["use_storage"] = use_storage
UC.ext["use_storage_reserves"] = use_storage_reserves
UC.ext["storage_reserve_names"] = ["EXPOSE_STORAGE"]
UC.ext["use_wind_reserves"] = false
UC.ext["use_solar_reg"] = use_solar_reg
UC.ext["use_solar_spin"] = use_solar_spin
UC.ext["use_reg"] = true
UC.ext["use_spin"] = true
UC.ext["use_must_run"] = use_must_run
UC.ext["C_res_penalty"] = 5000 * get_base_power(system_da)
UC.ext["C_ener_penalty"] = 9000 * get_base_power(system_da)
UC.ext["L_REG"] = 1 / 12 # 5 min
UC.ext["L_SPIN"] = 1 / 6 # 10 min
UC.ext["load_scale"] = 1
UC.ext["solar_scale"] = 1
UC.ext["storage_scale"] = 1
UC.ext["solar_reg_prop"] = 1
UC.ext["wind_reg_prop"] = 1
UC.ext["solar_spin_prop"] = 1
UC.ext["wind_spin_prop"] = 1
UC.ext["renewable_reg_prop"] = 1
UC.ext["renewable_spin_prop"] = 1
UC.ext["supp_type"] = "generic"
UC.ext["allowable_reserve_prop"] = 0.2 # Can use up to 20% total for all reserves
# Build and solve the standalone problem
build!(UC; output_dir = output_path, serialize = false) # Can add balance_slack_variables (load shedding and curtailment), use serialize=true to get OptimizationModel.json to debug
(status, solvetime) = @timed solve!(UC)
if status.value == 0
hour = 24
print(initial_time * " solved")
save_as_initial_condition(
UC,
joinpath(
system_file_path,
"initial_on_" * split(initial_time, "T")[1] * ".csv",
),
hour,
)
# write_to_CSV(
# UC,
# system_file_path,
# output_path;
# time=solvetime
# )
# plot_fuel(
# UC;
# save_dir = output_path,
# scenario = nothing
# )
# plot_reserve(
# UC,
# "REG_UP";
# save_dir = output_path,
# scenario = nothing
# )
# plot_reserve(
# UC,
# "REG_DN";
# save_dir = output_path,
# scenario = nothing
# )
# plot_reserve(
# UC,
# "SPIN";
# save_dir = output_path,
# scenario = nothing
# )
end
# end
end