Public API
These functions and types implement the API of DirectSearch.jl.
Problem Configuration
DirectSearch.DSProblem
— TypeDSProblem{T, UT}(N::Int; poll::AbstractPoll=LTMADS{T}(),
search::AbstractSearch=NullSearch(),
objective::Union{Function,Nothing}=nothing,
initial_point::Vector=zeros(T, N),
iteration_limit::Int=1000,
function_evaluation_limit::Int=5000,
sense::ProblemSense=Min,
full_output::Bool=false,
granularity::Vector=zeros(T, N),
min_mesh_size::Union{T,Nothing}=nothing,
min_poll_size::Union{T,Nothing}=nothing,
kwargs...
) where T
Return a problem definition for an N
dimensional problem using numbers of type T
.
poll
and search
specify the poll and search step algorithms to use. The default choices are LTMADS
and NullSearch
respectively.
The problem can contain user-defined parameters that are passed into every objective function evaluation. These parameters will be stored inside a field of type UT
.
DirectSearch.SetObjective
— FunctionSetObjective(p::DSProblem, obj::Function)
Sets the target objective function to solve. obj
should take a vector and return a single cost value.
DirectSearch.SetInitialPoint
— FunctionSetInitialPoint(p::DSProblem{T}, x::Vector{T}) where T
Set the initial incumbent point to x
. This must be of the correct dimension. If using any extreme barrier constraints then it must also satisfy these constraints.
DirectSearch.Optimize!
— FunctionOptimize!(p::DSProblem)
Run the direct search algorithm on problem p
.
p
must have had its initial point and objective function set. If extreme barrier constraints have been set then the initial point must be value for those constraints.
DirectSearch.SetVariableBound
— FunctionSetVariableBound(p::DSProblem{T}, index::Int, l::T, u::T) where T
Set the expected bounds of the variable with index i
to between lower (l
) and upper (u
) values. This does not create a constraint, and is only used for scaling when a variable varies with a significantly different scale to the others.
DirectSearch.SetVariableBounds
— FunctionSetVariableBounds(p::DSProblem{T}, l::Vector{T}, u::Vector{T}) where T
Call SetVariableBound
for each variable. The vectors l
and u
should contain a lower and upper bound for each variable.
DirectSearch.SetGranularity
— FunctionSetGranularity(p::DSProblem{T}, index::Int, granularity::T) where T
Set the granularity of the variable with index i
to granularity
.
SetGranularity(p::DSProblem{T}, granularities)
Set the granularity of multiple variables. The granularities should be provided in granularities
as a collection with key => value
pairs, where the key is the variable index and the value is the granularity.
Examples
julia> p = DSProblem(3; objective=x->sum(x.^2), initial_point=[0.25, 0.1, 1.0]);
julia> granularities = Dict( 1 => 0.1, 2 => 0.2, 3 => 0.3 )
Dict{Int64, Float64} with 3 entries:
2 => 0.2
3 => 0.3
1 => 0.1
julia> SetGranularity(p, granularities)
A vector can also be used to set the granularity, with granularities[index]
setting the granularity for the variable at index
with the granularity granularities[index]
.
julia> p = DSProblem(3; objective=x->sum(x.^2), initial_point=[0.25, 0.1, 1.0]);
julia> granularities = [0.1; 0.2; 0.3]
3-element Vector{Float64}:
0.1
0.2
0.3
julia> SetGranularity(p, granularities)
Missing docstring for SetGranularities
. Check Documenter's build log for details.
DirectSearch.SetSense
— FunctionSetSense(p::DSProblem, sense::ProblemSense )
Set the problem sense. Valid values for sense
are DS.Min
and DS.Max
.
DirectSearch.SetMaxEvals
— FunctionSetMaxEvals(p::DSProblem, max::Bool=true)
Set/unset parallel blackbox evaluations. The number of threads Julia was started with will be used.
Note that using parallel blackbox evaluations will only result in reduced runtime for problems that have long blackbox evaluations.
DirectSearch.SetOpportunisticEvaluation
— FunctionSetOpportunisticEvaluation(p::DSProblem; opportunistic::Bool=true)
Set/unset opportunistic evaluation (enables by default).
When using opportunistic evaluation the first allowable evaluated point with an improved cost is set as the new incumbent solution. If using progressive barrier constraints this point may be infeasible.
Search Stages
DirectSearch.NullSearch
— TypeNullSearch()
Return no trial points for a search stage (ie, skips the search stage from running)
DirectSearch.RandomSearch
— TypeRandomSearch(M::Int)
Return M
randomly chosen trial points from the current mesh.
Poll Stages
DirectSearch.LTMADS
— TypeLTMADS()
Return an empty LTMADS object.
LTMADS is a poll stage that creates a set of directions based on a semi-randomly generated lower triangular matrix. This randomness means that several runs of the algorithm may be needed to find a minimum.
DirectSearch.OrthoMADS
— TypeOrthoMADS()
Return an empty OrthoMADS object. N
must match the dimension of the problem that this stage is being given to.
OrthoMADS uses Halton sequences to generate an orthogonal basis of directiosn for the poll step. This is a deterministic process, unlike (LTMADS
)[@ref].
Constraints
DirectSearch.AddExtremeConstraint
— MethodAddExtremeConstraint(p::AbstractProblem, c::Function
index::CollectionIndex=CollectionIndex(1)
)::ConstraintIndex where T
Register a single function that defines an extreme barrier constraint. Return a constraint index.
The provided function should take a vector input and return a boolean or numeric value indicating if the constraint has been met or not. true
or less than or equal to 0 indicates the constraint has been met. false
or greater than 0 shows the constraint has been violated.
The index
argument can be specified to give a collection to add the constraint to. The specified collection must exist, and must be able to accept extreme barrier constraints. If index
is not specified then it is added to collection 1, the default extreme constraint collection.
DirectSearch.AddExtremeConstraint
— MethodAddExtremeConstraint(p::AbstractProblem, c::Vector{Function}; index::CollectionIndex=CollectionIndex(1))
Register a group of functions that define extreme barrier constraints. Calls AddExtremeConstraint
on each function individually.
DirectSearch.AddProgressiveConstraint
— MethodAddProgressiveConstraint(p::AbstractProblem, c::Function; index::CollectionIndex=CollectionIndex(2))
Register a single function that defines a progressive barrier constraint. Return an index that refers to the constraint.
The provided function should take a vector input and return a numeric value indicating if the constraint has been met or not. Less than or equal to 0 indicates the constraint has been met. 0 shows the constraint has been violated.
The index
argument can be specified to give a collection to add the constraint to. The specified collection must exist, and must be able to accept progressive barrier constraints. If index
is not specified then it is added to collection 2, the default progressive barrier constraint collection.
DirectSearch.AddProgressiveConstraint
— MethodAddProgressiveConstraint(p::AbstractProblem, c::Vector{Function})::Vector{Int}
Register a group of functions that define progressive barrier constraints. Calls AddProgressiveConstraint
on each function individually.
DirectSearch.AddExtremeCollection
— MethodAddExtremeCollection(p::Constraints{FT})::CollectionIndex where {FT<:AbstractFloat}
Instantiate a new constraint collection for extreme constraints. Returns an index that refers to the new collection.
DirectSearch.AddProgressiveCollection
— MethodAddProgressiveCollection(p::Constraints{FT}; h_max=Inf, h_max_update::Function=h_max_update,
aggregator::Function=x->max(0,x)^2)::CollectionIndex where {FT<:AbstractFloat}
Instantiate a new constraint collection within the problem. Returns an index that refers to this new collection.
The default constraint settings match those from Audet & Dennis 2009:
h_max
: Begins as infinity
h_max_update
: Sets h_max to the largest valid h evaluation if an iteration is improving
aggregator
: Creates h as $\sum k(x)$ where $k=\max(0,x)^2$
DirectSearch.DefaultExtremeRef
— ConstantDefaultExtremeRef
The collection index that refers to the default location of extreme barrier constraints.
DirectSearch.DefaultProgressiveRef
— ConstantDefaultProgressiveRef
The collection index that refers to the default location of progressive barrier constraints.
Cache
DirectSearch.CacheLoadJSON
— FunctionCacheLoadJSON(p::AbstractProblem{T}, path::String) where T
Load the costs from the provided JSON file to the cache. path
can be a relative or absolute path and must contain the '.json' extension.
DirectSearch.CacheSaveJSON
— FunctionCacheSaveJSON(p::AbstractProblem{T}, filename::String) where T
Save the costs from the cache to JSON file with the name filename
. Note that the filename should be without a file extension.
DirectSearch.CacheLoadJLD2
— FunctionCacheLoadJLD2(p::AbstractProblem{T}, path::String, dataset::String="cache_costs") where T
Load the costs from the provided JLD2 file and dataset to the cache. path
can be a relative or absolute path and must contain the '.jld2' extension. By default, it loads from the dataset named 'cache_costs'.
DirectSearch.CacheSaveJLD2
— FunctionCacheSaveJLD2(p::AbstractProblem{T}, filename::String, dataset::String="cache_costs") where T
Save the costs from the cache to a JLD2 file with the name filename
and to the dataset dataset
. The default dataset is named 'cache_costs'. It is possible to write to multiple datasets in one file, however, datasets cannot be overwritten.
Stopping Conditions
DirectSearch.AddStoppingCondition
— FunctionAddStoppingCondition(p::DSProblem, c::T) where T <: AbstractStoppingCondition
Add the stopping condition c
to the problem p
.
DirectSearch.SetIterationLimit
— FunctionSetIterationLimit(p::DSProblem, i::Int)
Set the maximum number of iterations to i
.
DirectSearch.BumpIterationLimit
— FunctionBumpIterationLimit(p::DSProblem, i::Int)
Increase the iteration limit by i
.
DirectSearch.SetFunctionEvaluationLimit
— FunctionSetFunctionEvaluationLimit(p::DSProblem, i::Int)
Set the maximum number of function evaluations to i
.
DirectSearch.BumpFunctionEvaluationLimit
— FunctionBumpFunctionEvaluationLimit(p::DSProblem, i::Int)
Increase the function evaluation limit by i
.
DirectSearch.SetMinimumMeshSize
— FunctionSetMinimumMeshSize(p::DSProblem{T}, i::T) where T
Set the minimum mesh size for continuous variables.
DirectSearch.SetMinimumPollSize
— FunctionSetMinimumPollSize(p::DSProblem{T}, i::T) where T
Set the minimum poll size for continuous variables.
Reporting
DirectSearch.ReportConfig
— FunctionReportConfig(p::DSProblem)
Print the configuration options currently used by p
.
DirectSearch.ReportStatus
— FunctionReportStatus(p::DSProblem)
Print the current non-problem-specific status information of p
.
DirectSearch.ReportProblem
— FunctionReportProblem(p::DSProblem)
Print the current problem specific status information of p
.
Base.print
— FunctionBase.print(p::DSProblem)
Print the output of ReportConfig
, ReportStatus
, and ReportProblem
in a list.