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 unnecessary Alp module reference #247

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion src/Alpine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import LinearAlgebra: dot, Diagonal
import Statistics

const ALPINE_DEBUG = false
const Alp = Alpine

include("const.jl")

Expand Down
12 changes: 6 additions & 6 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
bound_sol_pool::Dict{Any,Any} # A pool of solutions from solving model_mip

# Linking constraints info for Multilinear terms
linking_constraints_info::Union{Nothing,Dict{Any,Any}} # Stored multilinear linking constraints info
linking_constraints_info::Union{Nothing,Dict{Any,Any}} # Stored multilinear linking constraints info

# Logging information and status
logs::Dict{Symbol,Any} # Logging information
Expand All @@ -108,7 +108,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
# Constructor for Alpine.Optimizer
function Optimizer()
m = new()
m.options = Alp.get_default_options()
m.options = get_default_options()
MOI.empty!(m)
return m
end
Expand Down Expand Up @@ -254,10 +254,10 @@ MOI.get(::Optimizer, ::MOI.SolverName) = "Alpine"
MOI.get(::Optimizer, ::MOI.SolverVersion) = _ALPINE_VERSION

function MOI.set(model::Optimizer, param::MOI.RawOptimizerAttribute, value)
return Alp.set_option(model, Symbol(param.name), value)
return set_option(model, Symbol(param.name), value)
end
function MOI.get(model::Optimizer, param::MOI.RawOptimizerAttribute)
return Alp.get_option(model, Symbol(param.name))
return get_option(model, Symbol(param.name))
end

function MOI.add_variables(model::Optimizer, n::Int)
Expand Down Expand Up @@ -395,10 +395,10 @@ is_max_sense(model::Optimizer) = model.sense_orig == MOI.MAX_SENSE

function MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense)
model.sense_orig = sense
if Alp.is_max_sense(model)
if is_max_sense(model)
model.best_obj = -Inf
model.best_bound = Inf
elseif Alp.is_min_sense(model)
elseif is_min_sense(model)
model.best_obj = Inf
model.best_bound = -Inf
else
Expand Down
125 changes: 61 additions & 64 deletions src/bounding_model.jl

Large diffs are not rendered by default.

21 changes: 7 additions & 14 deletions src/embedding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
function embedding_map(λCnt::Int, encoding::Any = ebd_gray, ibs::Bool = false)
map = Dict()

encoding = Alp.resolve_encoding_key(encoding)
encoding = resolve_encoding_key(encoding)
L = Int(ceil(log(2, λCnt - 1)))
for i in 1:L*2
map[i] = Set()
end
H = [encoding(i, L) for i in 0:max(1, (2^L - 1))]
map[:H_orig] = H
map[:H] = [Alp.ebd_support_binary_vec(H[i]) for i in 1:length(H)] # Store the map
map[:H] = [ebd_support_binary_vec(H[i]) for i in 1:length(H)] # Store the map
map[:L] = L

