Skip to content

Commit

Permalink
Add a function select_sif_problems
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Aug 29, 2024
1 parent d0890f3 commit adc4986
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 75 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ using CUTEst
available_problems = list_sif_problems()
```

If you want to retrieve only problems with specific properties, you can use the function `select_sif_problems`:

```julia
using CUTEst

filtered_problems = select_sif_problems(; min_var=10, max_var=100, only_linear_con=true)
```

## Tutorial

You can check an [Introduction to CUTEst.jl](https://jso.dev/tutorials/introduction-to-cutest/) on our [site](https://jso.dev/).
Expand Down
143 changes: 68 additions & 75 deletions src/classification.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,83 +28,76 @@ const origins = ["academic", "modelling", "real"]
const classdb_origin = Dict("A" => origins[1], "M" => origins[2], "R" => origins[3])

"""
select_sif_problems(;min_var=1, max_var=Inf, min_con=0, max_con=Inf,
objtype=*, contype=*,
only_free_var=false, only_bnd_var=false,
only_linear_con=false, only_nonlinear_con=false,
only_equ_con=false, only_ineq_con=false,
custom_filter=*)
select_sif_problems(; min_var=1, max_var=Inf, min_con=0, max_con=Inf,
objtype=*, contype=*, only_free_var=false,
only_bnd_var=false, only_linear_con=false,
only_nonlinear_con=false, only_equ_con=false,
only_ineq_con=false, custom_filter=*)
Returns a subset of the CUTEst problems using the classification file
`classf.json`. This file is export together with the package, so if you have an
old CUTEst installation, it can lead to inconsistencies.
Returns a subset of the CUTEst problems using the classification file `classf.json`.
- `min_var` and `max_var` set the number of variables in the problem;
- `min_con` and `max_con` set the number of constraints in the problem
(e.g., use `max_con=0` for unconstrained or `min_con=1` for constrained)
- `only_*` flags are self-explaining. Note that they appear in conflicting
pairs. Both can be false, but only one can be true.
- `objtype` is the classification of the objective function according to the
[MASTSIF classification file](https://www.cuter.rl.ac.uk/Problems/classification.shtml).
It can be a number, a symbol, a string, or an array of those.
1, :none or "none" means there is no objective function;
2, :constant or "constant" means the objective function is a constant;
3, :linear or "linear" means the objective function is a linear functional;
4, :quadratic or "quadratic" means the objective function is quadratic;
5, :sum_of_squares or "sum_of_squares" means the objective function is a sum of squares
6, :other or "other" means the objective function is none of the above.
- `contype` is the classification of the constraints according to the same
MASTSIF classification file.
1, :unc or "unc" means there are no constraints at all;
2, :fixed_vars or "fixed_vars" means the only constraints are fixed variables;
3, :bounds or "bounds" means the only constraints are bounded variables;
4, :network or "network" means the constraints represent the adjacency matrix of a (linear) network;
5, :linear or "linear" means the constraints are linear;
6, :quadratic or "quadratic" means the constraints are quadratic;
7, :other or "other" means the constraints are more general.
## Keyword arguments
- `custom_filter`: A function to apply additional filtering to the problem data. This data is provided as a dictionary with the following fields:
- `min_var` and `max_var` set the number of variables in the problem;
- `"objtype"`: String representing the objective function type. It can be one of the following:
- `"none"`, `"constant"`, `"linear"`, `"quadratic"`, `"sum_of_squares"`, `"other"`
- `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);
- `"contype"`: String representing the constraint type. It can be one of the following:
- `"unc"`, `"fixed_vars"`, `"bounds"`, `"network"`, `"linear"`, `"quadratic"`, `"other"`
- `only_*` flags are self-explaining. Note that they appear in conflicting pairs. Both can be false, but only one can be true.
- `"regular"`: Boolean indicating whether the problem is regular or not.
- `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.
- 1, :none or "none" means there is no objective function;
- 2, :constant or "constant" means the objective function is a constant;
- 3, :linear or "linear" means the objective function is a linear functional;
- 4, :quadratic or "quadratic" means the objective function is quadratic;
- 5, :sum_of_squares or "sum_of_squares" means the objective function is a sum of squares;
- 6, :other or "other" means the objective function is none of the above.
- `"derivative_order"`: Integer representing the order of the highest derivative available.
- `contype` is the classification of the constraints according to the same MASTSIF classification file.
- 1, :unc or "unc" means there are no constraints at all;
- 2, :fixed_vars or "fixed_vars" means the only constraints are fixed variables;
- 3, :bounds or "bounds" means the only constraints are bounded variables;
- 4, :network or "network" means the constraints represent the adjacency matrix of a (linear) network;
- 5, :linear or "linear" means the constraints are linear;
- 6, :quadratic or "quadratic" means the constraints are quadratic;
- 7, :other or "other" means the constraints are more general.
- `"origin"`: String indicating the origin of the problem. Possible values are `"academic"`, `"modelling"`, or `"real"`.
- `"has_interval_var"`: Boolean indicating whether the problem includes interval variables.
- `custom_filter`: A function to apply additional filtering to the problem data. This data is provided as a dictionary with the following fields:
- `"objtype"`: String representing the objective function type. It can be one of the following:
- `"none"`, `"constant"`, `"linear"`, `"quadratic"`, `"sum_of_squares"`, `"other"`
- `"variables"`: Dictionary with fields related to variables:
- `"can_choose"`: Boolean indicating whether you can change the number of variables via parameters.
- `"number"`: Integer representing the number of variables (default if `"can_choose"` is true).
- `"fixed"`: Integer representing the number of fixed variables.
- `"free"`: Integer representing the number of free variables.
- `"bounded_below"`: Integer representing the number of variables bounded only from below.
- `"bounded_above"`: Integer representing the number of variables bounded only from above.
- `"bounded_both"`: Integer representing the number of variables bounded from both below and above.
- `"contype"`: String representing the constraint type. It can be one of the following:
- `"unc"`, `"fixed_vars"`, `"bounds"`, `"network"`, `"linear"`, `"quadratic"`, `"other"`
- `"constraints"`: Dictionary with fields related to constraints:
- `"can_choose"`: Boolean indicating whether you can change the number of constraints via parameters.
- `"number"`: Integer representing the number of constraints (default if `"can_choose"` is true).
- `"equality"`: Integer representing the number of equality constraints.
- `"ineq_below"`: Integer representing the number of inequalities of the form `c(x) ≥ cl`.
- `"ineq_above"`: Integer representing the number of inequalities of the form `c(x) ≤ cu`.
- `"ineq_both"`: Integer representing the number of inequalities of the form `cl ≤ c(x) ≤ cu`.
- `"linear"`: Integer representing the number of linear constraints.
- `"nonlinear"`: Integer representing the number of nonlinear constraints.
- `"regular"`: Boolean indicating whether the problem is regular or not.
- `"derivative_order"`: Integer representing the order of the highest derivative available.
For instance, if you'd like to choose only problems with fixed number of variables, you can pass
- `"origin"`: String indicating the origin of the problem. Possible values are `"academic"`, `"modelling"`, or `"real"`.
- `"has_interval_var"`: Boolean indicating whether the problem includes interval variables.
- `"variables"`: Dictionary with fields related to variables:
- `"can_choose"`: Boolean indicating whether you can change the number of variables via parameters.
- `"number"`: Integer representing the number of variables (default if `"can_choose"` is true).
- `"fixed"`: Integer representing the number of fixed variables.
- `"free"`: Integer representing the number of free variables.
- `"bounded_below"`: Integer representing the number of variables bounded only from below.
- `"bounded_above"`: Integer representing the number of variables bounded only from above.
- `"bounded_both"`: Integer representing the number of variables bounded from both below and above.
- `"constraints"`: Dictionary with fields related to constraints:
- `"can_choose"`: Boolean indicating whether you can change the number of constraints via parameters.
- `"number"`: Integer representing the number of constraints (default if `"can_choose"` is true).
- `"equality"`: Integer representing the number of equality constraints.
- `"ineq_below"`: Integer representing the number of inequalities of the form `c(x) ≥ cl`.
- `"ineq_above"`: Integer representing the number of inequalities of the form `c(x) ≤ cu`.
- `"ineq_both"`: Integer representing the number of inequalities of the form `cl ≤ c(x) ≤ cu`.
- `"linear"`: Integer representing the number of linear constraints.
- `"nonlinear"`: Integer representing the number of nonlinear constraints.
```julia
custom_filter = x -> x["variables"]["can_choose"] == false
filtered_problems1 = select_sif_problems(; min_var=10, max_var=100, only_linear_con=true)
filtered_problems2 = select_sif_problems(; max_con=0)
filtered_problems3 = select_sif_problems(; min_con=1)
```
"""
function select_sif_problems(;
Expand All @@ -114,12 +107,12 @@ function select_sif_problems(;
max_con = Inf,
objtype = objtypes,
contype = contypes,
only_free_var = false,
only_bnd_var = false,
only_linear_con = false,
only_nonlinear_con = false,
only_equ_con = false,
only_ineq_con = false,
only_free_var::Bool = false,
only_bnd_var::Bool = false,
only_linear_con::Bool = false,
only_nonlinear_con::Bool = false,
only_equ_con::Bool = false,
only_ineq_con::Bool = false,
custom_filter::Function = x -> true,
)
# Checks for conflicting option
Expand All @@ -137,9 +130,9 @@ function select_sif_problems(;
error("contypes $contype not supported")
end

data = JSON.parsefile(joinpath(dirname(@__FILE__), "classf.json"))
data = JSON.parsefile(joinpath(@__DIR__, "classf.json"))
problems = keys(data)
selection = Vector{String}()
selection = String[]
for p in problems
pv = data[p]["variables"]
pc = data[p]["constraints"]
Expand All @@ -164,6 +157,9 @@ function select_sif_problems(;
return selection
end

# Keep an unexported function `select` to not break the tutorial
select(; kwargs...) = select_sif_problems(; kwargs...)

canonicalize_ftype(reqtype::Integer, allowedtypes) = [allowedtypes[reqtype]]
canonicalize_ftype(reqtype::Symbol, allowedtypes) = [string(reqtype)]
canonicalize_ftype(reqtype::AbstractString, allowedtypes) = [reqtype]
Expand All @@ -172,9 +168,6 @@ canonicalize_ftype(reqtype::AbstractVector{T}, allowedtypes) where {T <: Integer
canonicalize_ftype(reqtype::AbstractVector{Symbol}, allowedtypes) = map(string, reqtype)
canonicalize_ftype(reqtype, allowedtypes) = reqtype

# Keep an unexported function `select` to not break the tutorial
select(; kwargs...) = select_sif_problems(; kwargs...)

"""
build_classification()
Expand Down

0 comments on commit adc4986

Please sign in to comment.