Skip to content

Commit

Permalink
Add cutest_finalize as a finalizer (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira authored and dpo committed Oct 29, 2016
1 parent 7234d25 commit 7775008
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/CUTEst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Base.Libdl.dlsym
# Only one problem can be interfaced at any given time.
global cutest_instances = 0

export CUTEstModel, sifdecoder, cutest_finalize
export CUTEstModel, sifdecoder

type CUTEstModel <: AbstractNLPModel
meta :: NLPModelMeta;
Expand Down Expand Up @@ -181,6 +181,8 @@ function CUTEstModel(name :: String, args...; decode :: Bool=true, verbose ::Boo
nlp = CUTEstModel(meta, Counters())

cutest_instances += 1;
finalizer(nlp, cutest_finalize)

return nlp
end

Expand Down
2 changes: 1 addition & 1 deletion test/consistency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ for problem in problems
@printf("Checking problem %-15s%12s\t", problem_s, "")
consistent_nlps(nlps)

cutest_finalize(nlp_cutest)
finalize(nlp_cutest)
end
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for problem in problems
test_coreinterface(nlp, adnlp)

println("Finalizing")
cutest_finalize(nlp)
finalize(nlp)
end

include("consistency.jl")
Expand Down Expand Up @@ -56,17 +56,17 @@ for p in problems
else
println("$p: specialized interface: f(x₀) = $(ufn(nvar, x0))")
end
cutest_finalize(nlp)
finalize(nlp)
end

# test arguments passed to decoder
nlp = CUTEstModel("DIXMAANJ", "-param", "M=5")
@assert nlp.meta.nvar == 15
cutest_finalize(nlp)
finalize(nlp)

nlp = CUTEstModel("DIXMAANJ", "-param", "M=30")
@assert nlp.meta.nvar == 90
cutest_finalize(nlp)
finalize(nlp)

# clean up the test directory
here = dirname(@__FILE__)
Expand Down
2 changes: 1 addition & 1 deletion test/test_mpb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ model = NLPtoMPB(nlp, IpoptSolver())
@assert isa(model, Ipopt.IpoptMathProgModel)
MathProgBase.optimize!(model)
@assert MathProgBase.getobjval(model) 0.0
cutest_finalize(nlp)
finalize(nlp)

0 comments on commit 7775008

Please sign in to comment.