Skip to content

WIP: Migrated First Conic Model #191

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

Merged
merged 3 commits into from
Jun 16, 2017
Merged
Changes from all 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
57 changes: 42 additions & 15 deletions test/conicinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using Base.Test
using MathProgBase

"""
function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false, tol=1e-6)
function coniclineartest(solver::MathProgBase.AbstractMathProgSolver; duals=false, tol=1e-6)
@testset "Testing linear problems through conic interface with $solver" begin
# Problem LIN1 - all vars in nonneg cone
# min -3x - 2y - 4z
Expand All @@ -23,21 +23,48 @@ function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false
A = [ 1.0 1.0 1.0;
0.0 1.0 1.0]
b = [ 3.0, 2.0]
m = MathProgBase.ConicModel(solver)
MathProgBase.loadproblem!(m, c, A, b, [(:Zero,1:2)], [(:NonNeg, 1:3)])
m = MPB.Model(solver)

#MathProgBase.loadproblem!(m, c, A, b, [(:Zero,1:2)], [(:NonNeg, 1:3)])
v = MPB.addvariables!(m, 3)

MPB.setattribute!(m, MPB.Sense(), MPB.MinSense)

vc = MPB.addconstraint!(m, v, MPB.NonNegative(3))
c = MPB.addconstraint!(m, b, -A, MPB.Zero(2))

MPB.setobjective!(m, 1, 0.0, v, c)

MathProgBase.optimize!(m)
@test MathProgBase.status(m) == :Optimal
@test isapprox(MathProgBase.getobjval(m), -11, atol=tol)
@test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol)
@test isapprox(MathProgBase.getsolution(m)[2], 0.0, atol=tol)
@test isapprox(MathProgBase.getsolution(m)[3], 2.0, atol=tol)

termination_status = MPB.getattribute(m, MPB.TerminationStatus())
@test termination_status == MPB.Success

primal_status = MPB.getattribute(m, MPB.PrimalStatus())
@test primal_status == MPB.FeasiblePoint

obj = MPB.getattribute(m, MPB.ObjectiveValue())
@test isapprox(obj, -11, atol=tol)

p_sol = MPB.getattribute(m, MPB.VariablePrimal(), v)
@test isapprox(p_sol[1], 1.0, atol=tol)
@test isapprox(p_sol[2], 0.0, atol=tol)
@test isapprox(p_sol[3], 2.0, atol=tol)
if duals
d = MathProgBase.getdual(m)
@test isapprox(d[1], 3.0, atol=tol)
@test isapprox(d[2], 1.0, atol=tol)
vardual = c + A'd
var = MathProgBase.getvardual(m)
@test isapprox(vardual, var, atol=tol)
@test MPB.cangetattribute(m, MPB.DualStatus())
@test MPB.cangetattribute(m, MPB.ConstraintDual(), c)
@test MPB.cangetattribute(m, MPB.ConstraintDual(), vc)

dual_status = MPB.getattribute(m, MPB.DualStatus())
@test dual_status == MPB.FeasiblePoint

d_sol = MPB.getattribute(m, MPB.ConstraintDual(), c)
@test isapprox(d_sol[1], 3.0, atol=tol)
@test isapprox(d_sol[2], 1.0, atol=tol)

vardual = c + A'd_sol
vd_sol = MPB.getattribute(m, MPB.ConstraintDual(), vc)
@test isapprox(vardual, vd_sol, atol=tol)
end
end

Expand All @@ -59,7 +86,7 @@ function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false
0.0 1.0 0.0;
0.0 0.0 -1.0]
b = [ 3.0, 2.0, 0.0, 0.0, 0.0]
m = MathProgBase.ConicModel(solver)
m = MPB.ConicModel(solver)
MathProgBase.loadproblem!(m,c, A, b, [(:Zero,1:2),(:NonPos,3:4),(:NonNeg,5)],
[(:Free, 1:3)])
MathProgBase.optimize!(m)
Expand Down