Skip to content

Commit

Permalink
Merge pull request #118 from odow/fixmiqp
Browse files Browse the repository at this point in the history
Fix handling of MIQP problem type. Fixes #115
  • Loading branch information
mlubin authored Feb 25, 2017
2 parents 6620417 + 0b0e4ce commit a07d709
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cpx_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ end
const type_map = Dict(
0 => :LP,
1 => :MILP,
3 => :MILP, # actually fixed milp
3 => :FIXEDMILP, # actually fixed milp
5 => :QP,
7 => :MIQP,
8 => :MIQP,
8 => :FIXEDMIQP,
10 => :QCP,
11 => :MIQCP
)
Expand All @@ -112,7 +112,7 @@ const rev_prob_type_map = Dict(
:FIXEDMILP => 3,
:QP => 5,
:MIQP => 7,
:MIQP => 8,
:FIXEDMIQP => 8,
:QCP => 10,
:MIQCP => 11
)
Expand Down
44 changes: 44 additions & 0 deletions test/miqcp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# QCP example
# minimize x^2
#
# s.t. x >= 0.1
# x ∈ {0, 1}
#
# solution: (0.1) objv = 0.01

using CPLEX
using Base.Test

# ===========================================

m = CPLEX.CplexMathProgModel()
CPLEX.loadproblem!(m, Array(Float64, (0,1)), [0.1], [Inf], [0], Float64[], Float64[], :Min)
@test CPLEX.get_prob_type(m.inner) == :LP
CPLEX.setquadobj!(m, [2]')
@test CPLEX.get_prob_type(m.inner) == :QP
CPLEX.optimize!(m)
@test isapprox(CPLEX.getobjval(m), 0.5*0.1*2*0.1)

# ===========================================

m2 = CPLEX.CplexMathProgModel()
CPLEX.loadproblem!(m2, Array(Float64, (0,1)), [0.1], [Inf], [0], Float64[], Float64[], :Min)
@test CPLEX.get_prob_type(m2.inner) == :LP
CPLEX.setvartype!(m2, [:Bin])
@test CPLEX.get_prob_type(m2.inner) == :MILP
CPLEX.setquadobj!(m2, [2]')
@test CPLEX.get_prob_type(m2.inner) == :MIQP
CPLEX.optimize!(m2)
@test isapprox(CPLEX.getobjval(m2), 0.5*1*2*1)

# ===========================================

m3 = CPLEX.CplexMathProgModel()
CPLEX.loadproblem!(m3, Array(Float64, (0,1)), [0.1], [Inf], [0], Float64[], Float64[], :Min)
@test CPLEX.get_prob_type(m3.inner) == :LP
CPLEX.setquadobj!(m3, [2]')
@test CPLEX.get_prob_type(m3.inner) == :QP
CPLEX.setvartype!(m3, [:Bin])
@test CPLEX.get_prob_type(m3.inner) == :MIQP
CPLEX.optimize!(m3)
@test isapprox(CPLEX.getobjval(m3), 0.5*1*2*1)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tests = ["low_level_api",
"env",
"sos",
"problemtype",
"miqcp",
"mathprog"
]

Expand Down

0 comments on commit a07d709

Please sign in to comment.