Skip to content

Commit

Permalink
Handle all Ipopt codes
Browse files Browse the repository at this point in the history
  • Loading branch information
IainNZ committed Oct 22, 2014
1 parent c9ad8ef commit d818e8b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Ipopt.jl
Expand Up @@ -46,7 +46,7 @@ end
end
end


# From Ipopt/src/Interfaces/IpReturnCodes_inc.h
ApplicationReturnStatus = {
0=>:Solve_Succeeded,
1=>:Solved_To_Acceptable_Level,
Expand Down
41 changes: 37 additions & 4 deletions src/IpoptSolverInterface.jl
Expand Up @@ -166,10 +166,43 @@ numvar(m::IpoptMathProgModel) = m.inner.n
numconstr(m::IpoptMathProgModel) = m.inner.m
optimize!(m::IpoptMathProgModel) = solveProblem(m.inner)
function status(m::IpoptMathProgModel)
if m.inner.status == 0 || m.inner.status == 1
return :Optimal
end
return :Infeasible
# Map all the possible return codes, as enumerated in
# Ipopt.ApplicationReturnStatus, to the MPB statuses:
# :Optimal, :Infeasible, :Unbounded, :UserLimit, and :Error
stat_sym = ApplicationReturnStatus[m.inner.status]
if stat_sym == :Solve_Succeeded ||
stat_sym == :Solved_To_Acceptable_Level
return :Optimal
elseif stat_sym == :Infeasible_Problem_Detected
return :Infeasible
elseif stat_sym == :Diverging_Iterates
return :Unbounded
# Things that are more likely to be fixable by changing
# a parameter will be treated as UserLimit, although
# some are error-like too.
elseif stat_sym == :User_Requested_Stop ||
stat_sym == :Maximum_Iterations_Exceeded ||
stat_sym == :Maximum_CpuTime_Exceeded
return :UserLimit
else
# Default is to not mislead user that it worked
# Includes:
# :Search_Direction_Becomes_Too_Small
# :Feasible_Point_Found
# :Restoration_Failed
# :Error_In_Step_Computation
# :Not_Enough_Degrees_Of_Freedom
# :Invalid_Problem_Definition
# :Invalid_Option
# :Invalid_Number_Detected
# :Unrecoverable_Exception
# :NonIpopt_Exception_Thrown
# :Insufficient_Memory
# :Internal_Error
warn("Ipopt finished with status $stat_sym")
return :Error
end

end
getobjval(m::IpoptMathProgModel) = m.inner.obj_val * (m.inner.sense == :Max ? -1 : +1)
getsolution(m::IpoptMathProgModel) = m.inner.x
Expand Down

0 comments on commit d818e8b

Please sign in to comment.