Skip to content

Commit

Permalink
Update solver and utility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 12, 2020
1 parent 3c5bb01 commit a097ca2
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 250 deletions.
2 changes: 1 addition & 1 deletion src/algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function set_variable_type(model::MOI.ModelLike, xs, variable_types)
fx = MOI.SingleVariable(x)
if variable_type == :Int
MOI.add_constraint(model, fx, MOI.Integer())
elseif variable_type == :Bool
elseif variable_type == :Bin
MOI.add_constraint(model, fx, MOI.ZeroOne())
else
@assert variable_type == :Cont
Expand Down
6 changes: 3 additions & 3 deletions src/amp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,15 @@ function disc_branch_solve(m::Optimizer)
# ================= Solve Start ================ #
set_mip_time_limit(m)
start_bounding_solve = time()
MOI.optimize!(m.model_mip)
JuMP.optimize!(m.model_mip)
status = MOI.get(m.model_mip, MOI.TerminationStatus())
cputime_branch_bounding_solve = time() - start_bounding_solve
m.logs[:total_time] += cputime_branch_bounding_solve
m.logs[:time_left] = max(0.0, get_option(m, :timeout) - m.logs[:total_time])
# ================= Solve End ================ #

if status in [:Optimal, :Suboptimal, :UserLimit]
return m.model_mip.objBound
if status in STATUS_OPT || status in STATUS_LIMIT
return MOI.get(m.model_mip, MOI.ObjectiveBound())
else
@warn " Warning: Unexpected solving condition $(status) during disc branching."
end
Expand Down
1 change: 0 additions & 1 deletion src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ function MOI.set(model::Optimizer, ::MOI.ObjectiveSense, sense)
else
error("Feasibility sense not supported yet by Alpine.")
end
@show model.best_bound
end

function MOI.set(model::Optimizer, ::MOI.ObjectiveFunction{F}, func::F) where F
Expand Down
4 changes: 2 additions & 2 deletions src/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,9 @@ function weighted_min_vertex_cover(m::Optimizer, distance::Dict)
@objective(minvertex, Min, sum(weights[i]*x[i] for i in nodes))

# Solve the minimum vertex cover
status = solve(minvertex, suppress_warnings=true)
JuMP.optimize!(minvertex)

xVal = getvalue(x)
xVal = JuMP.value.(x)
m.num_var_disc_mip = Int(sum(xVal))
m.disc_vars = [i for i in nodes if xVal[i] > 0 && abs(m.u_var_tight[i]-m.l_var_tight[i]) >= get_option(m, :tol)]
get_option(m, :loglevel) >= 99 && println("UPDATED DISC-VAR COUNT = $(length(m.disc_vars)) : $(m.disc_vars)")
Expand Down
2 changes: 1 addition & 1 deletion test/algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ end
"maxiter" => 1,
"presolve_bt" => false,
"loglevel" => 100)
m = convex_optimize!(solver=test_solver)
m = convex_solve(solver=test_solver)
JuMP.optimize!(m)
@test termination_status(m) == MOI.OPTIMAL
end
Expand Down
8 changes: 0 additions & 8 deletions test/expression.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
function _build(model::JuMP.Model)
MOI.set(model, MOI.NLPBlock(), JuMP._create_nlp_block_data(model))
MOI.Utilities.attach_optimizer(model)
alpine = JuMP.backend(model).optimizer.model
Alpine.load!(alpine)
return alpine
end

@testset "Expression Parsing || bilinear || Affine || exprs.jl" begin

test_solver = optimizer_with_attributes(Alpine.Optimizer,"nlp_solver" => IPOPT_SB,"mip_solver" => CBC,"loglevel" => 100)
Expand Down
14 changes: 9 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ const CBC = optimizer_with_attributes(Cbc.Optimizer, MOI.Silent() => true)
const JUNIPER = optimizer_with_attributes(Juniper.Optimizer, MOI.Silent() => true, "mip_solver" => CBC, "nl_solver" => IPOPT_SB)
const PAVITO = optimizer_with_attributes(Pavito.Optimizer, "mip_solver" => CBC, "cont_solver" => IPOPT_SB, "mip_solver_drives" => false)



#pavito_solver=PavitoSolver(mip_solver=CbcSolver(logLevel=0), cont_solver=IpoptSolver(print_level=0, sb="yes"), mip_solver_drives=false, log_level=0)
function _build(model::JuMP.Model)
MOI.set(model, MOI.NLPBlock(), JuMP._create_nlp_block_data(model))
MOI.Utilities.attach_optimizer(model)
alpine = JuMP.backend(model).optimizer.model
Alpine.load!(alpine)
return alpine
end

# Perform Tests
#include("$(alpine_dir)/test/solver.jl")
include("$(alpine_dir)/test/solver.jl")
include("$(alpine_dir)/test/expression.jl")
include("$(alpine_dir)/test/algorithm.jl")
#include("$(alpine_dir)/test/utility.jl")
include("$(alpine_dir)/test/utility.jl")
Loading

0 comments on commit a097ca2

Please sign in to comment.