Skip to content

Commit

Permalink
format compat
Browse files Browse the repository at this point in the history
  • Loading branch information
harshangrjn committed Sep 12, 2024
1 parent ea598d8 commit 2f1c91f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 1 addition & 2 deletions examples/run_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ data_dict, augment_budget = data_I(num_nodes, instance)
# data_dict, augment_budget = data_SLAM("CSAIL") # "CSAIL", "intel", "ais2klinik"
# data_dict, augment_budget = data_II()

params = Dict{String,Any}("data_dict" => data_dict,
"augment_budget" => augment_budget)
params = Dict{String,Any}("data_dict" => data_dict, "augment_budget" => augment_budget)

#----------------------------------------------------------------#
# Optimization model and visualize solution (optional) #
Expand Down
6 changes: 4 additions & 2 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@ function constraint_cheeger_cuts(
lom::LaplacianOptModel,
optimizer::MOI.OptimizerWithAttributes,
)

ac_lower_bound = floor(lom.options.best_lower_bound, digits = 3)

if isapprox(ac_lower_bound, 0, atol = 1E-4)
Memento.info(_LOGGER,"Cheeger cuts may be ineffective: best λ₂ lower bound is approximately 0.")
Memento.info(
_LOGGER,
"Cheeger cuts may be ineffective: best λ₂ lower bound is approximately 0.",
)
return
end

Expand Down
20 changes: 13 additions & 7 deletions src/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,15 @@ function cheeger_constant(
JuMP.@variable(m_cheeger, 0 <= cheeger <= cheeger_ub)
JuMP.@variable(m_cheeger, cheeger_z[1:num_nodes] >= 0)

if formulation_type == "set_cardinality"
if formulation_type == "set_cardinality"
JuMP.@constraint(m_cheeger, sum(z) >= 1)
JuMP.@constraint(m_cheeger, sum(z) <= floor(num_nodes / 2))

JuMP.@constraint(
m_cheeger,
sum(cheeger_z) >= sum(
G[i, j] * (z[i] + z[j] - 2*Z[i, j]) for i in 1:(num_nodes-1), j in (i+1):num_nodes if
G[i, j] * (z[i] + z[j] - 2 * Z[i, j]) for
i in 1:(num_nodes-1), j in (i+1):num_nodes if
!(isapprox(G[i, j], 0, atol = 1E-5))
)
)
Expand All @@ -203,20 +204,24 @@ function cheeger_constant(
laplacian = LOpt.laplacian_matrix(float(G .> 0))
k_vol_ub = sum(G .> 0) / 2 #|E|
JuMP.@constraint(m_cheeger, sum(z[i] * laplacian[i, i] for i in 1:num_nodes) >= 1)
JuMP.@constraint(m_cheeger, sum(z[i] * laplacian[i, i] for i in 1:num_nodes) <= k_vol_ub)
JuMP.@constraint(
m_cheeger,
sum(z[i] * laplacian[i, i] for i in 1:num_nodes) <= k_vol_ub
)

JuMP.@constraint(
m_cheeger,
sum(cheeger_z[i] * laplacian[i, i] for i in 1:num_nodes) >= sum(
G[i, j] * (z[i] + z[j] - 2*Z[i, j]) for i in 1:(num_nodes-1), j in (i+1):num_nodes if
G[i, j] * (z[i] + z[j] - 2 * Z[i, j]) for
i in 1:(num_nodes-1), j in (i+1):num_nodes if
!(isapprox(G[i, j], 0, atol = 1E-5))
)
)
end

for i = 1:(num_nodes-1), j = (i+1):num_nodes
for i in 1:(num_nodes-1), j in (i+1):num_nodes
if !(isapprox(G[i, j], 0, atol = 1E-5))
LOpt.relaxation_bilinear(m_cheeger, Z[i,j], z[i], z[j])
LOpt.relaxation_bilinear(m_cheeger, Z[i, j], z[i], z[j])
end
end

Expand All @@ -236,7 +241,8 @@ function cheeger_constant(
result_cheeger["termination_status"] = JuMP.termination_status(m_cheeger)
result_cheeger["optimality_gap_percent"] = 100 * JuMP.relative_gap(m_cheeger)

(length(result_cheeger["S"]) == 0) && (Memento.error(_LOGGER, "Cheeger set cardinality cannot be zero."))
(length(result_cheeger["S"]) == 0) &&
(Memento.error(_LOGGER, "Cheeger set cardinality cannot be zero."))
return result_cheeger
end

Expand Down

0 comments on commit 2f1c91f

Please sign in to comment.