Skip to content
11

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
julia
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

source
PortfolioOptimisers.SlvSettings Type
julia
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

source
PortfolioOptimisers.Solver Type
julia
struct Solver{T1, T2, T3, T4, T5} <: AbstractEstimator
    name::T1
    solver::T2
    settings::T3
    check_sol::T4
    add_bridges::T5
end

Container 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

Constructor

julia
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
julia> Solver()
Solver
         name ┼ String: ""
       solver ┼ nothing
     settings ┼ nothing
    check_sol ┼ @NamedTuple{}: NamedTuple()
  add_bridges ┴ Bool: true

Related

source
PortfolioOptimisers.VecSlv Type
julia
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

source
PortfolioOptimisers.Slv_VecSlv Type
julia
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

source
PortfolioOptimisers.AbstractJuMPResult Type
julia
abstract type AbstractJuMPResult <: AbstractResult end

Abstract 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

source
PortfolioOptimisers.JuMPResult Type
julia
struct JuMPResult{T1, T2} <: AbstractJuMPResult
    trials::T1
    success::T2
end

Result 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

julia
JuMPResult(; trials::AbstractDict, success::Bool)

Keyword arguments correspond to the fields above.

Examples

julia
julia> JuMPResult(; trials = Dict(:HiGHS => Dict(:optimize! => "error")), success = true)
JuMPResult
   trials ┼ Dict{Symbol, Dict{Symbol, String}}: Dict(:HiGHS => Dict(:optimize! => "error"))
  success ┴ Bool: true

Related

source
PortfolioOptimisers.set_solver_attributes Function
julia
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.
source
julia
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

source
julia
set_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

source
PortfolioOptimisers.optimise_JuMP_model! Function
julia
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: Single Solver or vector of Solver objects.

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