JuMP model optimisation
PortfolioOptimisers.jl is based on JuMP, as such it tries to be as flexible as possible.
These types and functions let us define solver and solution interfaces.
PortfolioOptimisers.DictStrA_VecPairStrA Type
const DictStrA_VecPairStrA = Union{<:AbstractDict{<:AbstractString, <:Any},
<:AbstractVector{<:Pair{<:AbstractString, <:Any}}}Alias for a dictionary or vector of pairs with string keys.
Represents solver settings as either a dictionary mapping strings to values, or a vector of pairs where the first element is a string and the second is any value. Used for passing attribute settings to JuMP solvers.
Related
sourcePortfolioOptimisers.SlvSettings Type
const SlvSettings = Union{<:Pair{<:AbstractString, <:Any}, <:DictStrA_VecPairStrA}Alias for solver settings used in JuMP-based optimisation.
Represents solver settings as either a single pair of string key and value, or as a dictionary/vector of pairs with string keys. Used for passing attribute settings to JuMP solvers.
Related
sourcePortfolioOptimisers.Solver Type
struct Solver{T1, T2, T3, T4, T5} <: AbstractEstimator
name::T1
solver::T2
settings::T3
check_sol::T4
add_bridges::T5
endContainer for configuring a JuMP solver and its settings.
The Solver struct encapsulates all information needed to set up and run a JuMP optimisation, including the solver backend, solver-specific settings, solution checks, and bridge options.
Fields
name: Symbol or string identifier for the solver.solver: Theoptimizer_factoryinset_optimizer.settings: Solver-specific settings used inset_attribute.check_sol: Named tuple of solution for keyword arguments inassert_is_solved_and_feasible.add_bridges: Theadd_bridgeskeyword argument inset_optimizer.
Constructor
Solver(; name::Sym_Str = "", solver::Any = nothing,
settings::Option{<:SlvSettings} = nothing, check_sol::NamedTuple = (;),
add_bridges::Bool = true)Keyword arguments correspond to the fields above.
Validation
settings:Dict_Vec:!isempty(settings).
Examples
julia> Solver()
Solver
name ┼ String: ""
solver ┼ nothing
settings ┼ nothing
check_sol ┼ @NamedTuple{}: NamedTuple()
add_bridges ┴ Bool: trueRelated
sourcePortfolioOptimisers.VecSlv Type
const VecSlv = AbstractVector{<:Solver}Alias for a vector of Solver objects.
Represents a collection of solver configurations to be used in JuMP-based optimisation routines. Enables sequential or fallback solver strategies by passing multiple solver setups.
Related Types
sourcePortfolioOptimisers.Slv_VecSlv Type
const Slv_VecSlv = Union{<:Solver, <:VecSlv}Alias for a single Solver or a vector of Solver objects.
Represents either a single solver configuration or a collection of solver configurations for JuMP-based optimisation routines. Enables flexible dispatch for optimisation functions that accept one or multiple solvers.
Related Types
sourcePortfolioOptimisers.AbstractJuMPResult Type
abstract type AbstractJuMPResult <: AbstractResult endAbstract supertype for all JuMP-based optimisation result types in PortfolioOptimisers.jl.
All concrete types representing the result of a JuMP model optimisation should subtype AbstractJuMPResult. This enables a consistent interface for handling solver results throughout the package.
Related
sourcePortfolioOptimisers.JuMPResult Type
struct JuMPResult{T1, T2} <: AbstractJuMPResult
trials::T1
success::T2
endResult type for JuMP model optimisation.
The JuMPResult struct records the outcome of a JuMP optimisation, including trial errors and success status.
Fields
trials: Dictionary of solver trials and errors.success: Boolean indicating whether optimisation succeeded.
Constructor
JuMPResult(; trials::AbstractDict, success::Bool)Keyword arguments correspond to the fields above.
Examples
julia> JuMPResult(; trials = Dict(:HiGHS => Dict(:optimize! => "error")), success = true)
JuMPResult
trials ┼ Dict{Symbol, Dict{Symbol, String}}: Dict(:HiGHS => Dict(:optimize! => "error"))
success ┴ Bool: trueRelated
sourcePortfolioOptimisers.set_solver_attributes Function
set_solver_attributes(args...)Set solver attributes for a JuMP model.
This is a generic fallback that does nothing if no model or settings are provided.
Arguments
args...: Arguments (ignored).
Returns
nothing.
set_solver_attributes(model::JuMP.Model, settings::DictStrA_VecPairStrA)Set multiple solver attributes on a JuMP model.
Iterates over the provided settings and applies each as a solver attribute.
Arguments
model: JuMP model.settings: Dictionary or vector of pairs of solver settings.
Returns
nothing.
Related
sourceset_solver_attributes(model::JuMP.Model, settings::Pair)Set a single solver attribute on a JuMP model.
Arguments
model: JuMP model.settings: Pair of attribute name and value.
Returns
nothing.
Related
sourcePortfolioOptimisers.optimise_JuMP_model! Function
optimise_JuMP_model!(model::JuMP.Model, slv::Slv_VecSlv)Attempt to optimise a JuMP model using one or more configured solvers.
Tries each solver in order, applying settings and checking for solution feasibility. Returns a JuMPResult with trial errors and success status.
Arguments
model: JuMP model to optimise.slv: SingleSolveror vector ofSolverobjects.
Returns
res::JuMPResult: Result object containing trial errors and success flag.
Details
For each solver, sets the optimizer and attributes, runs
JuMP.optimize!, and checks solution feasibility.If a solver fails, records the error and tries the next.
Stops at the first successful solution.
Related
source