Skip to content

Commit

Permalink
Implement additional plot for infeasibility
Browse files Browse the repository at this point in the history
  • Loading branch information
JannisHal committed Feb 2, 2024
1 parent 3fd332b commit a10470b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions examples/alm_sdp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ end

labels = ["Full", "Cyclic", "Stochastic"]

println(trajectories[1][1])

fp = plot_trajectories(
trajectories,
labels,
legend_position=:best,
xscalelog=true,
reduce_size=true,
marker_shapes=[:dtriangle, :rect, :circle, :dtriangle, :rect, :circle],
extra_plot=true,
extra_plot_label="infeasibility",
)

display(fp)
13 changes: 11 additions & 2 deletions examples/plot_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ function plot_trajectories(
primal_offset=1e-8,
line_width=1.3,
empty_marker=false,
extra_plot=false,
extra_plot_label="",
)
# theme(:dark)
# theme(:vibrant)
Expand Down Expand Up @@ -325,8 +327,15 @@ function plot_trajectories(
dit = sub_plot(1, 4; xlabel="Iterations", ylabel="FW gap")
dti = sub_plot(5, 4; xlabel="Time (s)")

fp = plot(pit, pti, dit, dti, layout=(2, 2)) # layout = @layout([A{0.01h}; [B C; D E]]))
plot!(size=(600, 400))
if extra_plot
iit = sub_plot(1, 6; ylabel=extra_plot_label)
iti = sub_plot(5, 6)
fp = plot(pit, pti, iit, iti, dit, dti, layout=(3, 2)) # layout = @layout([A{0.01h}; [B C; D E]]))
plot!(size=(600, 600))
else
fp = plot(pit, pti, dit, dti, layout=(2, 2)) # layout = @layout([A{0.01h}; [B C; D E]]))
plot!(size=(600, 400))
end
if filename !== nothing
savefig(fp, filename)
end
Expand Down
24 changes: 23 additions & 1 deletion src/alternating_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function alternating_linear_minimization(
x0::Tuple{Vararg{Any,N}};
lambda=1.0,
verbose=false,
trajectory=false,
callback=nothing,
print_iter=1e3,
kwargs...,
Expand All @@ -74,6 +75,21 @@ function alternating_linear_minimization(

f_bc(x) = sum(f(x.blocks[i]) for i in 1:N) + lambda * infeasibility(x)

infeasibilities = []
if trajectory
function make_infeasibitly_callback(callback)
return function callback_infeasibility(state, args...)
push!(infeasibilities, infeasibility(state.x))
if callback === nothing
return true
end
return callback(state, args...)
end
end

callback = make_infeasibitly_callback(callback)
end

if verbose
println("\nAlternating Linear Minimization (ALM).")
print("LAMBDA: $lambda")
Expand All @@ -97,12 +113,18 @@ function alternating_linear_minimization(
prod_lmo,
x0_bc;
verbose=verbose,
trajectory=trajectory,
callback=callback,
print_iter=print_iter,
kwargs...,
)

return x, v, primal, dual_gap, infeasibility(x), traj_data
if trajectory
traj_data = [(t...,infeasibilities[i]) for (i,t) in enumerate(traj_data)]
return x, v, primal, dual_gap, infeasibility(x), traj_data
else
return x, v, primal, dual_gap, infeasibility(x), traj_data
end
end


Expand Down

0 comments on commit a10470b

Please sign in to comment.