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

HS071 NLP problem MathProgBase: MOSEK error 1291: The optimization problem is nonconvex #62

Closed
steven-varga opened this issue Oct 22, 2015 · 4 comments

Comments

@steven-varga
Copy link

Hello,

for some reasons HS071 NLP problem reports MOSEK error 1291 even though seemingly solves the problem.
The problem is solvable with alternative solvers: Ipopt

comments are removed because of markdown

using Base.Test, MathProgBase, Mosek
import MathProgBase.MathProgSolverInterface


type HS071 <: MathProgSolverInterface.AbstractNLPEvaluator
end

function MathProgBase.initialize(d::HS071, requested_features::Vector{Symbol})
    for feat in requested_features
        if !(feat in [:Grad, :Jac, :Hess])
            error("Unsupported feature $feat")
            # TODO: implement Jac-vec and Hess-vec products
            # for solvers that need them
        end
    end
end

MathProgBase.features_available(d::HS071) = [:Grad, :Jac, :Hess]

MathProgBase.eval_f(d::HS071, x) = x[1] * x[4] * (x[1] + x[2] + x[3]) + x[3]

function MathProgBase.eval_g(d::HS071, g, x)
    g[1] = x[1]   * x[2]   * x[3]   * x[4]
    g[2] = x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2
end

function MathProgBase.eval_grad_f(d::HS071, grad_f, x)
    grad_f[1] = x[1] * x[4] + x[4] * (x[1] + x[2] + x[3])
    grad_f[2] = x[1] * x[4]
    grad_f[3] = x[1] * x[4] + 1
    grad_f[4] = x[1] * (x[1] + x[2] + x[3])
end

MathProgBase.jac_structure(d::HS071) = [1,1,1,1,2,2,2,2],[1,2,3,4,1,2,3,4]
MathProgBase.hesslag_structure(d::HS071) = [1,2,2,3,3,3,4,4,4,4],[1,1,2,1,2,3,1,2,3,4]


function MathProgBase.eval_jac_g(d::HS071, J, x)
    J[1] = x[2]*x[3]*x[4]  # 1,1
    J[2] = x[1]*x[3]*x[4]  # 1,2
    J[3] = x[1]*x[2]*x[4]  # 1,3
    J[4] = x[1]*x[2]*x[3]  # 1,4

    J[5] = 2*x[1]  # 2,1
    J[6] = 2*x[2]  # 2,2
    J[7] = 2*x[3]  # 2,3
    J[8] = 2*x[4]  # 2,4
end

function MathProgBase.eval_hesslag(d::HS071, H, x, σ, μ)
    H[1] = σ * (2*x[4])               # 1,1
    H[2] = σ * (  x[4])               # 2,1
    H[3] = 0                          # 2,2
    H[4] = σ * (  x[4])               # 3,1
    H[5] = 0                          # 3,2
    H[6] = 0                          # 3,3
    H[7] = σ* (2*x[1] + x[2] + x[3])  # 4,1
    H[8] = σ * (  x[1])               # 4,2
    H[9] = σ * (  x[1])               # 4,3
    H[10] = 0                         # 4,4

    H[2] += μ[1] * (x[3] * x[4])  # 2,1
    H[4] += μ[1] * (x[2] * x[4])  # 3,1
    H[5] += μ[1] * (x[1] * x[4])  # 3,2
    H[7] += μ[1] * (x[2] * x[3])  # 4,1
    H[8] += μ[1] * (x[1] * x[3])  # 4,2
    H[9] += μ[1] * (x[1] * x[2])  # 4,3

    H[1]  += μ[2] * 2  # 1,1
    H[3]  += μ[2] * 2  # 2,2
    H[6]  += μ[2] * 2  # 3,3
    H[10] += μ[2] * 2  # 4,4

end

function nlptest(solver=MathProgBase.defaultNLPsolver)

    m = MathProgBase.model(solver)
    l = [1,1,1,1]
    u = [5,5,5,5]
    lb = [25, 40]
    ub = [Inf, 70]
    MathProgBase.loadnonlinearproblem!(m, 4, 2, l, u, lb, ub, :Min, HS071())
    MathProgBase.optimize!(m)
end

nlptest( MosekSolver() )

-------------------- end of test file -----------------

@mlubin
Copy link
Contributor

mlubin commented Oct 23, 2015

The error message is correct. The problem is nonconvex and the Mosek NLP solver only supports convex problems.

(By the way, you can use three backticks like ``` to dump raw text.)

@steven-varga
Copy link
Author

Thanks for the backticks!
Is it wrong to interpret {l,u} lower and upper bounds as domain restrictions? within the bounds we are looking at a multiplication of increasing positive numbers with sum of other increasing positive numbers.

@mlubin
Copy link
Contributor

mlubin commented Oct 23, 2015

Multiplication of positive terms is not convex. The function f(x,y) = x*y does not have a positive semidefinite hessian matrix anywhere in its domain.

@steven-varga
Copy link
Author

Thanks for pointing out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants