Skip to content

Commit

Permalink
some clean up for eigen cuts
Browse files Browse the repository at this point in the history
  • Loading branch information
harshangrjn committed Aug 22, 2023
1 parent a0bd084 commit 0765b23
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ LaplacianOpt.jl Change Log
### v0.6.0
- Added mutiple heuristics to handle both spanning trees and graphs with loops
- Refactored `log.jl` to handle solutions from heuristics
- Included more used options for heuristic in `model_options`
- Included more user options for heuristic in `model_options`
- Cleaned up populating and logging of eigen cuts
- Updated docs and unit tests to reflect above changes

### v0.5.0
Expand Down
5 changes: 2 additions & 3 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ function constraint_lazycallback_wrapper(lom::LaplacianOptModel; optimizer = not
end

function constraint_eigen_cuts(W_val::Matrix{<:Number}, cb_cuts, lom::LaplacianOptModel)
if (size(lom.options.eigen_cuts_sizes)[1] > 0) &&
(minimum(lom.options.eigen_cuts_sizes) >= 2)
for cut_size in sort(unique(lom.options.eigen_cuts_sizes), rev = true)
if (length(keys(lom.minor_idx_dict)) > 0)
for cut_size in sort(collect(keys(lom.minor_idx_dict)), rev = true)
for i in lom.minor_idx_dict[cut_size]
LOpt._add_eigen_cut_lazy(W_val, cb_cuts, lom, collect(i))
end
Expand Down
14 changes: 5 additions & 9 deletions src/lopt_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ function build_LOModel(data::Dict{String,Any}; optimizer = nothing, options = no
end
end

LOpt._logging_info(lom)

if lom.options.formulation_type == "max_λ2"
if lom.options.solution_type == "heuristic"
LOpt._logging_info(lom)
return lom

elseif lom.options.solution_type == "optimal"
# Populate PMinor indices
lom.minor_idx_dict =
LOpt._PMinorIdx(lom.data["num_nodes"], lom.options.eigen_cuts_sizes)
LOpt._logging_info(lom)

LOpt.variable_LOModel(lom)
LOpt.constraint_LOModel(lom; optimizer = optimizer)
Expand Down Expand Up @@ -192,12 +192,8 @@ end

function _logging_info(lom::LaplacianOptModel)
if lom.options.solution_type == "optimal"
if (
size(lom.options.eigen_cuts_sizes)[1] > 0 &&
minimum(lom.options.eigen_cuts_sizes) >= 2 &&
maximum(lom.options.eigen_cuts_sizes) <= lom.data["num_nodes"]
)
for k in lom.options.eigen_cuts_sizes
if length(keys(lom.minor_idx_dict)) > 0
for k in keys(lom.minor_idx_dict)
Memento.info(_LOGGER, "Applying eigen cuts ($(k)x$(k) matrix)")
end
end
Expand All @@ -217,6 +213,6 @@ function _logging_info(lom::LaplacianOptModel)
Memento.info(_LOGGER, "Applying topology flow cuts")
end
elseif lom.options.solution_type == "heuristic"
Memento.info(_LOGGER, "Applying heuristics to obtain a lower bound")
Memento.info(_LOGGER, "Applying heuristics to obtain a feasible solution")
end
end
2 changes: 1 addition & 1 deletion src/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function build_LOModel_result(lom::LaplacianOptModel, solve_time::Number)
if status in [true, false]
result["optimality_certificate_MISDP"] = status
(status == false) &&
(Memento.warn(_LOGGER, "Optimality certificate for MISDP failed!!!"))
(Memento.warn(_LOGGER, "Optimality certificate for MISDP failed!"))
end
end

Expand Down
15 changes: 13 additions & 2 deletions src/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,19 @@ end

function _PMinorIdx(N::Int64, sizes::Vector{Int64})
minor_idx_dict = Dict{Int64,Vector{Tuple{Int64,Vararg{Int64}}}}()
for k in sizes
minor_idx_dict[k] = LOpt.get_minor_idx(N, k)

if length(sizes) > 0
if maximum(sizes) > N
Memento.warn(
_LOGGER,
"Detected maximum eigen-cut size ($(maximum(sizes))) > num_nodes",
)
end
for k in unique(sizes)
if (k >= 2) && (k <= N)
minor_idx_dict[k] = LOpt.get_minor_idx(N, k)
end
end
end

return minor_idx_dict
Expand Down

0 comments on commit 0765b23

Please sign in to comment.