!is_compatible_encoding(H) && error("Encodign method is not SOS-2 compatible...")
Expand Down Expand Up @@ -57,7 +57,7 @@ end
This function is the same σ() function described in Vielma and Nemhauser 2011.
"""
function ebd_σ(b::String)
sv = Alp.ebd_support_bool_vec(b)
sv = ebd_support_bool_vec(b)
return [i for i in 1:length(sv) if sv[i]]
end

Expand All @@ -82,10 +82,7 @@ end
function is_compatible_encoding(code_seq::Vector)
for i in 1:(length(code_seq)-1)
sum(
abs.(
Alp.ebd_support_bool_vec(code_seq[i]) -
Alp.ebd_support_bool_vec(code_seq[i+1])
),
abs.(ebd_support_bool_vec(code_seq[i]) - ebd_support_bool_vec(code_seq[i+1])),
) != 1 && return false
end
return true
Expand Down Expand Up @@ -132,8 +129,8 @@ function ebd_link_xα(

# Expression expansion
for i in 1:P
code_vec = Alp.ebd_support_bool_vec(code_seq[i])
lifters, exprs = Alp.ebd_link_expression(code_vec, lifters, exprs, i)
code_vec = ebd_support_bool_vec(code_seq[i])
lifters, exprs = ebd_link_expression(code_vec, lifters, exprs, i)
end

# Construct Variable Vector
Expand All @@ -145,11 +142,7 @@ function ebd_link_xα(
base_name = "αA$(var_idx)"
)
for i in keys(lifters) # Build first-level evaluation
Alp.relaxation_multilinear_binary(
m.model_mip,
α_A[lifters[i]-L],
[α[j] for j in i],
)
relaxation_multilinear_binary(m.model_mip, α_A[lifters[i]-L], [α[j] for j in i])
end

α_R = [α; α_A] # Initialize/re-arrgange the variable sequence
Expand Down
4 changes: 2 additions & 2 deletions src/heuristics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function update_disc_cont_var(m::Optimizer)
(var_diffs = _eval_var_diffs!(m.nonconvex_terms, var_diffs))

distance = Dict(zip(var_idxs, var_diffs))
Alp.weighted_min_vertex_cover(m, distance)
weighted_min_vertex_cover(m, distance)

(Alp.get_option(m, :log_level) > 100) &&
(get_option(m, :log_level) > 100) &&
println("updated partition var selection => $(m.disc_vars)")
return
end
Expand Down
77 changes: 35 additions & 42 deletions src/log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function create_logs!(m)
# Timers
logs[:presolve_time] = 0.0 # Total presolve-time of the algorithm
logs[:total_time] = 0.0 # Total run-time of the algorithm
logs[:time_left] = Alp.get_option(m, :time_limit) # Total remaining time of the algorithm if time-out is specified
logs[:time_left] = get_option(m, :time_limit) # Total remaining time of the algorithm if time-out is specified

# Values
logs[:obj] = [] # Iteration-based objective
Expand All @@ -23,15 +23,15 @@ end

function reset_timer(m::Optimizer)
m.logs[:total_time] = 0.0
m.logs[:time_left] = Alp.get_option(m, :time_limit)
m.logs[:time_left] = get_option(m, :time_limit)
return m
end

function logging_summary(m::Optimizer)
if Alp.get_option(m, :log_level) > 0
if get_option(m, :log_level) > 0
printstyled("\nPROBLEM STATISTICS\n", color = :cyan, bold = true)
Alp.is_min_sense(m) && (println(" Objective sense = Min"))
Alp.is_max_sense(m) && (println(" Objective sense = Max"))
is_min_sense(m) && (println(" Objective sense = Min"))
is_max_sense(m) && (println(" Objective sense = Max"))
println(
" # Variables = ",
length([i for i in 1:m.num_var_orig if m.var_type[i] == :Cont]) +
Expand All @@ -45,7 +45,7 @@ function logging_summary(m::Optimizer)
println(" # Constraints = ", m.num_constr_orig)
println(" # NL Constraints = ", m.num_nlconstr_orig)
println(" # Linear Constraints = ", m.num_lconstr_orig)
Alp.get_option(m, :recognize_convex) && println(
get_option(m, :recognize_convex) && println(
" # Detected convex constraints = $(length([i for i in m.constr_structure if i == :convex]))",
)
println(" # Detected nonlinear terms = ", length(m.nonconvex_terms))
Expand All @@ -56,7 +56,7 @@ function logging_summary(m::Optimizer)
println(" # Potential variables for partitioning = ", length(m.disc_vars))

printstyled("SUB-SOLVERS USED BY ALPINE\n", color = :cyan, bold = true)
if Alp.get_option(m, :minlp_solver) === nothing
if get_option(m, :minlp_solver) === nothing
println(" NLP local solver = ", m.nlp_solver_id)
else
println(" MINLP local solver = ", m.minlp_solver_id)
Expand All @@ -70,63 +70,56 @@ function logging_summary(m::Optimizer)
if Alp.is_min_sense(m)
odow marked this conversation as resolved.
Show resolved Hide resolved
println(
" Maximum iterations (lower-bounding MIPs) = ",
Alp.get_option(m, :max_iter),
get_option(m, :max_iter),
)
elseif Alp.is_max_sense(m)
elseif is_max_sense(m)
println(
" Maximum iterations (upper-bounding MIPs) = ",
Alp.get_option(m, :max_iter),
get_option(m, :max_iter),
)
else
println(
" Maximum iterations (bounding MIPs) = ",
Alp.get_option(m, :max_iter),
)
println(" Maximum iterations (bounding MIPs) = ", get_option(m, :max_iter))
end

println(
" Relative global optimality gap = ",
Alp.get_option(m, :rel_gap) * 100,
"%",
)
println(" Relative global optimality gap = ", get_option(m, :rel_gap) * 100, "%")

if Alp.get_option(m, :disc_var_pick) == 0
if get_option(m, :disc_var_pick) == 0
println(" Potential variables chosen for partitioning = All")
elseif Alp.get_option(m, :disc_var_pick) == 1
elseif get_option(m, :disc_var_pick) == 1
println(
" Potential variables chosen for partitioning = Minimum vertex cover",
)
end

if Alp.get_option(m, :partition_scaling_factor_branch)
if get_option(m, :partition_scaling_factor_branch)
println(" Partition scaling factor branch activated")
else
println(
" Partition scaling factor = ",
Alp.get_option(m, :partition_scaling_factor),
get_option(m, :partition_scaling_factor),
)
end
(Alp.get_option(m, :convhull_ebd)) && println(" Using convhull_ebd formulation")
(Alp.get_option(m, :convhull_ebd)) &&
println(" Encoding method = $(Alp.get_option(m, :convhull_ebd_encode))")
(Alp.get_option(m, :convhull_ebd)) && println(
" Independent branching scheme = $(Alp.get_option(m, :convhull_ebd_ibs))",
(get_option(m, :convhull_ebd)) && println(" Using convhull_ebd formulation")
(get_option(m, :convhull_ebd)) &&
println(" Encoding method = $(get_option(m, :convhull_ebd_encode))")
(get_option(m, :convhull_ebd)) && println(
" Independent branching scheme = $(get_option(m, :convhull_ebd_ibs))",
)
println(" Bound-tightening presolve = ", Alp.get_option(m, :presolve_bt))
Alp.get_option(m, :presolve_bt) && println(
println(" Bound-tightening presolve = ", get_option(m, :presolve_bt))
get_option(m, :presolve_bt) && println(
" Maximum iterations (OBBT) = ",
Alp.get_option(m, :presolve_bt_max_iter),
get_option(m, :presolve_bt_max_iter),
)
end
end

function logging_head(m::Optimizer)
if Alp.is_min_sense(m)
if is_min_sense(m)
printstyled("LOWER-BOUNDING ITERATIONS", color = :cyan, bold = true)
UB_iter = "Incumbent"
UB = "Best Incumbent"
LB = "Lower Bound"
elseif Alp.is_max_sense(m)
elseif is_max_sense(m)
printstyled("UPPER-BOUNDING ITERATIONS", color = :cyan, bold = true)
UB_iter = "Incumbent"
UB = "Best Incumbent"
Expand Down Expand Up @@ -244,7 +237,7 @@ function summary_status(m::Optimizer)

if m.detected_bound && m.detected_incumbent
m.alpine_status =
m.best_rel_gap > Alp.get_option(m, :rel_gap) ? MOI.OTHER_LIMIT : MOI.OPTIMAL
m.best_rel_gap > get_option(m, :rel_gap) ? MOI.OTHER_LIMIT : MOI.OPTIMAL
elseif m.status[:bounding_solve] == MOI.INFEASIBLE
m.alpine_status = MOI.INFEASIBLE
elseif m.detected_bound && !m.detected_incumbent
Expand All @@ -267,11 +260,11 @@ end
# cnt = length([1 for j in keys(m.nonconvex_terms) if m.nonconvex_terms[j][:nonlinear_type] == i])
# cnt > 0 && println("\tTerm $(i) Count = $(cnt) ")
# end
# println(" Maximum solution time = ", Alp.get_option(m, :time_limit))
# println(" Basic bound propagation = ", Alp.get_option(m, :presolve_bp))
# println(" Conseuctive solution rejection = after ", Alp.get_option(m, :disc_consecutive_forbid), " times")
# Alp.get_option(m, :presolve_bt) && println("bound tightening presolve algorithm = ", Alp.get_option(m, :presolve_bt)_algo)
# Alp.get_option(m, :presolve_bt) && println("bound tightening presolve width tolerance = ", Alp.get_option(m, :presolve_bt)_width_tol)
# Alp.get_option(m, :presolve_bt) && println("bound tightening presolve output tolerance = ", Alp.get_option(m, :presolve_bt)_output_tol)
# Alp.get_option(m, :presolve_bt) && println("bound tightening presolve relaxation = ", Alp.get_option(m, :presolve_bt)_relax)
# Alp.get_option(m, :presolve_bt) && println("bound tightening presolve mip regulation time = ", Alp.get_option(m, :presolve_bt)_mip_time_limit)
# println(" Maximum solution time = ", get_option(m, :time_limit))
# println(" Basic bound propagation = ", get_option(m, :presolve_bp))
# println(" Conseuctive solution rejection = after ", get_option(m, :disc_consecutive_forbid), " times")
# get_option(m, :presolve_bt) && println("bound tightening presolve algorithm = ", get_option(m, :presolve_bt)_algo)
# get_option(m, :presolve_bt) && println("bound tightening presolve width tolerance = ", get_option(m, :presolve_bt)_width_tol)
# get_option(m, :presolve_bt) && println("bound tightening presolve output tolerance = ", get_option(m, :presolve_bt)_output_tol)
# get_option(m, :presolve_bt) && println("bound tightening presolve relaxation = ", get_option(m, :presolve_bt)_relax)
# get_option(m, :presolve_bt) && println("bound tightening presolve mip regulation time = ", get_option(m, :presolve_bt)_mip_time_limit)
Loading
Loading