Skip to content

Commit

Permalink
fix time bug (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Feb 21, 2022
1 parent 708dfd0 commit ebe587f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/NLPModelsIpopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function ipopt(nlp::AbstractNLPModel; callback::Union{Function, Nothing} = nothi
dual_feas = primal_feas = Inf
iter = -1
for line in ipopt_output
if occursin("CPU secs", line)
if occursin("Total seconds", line)
Δt += Meta.parse(split(line, "=")[2])
elseif occursin("Dual infeasibility", line)
dual_feas = Meta.parse(split(line)[4])
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ function tests()
stats = ipopt(nlp, print_level = 0)
@test isapprox(stats.solution, [1.0; 1.0], rtol = 1e-6)
@test stats.status == :first_order
@test stats.elapsed_time > 0

nlp = ADNLPModel(x -> (x[1] - 1)^2 + 100 * (x[2] - x[1]^2)^2, [-1.2; 1.0])
stats = ipopt(nlp, tol = 1e-12, print_level = 0)
@test isapprox(stats.solution, [1.0; 1.0], rtol = 1e-6)
@test stats.status == :first_order
@test stats.elapsed_time > 0

# solve again from solution
x0 = copy(stats.solution)
Expand All @@ -26,13 +28,15 @@ function tests()
@test stats.status == :user
@test stats.solver_specific[:internal_msg] == :User_Requested_Stop
@test stats.iter == 1
@test stats.elapsed_time > 0

nlp =
ADNLPModel(x -> (x[1] - 1)^2 + 4 * (x[2] - 3)^2, zeros(2), x -> [sum(x) - 1.0], [0.0], [0.0])
stats = ipopt(nlp, print_level = 0)
@test isapprox(stats.solution, [-1.4; 2.4], rtol = 1e-6)
@test stats.iter == 1
@test stats.status == :first_order
@test stats.elapsed_time > 0

# solve constrained problem again from solution
x0 = copy(stats.solution)
Expand All @@ -56,6 +60,7 @@ function tests()
@test isapprox(stats.multipliers_L, zeros(1), atol = 1e-6)
@test isapprox(stats.multipliers_U, -ones(1), rtol = 1e-6)
@test stats.status == :first_order
@test stats.elapsed_time > 0
end

tests()

0 comments on commit ebe587f

Please sign in to comment.