Skip to content

Commit

Permalink
Allow continuous solvers to solve relaxations of MIPs
Browse files Browse the repository at this point in the history
  • Loading branch information
joehuchette committed Aug 6, 2016
1 parent 1bd4ab2 commit 6e92de8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/solvers.jl
Expand Up @@ -26,8 +26,8 @@ type ProblemTraits
sos::Bool # has an SOS constraint
conic::Bool # has an SDP or SOC constraint
end
function ProblemTraits(m::Model)
int = any(c-> !(c == :Cont || c == :Fixed), m.colCat)
function ProblemTraits(m::Model; relaxation=false)
int = !relaxation && any(c-> !(c == :Cont || c == :Fixed), m.colCat)
qp = !isempty(m.obj.qvars1)
qc = !isempty(m.quadconstr)
nlp = m.nlpdata !== nothing
Expand Down Expand Up @@ -128,10 +128,10 @@ function solve(m::Model; suppress_warnings=false,
unset = m.solver == UnsetSolver()

# Analyze the problems traits to determine what solvers we can use
traits = ProblemTraits(m)
traits = ProblemTraits(m, relaxation=relaxation)

# Build the MathProgBase model from the JuMP model
build(m, traits, suppress_warnings=suppress_warnings, relaxation=relaxation)
build(m, traits=traits, suppress_warnings=suppress_warnings, relaxation=relaxation)

# If the model is a general nonlinear, use different logic in
# nlp.jl to solve the problem
Expand Down Expand Up @@ -303,8 +303,7 @@ end

# Converts the JuMP Model into a MathProgBase model based on the
# traits of the model
function build(m::Model, traits=ProblemTraits(m);
suppress_warnings=false, relaxation=false)
function build(m::Model; suppress_warnings=false, relaxation=false, traits=ProblemTraits(m,relaxation=relaxation))
# Set solver based on the model's traits if it hasn't provided
if isa(m.solver, UnsetSolver)
m.solver = default_solver(traits)
Expand Down
21 changes: 21 additions & 0 deletions test/model.jl
Expand Up @@ -890,3 +890,24 @@ facts("[model] Unrecognized keyword argument to solve") do
m = Model()
@fact_throws solve(m, this_should_throw=true)
end

facts("[model] Solve MIP relaxation with continuous solvers") do
for solver in lp_solvers
context("With solver $(typeof(solver))") do
m = Model(solver=solver)
@variable(m, x, Bin)
@constraint(m, x >= 0.5)
@objective(m, Min, x)
@fact solve(m, relaxation=true) --> :Optimal
@fact getvalue(x) --> roughly(0.5, TOL)
end; end
for solver in nlp_solvers
context("With solver $(typeof(solver))") do
m = Model(solver=solver)
@variable(m, x, Bin)
@objective(m, Min, x)
@NLconstraint(m, x >= 0.5)
@fact solve(m, relaxation=true) --> :Optimal
@fact getvalue(x) --> roughly(0.5, TOL)
end; end
end

0 comments on commit 6e92de8

Please sign in to comment.