Skip to content

Commit adc4986

Browse files
committed
Add a function select_sif_problems
1 parent d0890f3 commit adc4986

File tree

2 files changed

+76
-75
lines changed

2 files changed

+76
-75
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ using CUTEst
8888
available_problems = list_sif_problems()
8989
```
9090

91+
If you want to retrieve only problems with specific properties, you can use the function `select_sif_problems`:
92+
93+
```julia
94+
using CUTEst
95+
96+
filtered_problems = select_sif_problems(; min_var=10, max_var=100, only_linear_con=true)
97+
```
98+
9199
## Tutorial
92100

93101
You can check an [Introduction to CUTEst.jl](https://jso.dev/tutorials/introduction-to-cutest/) on our [site](https://jso.dev/).

src/classification.jl

+68-75
Original file line numberDiff line numberDiff line change
@@ -28,83 +28,76 @@ const origins = ["academic", "modelling", "real"]
2828
const classdb_origin = Dict("A" => origins[1], "M" => origins[2], "R" => origins[3])
2929

3030
"""
31-
select_sif_problems(;min_var=1, max_var=Inf, min_con=0, max_con=Inf,
32-
objtype=*, contype=*,
33-
only_free_var=false, only_bnd_var=false,
34-
only_linear_con=false, only_nonlinear_con=false,
35-
only_equ_con=false, only_ineq_con=false,
36-
custom_filter=*)
31+
select_sif_problems(; min_var=1, max_var=Inf, min_con=0, max_con=Inf,
32+
objtype=*, contype=*, only_free_var=false,
33+
only_bnd_var=false, only_linear_con=false,
34+
only_nonlinear_con=false, only_equ_con=false,
35+
only_ineq_con=false, custom_filter=*)
3736
38-
Returns a subset of the CUTEst problems using the classification file
39-
`classf.json`. This file is export together with the package, so if you have an
40-
old CUTEst installation, it can lead to inconsistencies.
37+
Returns a subset of the CUTEst problems using the classification file `classf.json`.
4138
42-
- `min_var` and `max_var` set the number of variables in the problem;
43-
- `min_con` and `max_con` set the number of constraints in the problem
44-
(e.g., use `max_con=0` for unconstrained or `min_con=1` for constrained)
45-
- `only_*` flags are self-explaining. Note that they appear in conflicting
46-
pairs. Both can be false, but only one can be true.
47-
- `objtype` is the classification of the objective function according to the
48-
[MASTSIF classification file](https://www.cuter.rl.ac.uk/Problems/classification.shtml).
49-
It can be a number, a symbol, a string, or an array of those.
50-
51-
1, :none or "none" means there is no objective function;
52-
2, :constant or "constant" means the objective function is a constant;
53-
3, :linear or "linear" means the objective function is a linear functional;
54-
4, :quadratic or "quadratic" means the objective function is quadratic;
55-
5, :sum_of_squares or "sum_of_squares" means the objective function is a sum of squares
56-
6, :other or "other" means the objective function is none of the above.
57-
58-
- `contype` is the classification of the constraints according to the same
59-
MASTSIF classification file.
60-
61-
1, :unc or "unc" means there are no constraints at all;
62-
2, :fixed_vars or "fixed_vars" means the only constraints are fixed variables;
63-
3, :bounds or "bounds" means the only constraints are bounded variables;
64-
4, :network or "network" means the constraints represent the adjacency matrix of a (linear) network;
65-
5, :linear or "linear" means the constraints are linear;
66-
6, :quadratic or "quadratic" means the constraints are quadratic;
67-
7, :other or "other" means the constraints are more general.
39+
## Keyword arguments
6840
69-
- `custom_filter`: A function to apply additional filtering to the problem data. This data is provided as a dictionary with the following fields:
41+
- `min_var` and `max_var` set the number of variables in the problem;
7042
71-
- `"objtype"`: String representing the objective function type. It can be one of the following:
72-
- `"none"`, `"constant"`, `"linear"`, `"quadratic"`, `"sum_of_squares"`, `"other"`
43+
- `min_con` and `max_con` set the number of constraints in the problem (use `max_con=0` for unconstrained or `min_con=1` for constrained);
7344
74-
- `"contype"`: String representing the constraint type. It can be one of the following:
75-
- `"unc"`, `"fixed_vars"`, `"bounds"`, `"network"`, `"linear"`, `"quadratic"`, `"other"`
45+
- `only_*` flags are self-explaining. Note that they appear in conflicting pairs. Both can be false, but only one can be true.
7646
77-
- `"regular"`: Boolean indicating whether the problem is regular or not.
47+
- `objtype` is the classification of the objective function according to the [MASTSIF classification](https://www.cuter.rl.ac.uk/Problems/classification.shtml). It can be a number, a symbol, a string, or an array of those.
48+
- 1, :none or "none" means there is no objective function;
49+
- 2, :constant or "constant" means the objective function is a constant;
50+
- 3, :linear or "linear" means the objective function is a linear functional;
51+
- 4, :quadratic or "quadratic" means the objective function is quadratic;
52+
- 5, :sum_of_squares or "sum_of_squares" means the objective function is a sum of squares;
53+
- 6, :other or "other" means the objective function is none of the above.
7854
79-
- `"derivative_order"`: Integer representing the order of the highest derivative available.
55+
- `contype` is the classification of the constraints according to the same MASTSIF classification file.
56+
- 1, :unc or "unc" means there are no constraints at all;
57+
- 2, :fixed_vars or "fixed_vars" means the only constraints are fixed variables;
58+
- 3, :bounds or "bounds" means the only constraints are bounded variables;
59+
- 4, :network or "network" means the constraints represent the adjacency matrix of a (linear) network;
60+
- 5, :linear or "linear" means the constraints are linear;
61+
- 6, :quadratic or "quadratic" means the constraints are quadratic;
62+
- 7, :other or "other" means the constraints are more general.
8063
81-
- `"origin"`: String indicating the origin of the problem. Possible values are `"academic"`, `"modelling"`, or `"real"`.
82-
83-
- `"has_interval_var"`: Boolean indicating whether the problem includes interval variables.
64+
- `custom_filter`: A function to apply additional filtering to the problem data. This data is provided as a dictionary with the following fields:
65+
- `"objtype"`: String representing the objective function type. It can be one of the following:
66+
- `"none"`, `"constant"`, `"linear"`, `"quadratic"`, `"sum_of_squares"`, `"other"`
8467
85-
- `"variables"`: Dictionary with fields related to variables:
86-
- `"can_choose"`: Boolean indicating whether you can change the number of variables via parameters.
87-
- `"number"`: Integer representing the number of variables (default if `"can_choose"` is true).
88-
- `"fixed"`: Integer representing the number of fixed variables.
89-
- `"free"`: Integer representing the number of free variables.
90-
- `"bounded_below"`: Integer representing the number of variables bounded only from below.
91-
- `"bounded_above"`: Integer representing the number of variables bounded only from above.
92-
- `"bounded_both"`: Integer representing the number of variables bounded from both below and above.
68+
- `"contype"`: String representing the constraint type. It can be one of the following:
69+
- `"unc"`, `"fixed_vars"`, `"bounds"`, `"network"`, `"linear"`, `"quadratic"`, `"other"`
9370
94-
- `"constraints"`: Dictionary with fields related to constraints:
95-
- `"can_choose"`: Boolean indicating whether you can change the number of constraints via parameters.
96-
- `"number"`: Integer representing the number of constraints (default if `"can_choose"` is true).
97-
- `"equality"`: Integer representing the number of equality constraints.
98-
- `"ineq_below"`: Integer representing the number of inequalities of the form `c(x) ≥ cl`.
99-
- `"ineq_above"`: Integer representing the number of inequalities of the form `c(x) ≤ cu`.
100-
- `"ineq_both"`: Integer representing the number of inequalities of the form `cl ≤ c(x) ≤ cu`.
101-
- `"linear"`: Integer representing the number of linear constraints.
102-
- `"nonlinear"`: Integer representing the number of nonlinear constraints.
71+
- `"regular"`: Boolean indicating whether the problem is regular or not.
72+
- `"derivative_order"`: Integer representing the order of the highest derivative available.
10373
104-
For instance, if you'd like to choose only problems with fixed number of variables, you can pass
74+
- `"origin"`: String indicating the origin of the problem. Possible values are `"academic"`, `"modelling"`, or `"real"`.
75+
76+
- `"has_interval_var"`: Boolean indicating whether the problem includes interval variables.
77+
78+
- `"variables"`: Dictionary with fields related to variables:
79+
- `"can_choose"`: Boolean indicating whether you can change the number of variables via parameters.
80+
- `"number"`: Integer representing the number of variables (default if `"can_choose"` is true).
81+
- `"fixed"`: Integer representing the number of fixed variables.
82+
- `"free"`: Integer representing the number of free variables.
83+
- `"bounded_below"`: Integer representing the number of variables bounded only from below.
84+
- `"bounded_above"`: Integer representing the number of variables bounded only from above.
85+
- `"bounded_both"`: Integer representing the number of variables bounded from both below and above.
86+
87+
- `"constraints"`: Dictionary with fields related to constraints:
88+
- `"can_choose"`: Boolean indicating whether you can change the number of constraints via parameters.
89+
- `"number"`: Integer representing the number of constraints (default if `"can_choose"` is true).
90+
- `"equality"`: Integer representing the number of equality constraints.
91+
- `"ineq_below"`: Integer representing the number of inequalities of the form `c(x) ≥ cl`.
92+
- `"ineq_above"`: Integer representing the number of inequalities of the form `c(x) ≤ cu`.
93+
- `"ineq_both"`: Integer representing the number of inequalities of the form `cl ≤ c(x) ≤ cu`.
94+
- `"linear"`: Integer representing the number of linear constraints.
95+
- `"nonlinear"`: Integer representing the number of nonlinear constraints.
10596
10697
```julia
107-
custom_filter = x -> x["variables"]["can_choose"] == false
98+
filtered_problems1 = select_sif_problems(; min_var=10, max_var=100, only_linear_con=true)
99+
filtered_problems2 = select_sif_problems(; max_con=0)
100+
filtered_problems3 = select_sif_problems(; min_con=1)
108101
```
109102
"""
110103
function select_sif_problems(;
@@ -114,12 +107,12 @@ function select_sif_problems(;
114107
max_con = Inf,
115108
objtype = objtypes,
116109
contype = contypes,
117-
only_free_var = false,
118-
only_bnd_var = false,
119-
only_linear_con = false,
120-
only_nonlinear_con = false,
121-
only_equ_con = false,
122-
only_ineq_con = false,
110+
only_free_var::Bool = false,
111+
only_bnd_var::Bool = false,
112+
only_linear_con::Bool = false,
113+
only_nonlinear_con::Bool = false,
114+
only_equ_con::Bool = false,
115+
only_ineq_con::Bool = false,
123116
custom_filter::Function = x -> true,
124117
)
125118
# Checks for conflicting option
@@ -137,9 +130,9 @@ function select_sif_problems(;
137130
error("contypes $contype not supported")
138131
end
139132

140-
data = JSON.parsefile(joinpath(dirname(@__FILE__), "classf.json"))
133+
data = JSON.parsefile(joinpath(@__DIR__, "classf.json"))
141134
problems = keys(data)
142-
selection = Vector{String}()
135+
selection = String[]
143136
for p in problems
144137
pv = data[p]["variables"]
145138
pc = data[p]["constraints"]
@@ -164,6 +157,9 @@ function select_sif_problems(;
164157
return selection
165158
end
166159

160+
# Keep an unexported function `select` to not break the tutorial
161+
select(; kwargs...) = select_sif_problems(; kwargs...)
162+
167163
canonicalize_ftype(reqtype::Integer, allowedtypes) = [allowedtypes[reqtype]]
168164
canonicalize_ftype(reqtype::Symbol, allowedtypes) = [string(reqtype)]
169165
canonicalize_ftype(reqtype::AbstractString, allowedtypes) = [reqtype]
@@ -172,9 +168,6 @@ canonicalize_ftype(reqtype::AbstractVector{T}, allowedtypes) where {T <: Integer
172168
canonicalize_ftype(reqtype::AbstractVector{Symbol}, allowedtypes) = map(string, reqtype)
173169
canonicalize_ftype(reqtype, allowedtypes) = reqtype
174170

175-
# Keep an unexported function `select` to not break the tutorial
176-
select(; kwargs...) = select_sif_problems(; kwargs...)
177-
178171
"""
179172
build_classification()
180173

0 commit comments

Comments
 (0)