jump-dev / JuMP.jl

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)
http://jump.dev/JuMP.jl/
Other
2.24k stars 395 forks source link

JuMP with Ipopt algorithm find a wrong optimal solution #1214

Closed Simpleton123 closed 6 years ago

Simpleton123 commented 6 years ago

I need to find the solution (x,y) to minimize a function. I choose trust-region-reflective algorithm on MATLAB, find the optimal solution is (1.45392043849310, 2.22057922774844e-14), and objective = -652.457827998786. Then I choose JuMP and use Ipopt algorithm on Julia, with the same initialized value (0.948683298050514, 0.500000000000000), same constraints and same tolerance = 1e-9, but algorithm stops, optimal solution is (0.948683638232005, 0.500), and objective = -600.58335. Since on MATLAB, I can call fmincon function, which can use gradient and also hessian of function. But on Julia, there is an information that hessian can not be used for multi-variable optimization, so I only use gradient. This is different between two code. Could someone help me with this problem? Thanks!!!

Julia code is as following:

_file = matopen("data_test.mat")
PARAM = read(file, "PARAM")
data = read(file,"data")
evalue_ini = read(file,"evalue_ini")
m = JuMP.Model(solver=Ipopt.IpoptSolver(tol=1e-9))
function f(x,y)
    par = LF(x, y, data, evalue_ini,tdays,adjsig,adjweight);
    return par
end
function ∇f(g,x,y)
    g = prime_LF(x, y, data, evalue_ini,tdays,adjsig,adjweight);
end
JuMP.register(m,:f,2,f,∇f)
@variable(m,x,start=PARAM[1])
@constraint(m,0<=x<=Inf)
@variable(m,y,start=PARAM[2])
@constraint(m,0<=y<=1)
@NLobjective(m,Min,f(x,y))
solve(m)_

Optimal report is as following:

_This is Ipopt version 3.12.2, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).

Number of nonzeros in equality constraint Jacobian...:        0
Number of nonzeros in inequality constraint Jacobian.:        2
Number of nonzeros in Lagrangian Hessian.............:        0

Total number of variables............................:        2
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
Total number of inequality constraints...............:        2
        inequality constraints with only lower bounds:        1
   inequality constraints with lower and upper bounds:        1
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0 -6.0058324e+002 0.00e+000 5.00e-001   0.0 0.00e+000    -  0.00e+000 0.00e+000   0
   1 -6.0058335e+002 0.00e+000 5.00e-003  -6.2 3.33e-007    -  9.90e-001 1.00e+000f  1
   2 -6.0058335e+002 0.00e+000 4.74e-005  -8.2 6.78e-009    -  9.91e-001 1.00e+000f  1
   3 -6.0058335e+002 0.00e+000 4.27e-009 -10.2 6.50e-011    -  1.00e+000 1.00e+000f  1
   4 -6.0058335e+002 0.00e+000 5.27e-012 -11.0 1.05e-011    -  1.00e+000 1.00e+000f  1

Number of Iterations....: 4

                                   (scaled)                 (unscaled)
Objective...............: -6.0058334963170796e+002  -6.0058334963170796e+002
Dual infeasibility......:  5.2704607741201870e-012   5.2704607741201870e-012
Constraint violation....:  0.0000000000000000e+000   0.0000000000000000e+000
Complementarity.........:  9.9999999999998912e-012   9.9999999999998912e-012
Overall NLP error.......:  9.9999999999998912e-012   9.9999999999998912e-012

Number of objective function evaluations             = 5
Number of objective gradient evaluations             = 5
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 5
Number of equality constraint Jacobian evaluations   = 0
Number of inequality constraint Jacobian evaluations = 5
Number of Lagrangian Hessian evaluations             = 0
Total CPU secs in IPOPT (w/o function evaluations)   =      0.005
Total CPU secs in NLP function evaluations           =      0.014

EXIT: Optimal Solution Found._
blegat commented 6 years ago

Duplicate of https://github.com/JuliaOpt/Ipopt.jl/issues/109. Note that if you are looking for more feedback on your issue, you will have better luck posting it on Discourse than on a Github issue ;)

mlubin commented 6 years ago

Closing, since there's unlikely an issue with JuMP here. Questions about solver behavior could go to Discourse as @blegat suggested, or to the solvers' respective mailing lists.