@@ -54,6 +54,41 @@ function get_stats(sol, ::OptimizationMOI.MOI.OptimizerWithAttributes)
5454 return (length(sol.u), MOI.get(sol.original.model, MOI.SolveTimeSec()),
5555 "Ipopt", Symbol(sol.retcode))
5656end
57+
58+ function run_benchmarks(problems, optimizers)
59+ problem = String[]
60+ n_vars = Int64[]
61+ secs = Float64[]
62+ solver = String[]
63+ retcode = Symbol[]
64+
65+ optz = length(optimizers)
66+ n = length(problems)
67+
68+ broadcast(c -> sizehint!(c, optz * n), [problem, n_vars, secs, solver, retcode])
69+
70+ for prob_name in problems
71+ nlp_prob = CUTEstModel(prob_name)
72+ prob = OptimizationNLPModels.OptimizationProblem(nlp_prob, Optimization.AutoForwardDiff())
73+ for optimizer in optimizers
74+ sol = solve(prob, optimizer; maxiters = 1e7)
75+
76+ @info "Solved $(prob_name) with $(optimizer)"
77+ vars, time, alg, code = get_stats(sol, optimizer)
78+
79+ push!(problem, prob_name)
80+ push!(n_vars, vars)
81+ push!(secs, time)
82+ push!(solver, alg)
83+ push!(retcode, code)
84+
85+ end
86+ finalize(nlp_prob)
87+ end
88+
89+ return DataFrame(problem = problem, n_vars = n_vars, secs = secs, solver = solver,
90+ retcode = retcode)
91+ end
5792```
5893
5994## Unconstrained problems
@@ -63,48 +98,54 @@ terms of the time to solution with respect to the number of variables.
6398
6499```julia
65100unc_problems = CUTEst.select(contype="unc")
66- n = length(unc_problems)
67- optz = length(optimizers)
68101
69- problem = String[]
70- n_vars = Int64[]
71- secs = Float64[]
72- solver = String[]
73- retcode = Symbol[]
74-
75- broadcast(c -> sizehint!(c, optz * n), [problem, n_vars, secs, solver, retcode])
102+ # Analysis
103+ unc_results = run_benchmarks(unc_problems, optimizers)
76104
77- for prob_name in unc_problems
78- @show prob_name
79- nlp_prob = CUTEstModel(prob_name)
80- prob = OptimizationNLPModels.OptimizationProblem(nlp_prob, Optimization.AutoForwardDiff())
81- for optimizer in optimizers
82- sol = solve(prob, optimizer; maxiters = 1e7)
105+ @df unc_results scatter(:n_vars, :secs,
106+ group = :solver,
107+ xlabel = "n. variables",
108+ ylabel = "secs.",
109+ title = "Time to solution by optimizer and number of vars",
110+ )
111+ ```
83112
84- @info "Solved $(prob_name) with $(optimizer)"
85- vars, time, alg, code = get_stats(sol, optimizer)
113+ ## Equality/Inequality constrained problems with unbounded variables
86114
87- push!(problem, prob_name)
88- push!(n_vars, vars)
89- push!(secs, time)
90- push!(solver, alg)
91- push!(retcode, code)
115+ These problems have a constraint function that's subject to either equality or inequality
116+ constraints, but the variables themselves are free. CUTEst contains 285 problems with
117+ equality constraints and 114 with inequality constraints for a total of 299.
92118
93- end
94- finalize(nlp_prob)
119+ We start by analyzing the equality-constrained problems, of which there are 285. The
120+ following figure shows the time to solution as a function of number of variables by
121+ optimizer.
95122
96- break
97- end
123+ ```julia
124+ eq_unb_problems = CUTEst.select(min_con=1, only_equ_con=true, only_free_var=true)
98125
99126# Analysis
100- unc_results = DataFrame(problem = problem, n_vars = n_vars, secs = secs, solver = solver,
101- retcode = retcode)
127+ eq_unb_results = run_benchmarks(unc_problems, optimizers)
102128
103- @df unc_results scatter(:nvars , :secs,
129+ @df eq_unb_results scatter(:n_vars , :secs,
104130 group = :solver,
105131 xlabel = "n. variables",
106132 ylabel = "secs.",
107133 title = "Time to solution by optimizer and number of vars",
108134 )
109135```
110136
137+ Next, we examine the same relationship for problems with inequality-constrained problems.
138+
139+ ```julia
140+ neq_unb_problems = CUTEst.select(min_con=1, only_ineq_con=true, only_free_var=true)
141+
142+ # Analysis
143+ neq_unb_results = run_benchmarks(unc_problems, optimizers)
144+
145+ @df neq_unb_results scatter(:n_vars, :secs,
146+ group = :solver,
147+ xlabel = "n. variables",
148+ ylabel = "secs.",
149+ title = "Time to solution by optimizer and number of vars",
150+ )
151+ ```
0 commit comments