Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove second SDP relaxation in OPF tutorial due to unreliable numerics. #3432

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 7 additions & 75 deletions docs/src/tutorials/applications/optimal_power_flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,10 @@ better_lower_bound
E(k, n) = SparseArrays.sparse([k], [n], 1, N, N);

# Of course, we've shifted the nonlinearity into the equality constraint
# ``W = V V^*``: it is this constraint we will now relax using two different
# semidefinite programming approaches, one with the complex voltage variables
# ``V`` and the other one without.
# ``W = V V^*``: it is this constraint we will now relax using a
# semidefinite programming approach.

# ### ``W`` and ``V`` relaxation

# In the first instance, we will make use of complex voltages and relax
# We will make use of complex voltages and relax
# ``W = V V^*`` to;
# ```math
# W \succeq V V^*,
Expand Down Expand Up @@ -419,12 +416,12 @@ optimize!(model)

#-

first_relaxation_lower_bound = round(objective_value(model); digits = 2)
sdp_relaxation_lower_bound = round(objective_value(model); digits = 2)
Test.@test termination_status(model) in (OPTIMAL, ALMOST_OPTIMAL) #src
Test.@test primal_status(model) in (FEASIBLE_POINT, NEARLY_FEASIBLE_POINT) #src
Test.@test isapprox(first_relaxation_lower_bound, 2753.04; rtol = 1e-3) #src
Test.@test isapprox(sdp_relaxation_lower_bound, 2753.04; rtol = 1e-3) #src
println(
"Objective value (W & V relax. lower bound): $first_relaxation_lower_bound",
"Objective value (W & V relax. lower bound): $sdp_relaxation_lower_bound",
)

# We can more easily see solution values by rounding out noisy data:
Expand All @@ -441,75 +438,10 @@ DataFrames.DataFrame(;

# For further information on exploiting sparsity see Jabr (2012).

# ### ``W`` only relaxation

# In the second instance, we will relax ``W = V V^*`` to
# ```math
# W \succeq 0
# ```
# where we now introduce ``W`` as a new Hermitian matrix of decision variables.
# This enables us to write down a relaxation without complex voltage variables.

# With this modification we get the following semidefinite relaxation of the
# AC-OPF problem:

model = Model(Clarabel.Optimizer)
set_attribute(model, "tol_gap_rel", 0.01)
@variable(
model,
S_G[i in 1:N] in ComplexPlane(),
lower_bound = P_Gen_lb[i] + Q_Gen_lb[i] * im,
upper_bound = P_Gen_ub[i] + Q_Gen_ub[i] * im,
)
@variable(model, W[1:N, 1:N] in HermitianPSDCone())
@constraint(model, [i in 1:N], 0.9^2 <= real(W[i, i]) <= 1.1^2)
@constraint(
model,
[i in 1:N],
S_G[i] - S_Demand[i] == LinearAlgebra.tr((conj(Y) * E(i, i)) * W),
)
P_G = real(S_G)
@objective(
model,
Min,
(0.11 * P_G[1]^2 + 5 * P_G[1] + 150) +
(0.085 * P_G[2]^2 + 1.2 * P_G[2] + 600) +
(0.1225 * P_G[3]^2 + P_G[3] + 335),
)
optimize!(model)

#-

second_relaxation_lower_bound = round(objective_value(model); digits = 2)
println(
"Objective value (W relax. lower bound): $second_relaxation_lower_bound",
)

Test.@test termination_status(model) in (OPTIMAL, ALMOST_OPTIMAL) #src
Test.@test primal_status(model) in (FEASIBLE_POINT, NEARLY_FEASIBLE_POINT) #src
Test.@test isapprox(second_relaxation_lower_bound, 2753.04; rtol = 1e-3) #src

# We can more easily see the solution by filtering out the noisy data
# arising from solver tolerances:

W_2 = SparseArrays.sparse(round.(value.(W); digits = 1))
Test.@test iszero(imag(LinearAlgebra.diag(W_2))) #src

# with corresponding voltage magnitude estimates:

DataFrames.DataFrame(;
Bus = 1:N,
Magnitude = round.(real.(sqrt.(LinearAlgebra.diag(W_2))); digits = 2),
)

# The first relaxation has the advantage that we can work directly with complex
# This relaxation has the advantage that we can work directly with complex
# voltages to extend the formulation, strengthen the relaxation and gain
# additional approximate information about the voltage variables.

# The second relaxation has the advantage of compactness in variables and
# constraints while giving the same objective lower bound as the first
# relaxation.

# ## References and further resources

# **Bukhsh**, W. A., Grothey, A., McKinnon, K. I., & Trodden, P. A.
Expand Down
Loading