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.Dict_VecPair Type
const Dict_VecPair = Union{<:AbstractDict, <:AbstractVector{<:Pair}}Alias for a dictionary or vector of pairs.
Represents solver settings as either a dictionary mapping constraint attributes to values, or a vector of pairs where the first element is a constraint attribute and the second is its value. Used for passing attribute settings to JuMP solvers.
Related
sourcePortfolioOptimisers.SlvSettings Type
const SlvSettings = Union{<:Pair, <:Dict_VecPair}Alias for solver settings used in JuMP-based optimisation.
Represents solver settings as either a single solver attribute, or a collection of solver attributes.
Related
sourcePortfolioOptimisers.Solver Type
struct Solver{__T_name, __T_solver, __T_settings, __T_check_sol, __T_add_bridges} <: AbstractEstimatorContainer 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 logging purposes.solver: Theoptimizer_factoryinset_optimizer.settings: Optional 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.
Constructors
Solver(;
name::Sym_Str = "",
solver::Any = nothing,
settings::Option{<:SlvSettings} = nothing,
check_sol::NamedTuple = (;),
add_bridges::Bool = true
) -> SolverKeywords correspond to the struct's fields.
Validation
- If not
nothing,!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
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
sourcePortfolioOptimisers.AbstractJuMPResult Type
abstract type AbstractJuMPResult <: AbstractResultAbstract supertype for all JuMP-based optimisation result types in PortfolioOptimisers.jl.
All concrete and/or abstract types representing the result of a JuMP model optimisation should be subtypes of AbstractJuMPResult.
Related
sourcePortfolioOptimisers.JuMPResult Type
struct JuMPResult{__T_trials, __T_success} <: AbstractJuMPResultResult 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.
Constructors
JuMPResult(;
trials::AbstractDict,
success::Bool
) -> JuMPResultKeywords correspond to the struct's fields.
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::Dict_VecPair)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