@@ -81,28 +81,63 @@ const DoubleDictInner{F,S,T} = MOI.Utilities.DoubleDicts.DoubleDictInner{F,S,T}
8181include (" parametric_functions.jl" )
8282
8383"""
84- Optimizer{T, OT <: MOI.ModelLike} <: MOI.AbstractOptimizer
84+ Optimizer{T}(
85+ optimizer::Union{MOI.ModelLike,Any};
86+ evaluate_duals::Bool = true,
87+ save_original_objective_and_constraints::Bool = true,
88+ with_bridge_type = nothing,
89+ )
8590
86- Declares a `Optimizer`, which allows the handling of parameters in a
91+ Create an `Optimizer`, which allows the handling of parameters in an
8792optimization model.
8893
94+ If `optimizer` is not a `MOI.ModelLike,` the inner optimizer is constructed
95+ using `MOI.instantiate(optimizer; with_bridge_type)`.
96+
97+ The `{T}` type parameter is optional; it defaults to `Float64`.
98+
8999## Keyword arguments
90100
91- - `evaluate_duals::Bool`: If `true`, evaluates the dual of parameters. Users might want to set it to `false`
92- to increase performance when the duals of parameters are not necessary. Defaults to `true`.
101+ - `evaluate_duals::Bool`: If `true`, evaluates the dual of parameters. Set it to
102+ `false` to increase performance when the duals of parameters are not
103+ necessary. Defaults to `true`.
93104
94- - `save_original_objective_and_constraints`: If `true` saves the orginal function and set of the constraints
95- as well as the original objective function inside [`Optimizer`](@ref). This is useful for printing the model
96- but greatly increases the memory footprint. Users might want to set it to `false` to increase performance
97- in applications where you don't need to query the original expressions provided to the model in constraints
98- or in the objective. Note that this might break printing or queries such as `MOI.get(model, MOI.ConstraintFunction(), c)`.
99- Defaults to `true`.
105+ - `save_original_objective_and_constraints`: If `true` saves the orginal
106+ function and set of the constraints as well as the original objective function
107+ inside [`Optimizer`](@ref). This is useful for printing the model but greatly
108+ increases the memory footprint. Users might want to set it to `false` to
109+ increase performance in applications where you don't need to query the
110+ original expressions provided to the model in constraints or in the objective.
111+ Note that this might break printing or queries such as
112+ `MOI.get(model, MOI.ConstraintFunction(), c)`. Defaults to `true`.
113+
114+ - `with_bridge_type`: this is ignroed if `optimizer::MOI.ModelLike`, otherwise
115+ it is passed to `MOI.instantiate`.
100116
101117## Example
102118
103119```julia-repl
104- julia> ParametricOptInterface.Optimizer(HiGHS.Optimizer())
105- ParametricOptInterface.Optimizer{Float64,HiGHS.Optimizer}
120+ julia> import ParametricOptInterface as POI
121+
122+ julia> import HiGHS
123+
124+ julia> POI.Optimizer(HiGHS.Optimizer(); evaluate_duals = true)
125+ ParametricOptInterface.Optimizer{Float64, HiGHS.Optimizer}
126+ ├ ObjectiveSense: FEASIBILITY_SENSE
127+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
128+ ├ NumberOfVariables: 0
129+ └ NumberOfConstraints: 0
130+
131+ julia> POI.Optimizer(
132+ HiGHS.Optimizer;
133+ with_bridge_type = Float64,
134+ evaluate_duals = false,
135+ )
136+ ParametricOptInterface.Optimizer{Float64, MOIB.LazyBridgeOptimizer{HiGHS.Optimizer}}
137+ ├ ObjectiveSense: FEASIBILITY_SENSE
138+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
139+ ├ NumberOfVariables: 0
140+ └ NumberOfConstraints: 0
106141```
107142"""
108143mutable struct Optimizer{T,OT<: MOI.ModelLike } <: MOI.AbstractOptimizer
@@ -183,11 +218,12 @@ mutable struct Optimizer{T,OT<:MOI.ModelLike} <: MOI.AbstractOptimizer
183218
184219 # extension data
185220 ext:: Dict{Symbol,Any}
221+
186222 function Optimizer {T} (
187223 optimizer:: OT ;
188224 evaluate_duals:: Bool = true ,
189225 save_original_objective_and_constraints:: Bool = true ,
190- ) where {T,OT}
226+ ) where {T,OT<: MOI.ModelLike }
191227 return new {T,OT} (
192228 optimizer,
193229 MOI. Utilities. CleverDicts. CleverDict {ParameterIndex,T} (
@@ -251,7 +287,20 @@ mutable struct Optimizer{T,OT<:MOI.ModelLike} <: MOI.AbstractOptimizer
251287 end
252288end
253289
254- Optimizer (args... ; kws... ) = Optimizer {Float64} (args... ; kws... )
290+ Optimizer (arg; kwargs... ) = Optimizer {Float64} (arg; kwargs... )
291+
292+ function Optimizer {T} (
293+ optimizer_fn;
294+ with_bridge_type = nothing ,
295+ kwargs... ,
296+ ) where {T}
297+ inner = MOI. instantiate (optimizer_fn; with_bridge_type)
298+ if ! MOI. supports_incremental_interface (inner)
299+ cache = MOI. default_cache (inner, T)
300+ inner = MOI. Utilities. CachingOptimizer (cache, inner)
301+ end
302+ return Optimizer {T} (inner; kwargs... )
303+ end
255304
256305function _next_parameter_index! (model:: Optimizer )
257306 return model. last_parameter_index_added += 1
0 commit comments