Models
Attribute interface
MathOptInterface.is_set_by_optimize
— Functionis_set_by_optimize(::AnyAttribute)
Return a Bool
indicating whether the value of the attribute is set during an optimize!
call, that is, the attribute is used to query the result of the optimization.
If an attribute can be set by the user, define is_copyable
instead.
An attribute cannot be both is_copyable
and is_set_by_optimize
.
Default fallback
This function returns false
by default so it should be implemented for attributes that are set by optimize!
.
Undefined behavior
Querying the value of the attribute that is_set_by_optimize
before a call to optimize!
is undefined and depends on solver-specific behavior.
Example
julia> import MathOptInterface as MOI
julia> MOI.is_set_by_optimize(MOI.ObjectiveValue())
true
julia> MOI.is_set_by_optimize(MOI.VariableName())
false
MathOptInterface.is_copyable
— Functionis_copyable(::AnyAttribute)
Return a Bool
indicating whether the value of the attribute may be copied during copy_to
using set
.
If an attribute is_copyable
, then it cannot be modified by the optimizer, and get
must always return the value that was set
by the user.
If an attribute is the result of an optimization, define is_set_by_optimize
instead.
An attribute cannot be both is_set_by_optimize
and is_copyable
.
Default fallback
By default is_copyable(attr)
returns !is_set_by_optimize(attr)
, which is most probably true
.
If an attribute should not be copied, define is_copyable(::MyAttribute) = false
.
MathOptInterface.get
— Functionget(optimizer::AbstractOptimizer, attr::AbstractOptimizerAttribute)
Return an attribute attr
of the optimizer optimizer
.
get(model::ModelLike, attr::AbstractModelAttribute)
Return an attribute attr
of the model model
.
get(model::ModelLike, attr::AbstractVariableAttribute, v::VariableIndex)
If the attribute attr
is set for the variable v
in the model model
, return its value, return nothing
otherwise. If the attribute attr
is not supported by model
then an error should be thrown instead of returning nothing
.
get(model::ModelLike, attr::AbstractVariableAttribute, v::Vector{VariableIndex})
Return a vector of attributes corresponding to each variable in the collection v
in the model model
.
get(model::ModelLike, attr::AbstractConstraintAttribute, c::ConstraintIndex)
If the attribute attr
is set for the constraint c
in the model model
, return its value, return nothing
otherwise. If the attribute attr
is not supported by model
then an error should be thrown instead of returning nothing
.
get(
model::ModelLike,
attr::AbstractConstraintAttribute,
c::Vector{ConstraintIndex{F,S}},
) where {F,S}
Return a vector of attributes corresponding to each constraint in the collection c
in the model model
.
get(model::ModelLike, ::Type{VariableIndex}, name::String)
If a variable with name name
exists in the model model
, return the corresponding index, otherwise return nothing
. Errors if two variables have the same name.
get(
model::ModelLike,
::Type{ConstraintIndex{F,S}},
name::String,
) where {F,S}
If an F
-in-S
constraint with name name
exists in the model model
, return the corresponding index, otherwise return nothing
. Errors if two constraints have the same name.
get(model::ModelLike, ::Type{ConstraintIndex}, name::String)
If any constraint with name name
exists in the model model
, return the corresponding index, otherwise return nothing
. This version is available for convenience but may incur a performance penalty because it is not type stable. Errors if two constraints have the same name.
MOI.get(b::AbstractBridge, ::MOI.NumberOfVariables)::Int64
Return the number of variables created by the bridge b
in the model.
See also MOI.NumberOfConstraints
.
Implementation notes
- There is a default fallback, so you need only implement this if the bridge adds new variables.
MOI.get(b::AbstractBridge, ::MOI.ListOfVariableIndices)
Return the list of variables created by the bridge b
.
See also MOI.ListOfVariableIndices
.
Implementation notes
- There is a default fallback, so you need only implement this if the bridge adds new variables.
MOI.get(b::AbstractBridge, ::MOI.NumberOfConstraints{F,S})::Int64 where {F,S}
Return the number of constraints of the type F
-in-S
created by the bridge b
.
See also MOI.NumberOfConstraints
.
Implementation notes
- There is a default fallback, so you need only implement this for the constraint types returned by
added_constraint_types
.
MOI.get(b::AbstractBridge, ::MOI.ListOfConstraintIndices{F,S}) where {F,S}
Return a Vector{ConstraintIndex{F,S}}
with indices of all constraints of type F
-in-S
created by the bride b
.
See also MOI.ListOfConstraintIndices
.
Implementation notes
- There is a default fallback, so you need only implement this for the constraint types returned by
added_constraint_types
.
function MOI.get(
model::MOI.ModelLike,
attr::MOI.AbstractConstraintAttribute,
bridge::AbstractBridge,
)
Return the value of the attribute attr
of the model model
for the constraint bridged by bridge
.
MathOptInterface.get!
— Functionget!(output, model::ModelLike, args...)
An in-place version of get
.
The signature matches that of get
except that the result is placed in the vector output
.
MathOptInterface.set
— Functionset(optimizer::AbstractOptimizer, attr::AbstractOptimizerAttribute, value)
Assign value
to the attribute attr
of the optimizer optimizer
.
set(model::ModelLike, attr::AbstractModelAttribute, value)
Assign value
to the attribute attr
of the model model
.
set(model::ModelLike, attr::AbstractVariableAttribute, v::VariableIndex, value)
Assign value
to the attribute attr
of variable v
in model model
.
set(
model::ModelLike,
attr::AbstractVariableAttribute,
v::Vector{VariableIndex},
vector_of_values,
)
Assign a value respectively to the attribute attr
of each variable in the collection v
in model model
.
set(
model::ModelLike,
attr::AbstractConstraintAttribute,
c::ConstraintIndex,
value,
)
Assign a value to the attribute attr
of constraint c
in model model
.
set(
model::ModelLike,
attr::AbstractConstraintAttribute,
c::Vector{ConstraintIndex{F,S}},
vector_of_values,
) where {F,S}
Assign a value respectively to the attribute attr
of each constraint in the collection c
in model model
.
An UnsupportedAttribute
error is thrown if model
does not support the attribute attr
(see supports
) and a SetAttributeNotAllowed
error is thrown if it supports the attribute attr
but it cannot be set.
set(
model::ModelLike,
::ConstraintSet,
c::ConstraintIndex{F,S},
set::S,
) where {F,S}
Change the set of constraint c
to the new set set
which should be of the same type as the original set.
set(
model::ModelLike,
::ConstraintFunction,
c::ConstraintIndex{F,S},
func::F,
) where {F,S}
Replace the function in constraint c
with func
. F
must match the original function type used to define the constraint.
Setting the constraint function is not allowed if F
is VariableIndex
; a SettingVariableIndexNotAllowed
error is thrown instead. This is because, it would require changing the index c
since the index of VariableIndex
constraints must be the same as the index of the variable.
function MOI.set(
model::MOI.ModelLike,
attr::MOI.AbstractConstraintAttribute,
bridge::AbstractBridge,
value,
)
Set the value of the attribute attr
of the model model
for the constraint bridged by bridge
.
MathOptInterface.supports
— Functionsupports(model::ModelLike, sub::AbstractSubmittable)::Bool
Return a Bool
indicating whether model
supports the submittable sub
.
supports(model::ModelLike, attr::AbstractOptimizerAttribute)::Bool
Return a Bool
indicating whether model
supports the optimizer attribute attr
. That is, it returns false
if copy_to(model, src)
shows a warning in case attr
is in the ListOfOptimizerAttributesSet
of src
; see copy_to
for more details on how unsupported optimizer attributes are handled in copy.
supports(model::ModelLike, attr::AbstractModelAttribute)::Bool
Return a Bool
indicating whether model
supports the model attribute attr
. That is, it returns false
if copy_to(model, src)
cannot be performed in case attr
is in the ListOfModelAttributesSet
of src
.
supports(
model::ModelLike,
attr::AbstractVariableAttribute,
::Type{VariableIndex},
)::Bool
Return a Bool
indicating whether model
supports the variable attribute attr
. That is, it returns false
if copy_to(model, src)
cannot be performed in case attr
is in the ListOfVariableAttributesSet
of src
.
supports(
model::ModelLike,
attr::AbstractConstraintAttribute,
::Type{ConstraintIndex{F,S}},
)::Bool where {F,S}
Return a Bool
indicating whether model
supports the constraint attribute attr
applied to an F
-in-S
constraint. That is, it returns false
if copy_to(model, src)
cannot be performed in case attr
is in the ListOfConstraintAttributesSet
of src
.
For all five methods, if the attribute is only not supported in specific circumstances, it should still return true
.
Note that supports
is only defined for attributes for which is_copyable
returns true
as other attributes do not appear in the list of attributes set obtained by ListOfXXXAttributesSet
.
MOI.supports(
model::MOI.ModelLike,
attr::MOI.AbstractConstraintAttribute,
BT::Type{<:AbstractBridge},
)
Return a Bool
indicating whether BT
supports setting attr
to model
.
MathOptInterface.attribute_value_type
— Functionattribute_value_type(attr::AnyAttribute)
Given an attribute attr
, return the type of value expected by get
, or returned by set
.
Notes
- Only implement this if it make sense to do so. If un-implemented, the default is
Any
.
Model interface
MathOptInterface.ModelLike
— TypeModelLike
Abstract supertype for objects that implement the "Model" interface for defining an optimization problem.
MathOptInterface.is_empty
— Functionis_empty(model::ModelLike)
Returns false
if the model
has any model attribute set or has any variables or constraints.
Note that an empty model can have optimizer attributes set.
MathOptInterface.empty!
— Functionempty!(model::ModelLike)
Empty the model, that is, remove all variables, constraints and model attributes but not optimizer attributes.
MathOptInterface.write_to_file
— Functionwrite_to_file(model::ModelLike, filename::String)
Write the current model to the file at filename
.
Supported file types depend on the model type.
MathOptInterface.read_from_file
— Functionread_from_file(model::ModelLike, filename::String)
Read the file filename
into the model model
. If model
is non-empty, this may throw an error.
Supported file types depend on the model type.
Note
Once the contents of the file are loaded into the model, users can query the variables via get(model, ListOfVariableIndices())
. However, some filetypes, such as LP files, do not maintain an explicit ordering of the variables. Therefore, the returned list may be in an arbitrary order.
To avoid depending on the order of the indices, look up each variable index by name using get(model, VariableIndex, "name")
.
MathOptInterface.supports_incremental_interface
— Functionsupports_incremental_interface(model::ModelLike)
Return a Bool
indicating whether model
supports building incrementally via add_variable
and add_constraint
.
The main purpose of this function is to determine whether a model can be loaded into model
incrementally or whether it should be cached and copied at once instead.
MathOptInterface.copy_to
— Functioncopy_to(dest::ModelLike, src::ModelLike)::IndexMap
Copy the model from src
into dest
.
The target dest
is emptied, and all previous indices to variables and constraints in dest
are invalidated.
Returns an IndexMap
object that translates variable and constraint indices from the src
model to the corresponding indices in the dest
model.
Notes
- If a constraint that in
src
is not supported bydest
, then anUnsupportedConstraint
error is thrown. - If an
AbstractModelAttribute
,AbstractVariableAttribute
, orAbstractConstraintAttribute
is set insrc
but not supported bydest
, then anUnsupportedAttribute
error is thrown.
AbstractOptimizerAttribute
s are not copied to the dest
model.
IndexMap
Implementations of copy_to
must return an IndexMap
. For technical reasons, this type is defined in the Utilities submodule as MOI.Utilities.IndexMap
. However, since it is an integral part of the MOI API, we provide MOI.IndexMap
as an alias.
Example
# Given empty `ModelLike` objects `src` and `dest`.
x = add_variable(src)
is_valid(src, x) # true
is_valid(dest, x) # false (`dest` has no variables)
index_map = copy_to(dest, src)
is_valid(dest, x) # false (unless index_map[x] == x)
is_valid(dest, index_map[x]) # true
MathOptInterface.IndexMap
— TypeIndexMap()
The dictionary-like object returned by copy_to
.
IndexMap
Implementations of copy_to
must return an IndexMap
. For technical reasons, the IndexMap
type is defined in the Utilities submodule as MOI.Utilities.IndexMap
. However, since it is an integral part of the MOI API, we provide this MOI.IndexMap
as an alias.
Model attributes
MathOptInterface.AbstractModelAttribute
— TypeAbstractModelAttribute
Abstract supertype for attribute objects that can be used to set or get attributes (properties) of the model.
MathOptInterface.Name
— TypeName()
An AbstractModelAttribute
for the string identifying the model.
It has a default value of ""
if not set.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.Name)::String
MOI.set(::Optimizer, ::MOI.Name, ::String)::Nothing
MOI.supports(::Optimizer, ::MOI.Name)::Bool
MathOptInterface.ObjectiveFunction
— TypeObjectiveFunction{F<:AbstractScalarFunction}()
An AbstractModelAttribute
for the objective function which has a type F<:AbstractScalarFunction
.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ObjectiveFunction{F},
)::F where {F<:MOI.AbstractFunction}
MOI.set(
::Optimizer,
::MOI.ObjectiveFunction{F},
::F,
)::F where {F<:MOI.AbstractFunction}
MOI.supports(::Optimizer, ::MOI.ObjectiveFunction{<:MOI.AbstractFunction})::Bool
When implementing get
, F
may to be equivalent but not necessarily identical to the function type set by the user. If the objective function cannot be converted to F
, an InexactError
must be thrown.
MathOptInterface.ObjectiveFunctionType
— TypeObjectiveFunctionType()
An AbstractModelAttribute
for the type F
of the objective function set using the ObjectiveFunction{F}
attribute.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ObjectiveFunctionType,
)::Type{<:MOI.AbstractFunction}
They should not implement set
or supports
.
Example
julia> import MathOptInterface as MOI
julia> model = MOI.Utilities.Model{Float64}();
julia> x = MOI.add_variable(model)
MOI.VariableIndex(1)
julia> MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(), x)
julia> MOI.get(model, MOI.ObjectiveFunctionType())
MathOptInterface.VariableIndex
MathOptInterface.ObjectiveSense
— TypeObjectiveSense()
An AbstractModelAttribute
for the objective sense of the objective function, which must be an OptimizationSense
.
The default is FEASIBILITY_SENSE
.
Interaction with ObjectiveFunction
Setting the sense to FEASIBILITY_SENSE
unsets the ObjectiveFunction
attribute. That is, if you first set ObjectiveFunction
and then set ObjectiveSense
to be FEASIBILITY_SENSE
, no objective function will be passed to the solver.
In addition, some reformulations of ObjectiveFunction
via bridges rely on the value of ObjectiveSense
. Therefore, you should set ObjectiveSense
before setting ObjectiveFunction
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.ObjectiveSense)::MOI.OptimizationSense
MOI.set(::Optimizer, ::MOI.ObjectiveSense, ::MOI.OptimizationSense)::Nothing
MOI.supports(::Optimizer, ::MOI.ObjectiveSense)::Bool
MathOptInterface.OptimizationSense
— TypeOptimizationSense
An Enum for the value of the ObjectiveSense
attribute.
Values
The goal is to minimize the objective function.
The goal is to maximize the objective function.
The model does not have an objective function.
MathOptInterface.MIN_SENSE
— ConstantMIN_SENSE::OptimizationSense
An instance of the OptimizationSense
enum.
About
The goal is to minimize the objective function.
MathOptInterface.MAX_SENSE
— ConstantMAX_SENSE::OptimizationSense
An instance of the OptimizationSense
enum.
About
The goal is to maximize the objective function.
MathOptInterface.FEASIBILITY_SENSE
— ConstantFEASIBILITY_SENSE::OptimizationSense
An instance of the OptimizationSense
enum.
About
The model does not have an objective function.
MathOptInterface.NumberOfVariables
— TypeNumberOfVariables()
An AbstractModelAttribute
for the number of variables in the model.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.NumberOfVariables)::Int64
MathOptInterface.ListOfVariableIndices
— TypeListOfVariableIndices()
An AbstractModelAttribute
for querying the Vector{MOI.VariableIndex}
of all [MOI.VariableIndex
] present in the model.
Order
The variables must be returned in the order in which they were added to the model.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.ListOfVariableIndices)::Vector{MOI.VariableIndex}
MathOptInterface.ListOfConstraintTypesPresent
— TypeListOfConstraintTypesPresent()
An AbstractModelAttribute
for the list of tuples of the form (F, S)
, indicating that the attribute NumberOfConstraints{F,S}
has a value greater than zero.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ListOfConstraintTypesPresent,
)::Vector{Tuple{Type,Type}}
MathOptInterface.NumberOfConstraints
— TypeNumberOfConstraints{F,S}()
An AbstractModelAttribute
for querying the number of constraints of the type F
-in-S
present in the model.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.NumberOfConstraints{F,S},
)::Int64 where {F<:MOI.AbstractFunction,MOI.AbstractSet}
MathOptInterface.ListOfConstraintIndices
— TypeListOfConstraintIndices{F,S}()
An AbstractModelAttribute
for the Vector{MOI.ConstraintIndex{F,S}}
of all constraint indices of type F
-in-S
in the model.
Order
The constraints must be returned in the order in which they were added to the model.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ListOfConstraintIndices{F,S},
)::Vector{MOI.ConstraintIndex{F,S}} where {F<:MOI.AbstractFunction,MOI.AbstractSet}
MathOptInterface.ListOfOptimizerAttributesSet
— TypeListOfOptimizerAttributesSet()
An AbstractOptimizerAttribute
for the Vector{AbstractOptimizerAttribute}
of all optimizer attributes that were set.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ListOfOptimizerAttributesSet,
)::Vector{MOI.AbstractOptimizerAttribute}
MathOptInterface.ListOfModelAttributesSet
— TypeListOfModelAttributesSet()
An AbstractModelAttribute
for the Vector{AbstractModelAttribute}
of all model attributes attr
such that:
is_copyable(attr)
returnstrue
, and- the attribute was set to the model
MathOptInterface.ListOfVariableAttributesSet
— TypeListOfVariableAttributesSet()
An AbstractModelAttribute
for the Vector{AbstractVariableAttribute}
of all variable attributes attr
such that:
is_copyable(attr)
returnstrue
- the attribute was set for at least one variable in the model
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ListOfVariableAttributesSet,
)::Vector{MOI.AbstractVariableAttribute}
MathOptInterface.ListOfVariablesWithAttributeSet
— TypeListOfVariablesWithAttributeSet(attr::AbstractVariableAttribute)
An AbstractModelAttribute
for the Vector{MOI.VariableIndex}
of all variables with the attribute attr
set.
The returned list may not be minimal, so some elements may have their default value set.
Note
This is an optional attribute to implement. The default fallback is to get ListOfVariableIndices
.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ListOfVariablesWithAttributeSet{<:MOI.AbstractVariableAttribute},
)::Vector{MOI.VarialbeIndex}
MathOptInterface.ListOfConstraintAttributesSet
— TypeListOfConstraintAttributesSet{F, S}()
An AbstractModelAttribute
for the Vector{AbstractConstraintAttribute}
of all constraint attributes attr
such that:
is_copyable(attr)
returnstrue
and- the attribute was set to
F
-in-S
constraints.
Note
The attributes ConstraintFunction
and ConstraintSet
should not be included in the list even if then have been set with set
.
MathOptInterface.ListOfConstraintsWithAttributeSet
— TypeListOfConstraintsWithAttributeSet{F,S}(attr:AbstractConstraintAttribute)
An AbstractModelAttribute
for the Vector{ConstraintIndex{F,S}}
of all constraints with the attribute attr
set.
The returned list may not be minimal, so some elements may have their default value set.
Note
This is an optional attribute to implement. The default fallback is to get ListOfConstraintIndices
.
MathOptInterface.UserDefinedFunction
— TypeUserDefinedFunction(name::Symbol, arity::Int) <: AbstractModelAttribute
Set this attribute to register a user-defined function by the name of name
with arity
arguments.
Once registered, name
will appear in ListOfSupportedNonlinearOperators
.
You cannot register multiple UserDefinedFunction
s with the same name
but different arity
.
Value type
The value to be set is a tuple containing one, two, or three functions to evaluate the function, the first-order derivative, and the second-order derivative respectively. Both derivatives are optional, but if you pass the second-order derivative you must also pass the first-order derivative.
For univariate functions with arity == 1
, the functions in the tuple must have the form:
f(x::T)::T
: returns the value of the function atx
∇f(x::T)::T
: returns the first-order derivative off
with respect tox
∇²f(x::T)::T
: returns the second-order derivative off
with respect tox
.
For multivariate functions with arity > 1
, the functions in the tuple must have the form:
f(x::T...)::T
: returns the value of the function atx
∇f(g::AbstractVector{T}, x::T...)::Nothing
: fills the components ofg
, withg[i]
being the first-order partial derivative off
with respect tox[i]
∇²f(H::AbstractMatrix{T}, x::T...)::Nothing
: fills the non-zero components ofH
, withH[i, j]
being the second-order partial derivative off
with respect tox[i]
and thenx[j]
.H
is initialized to the zero matrix, so you do not need to set any zero elements.
Example
julia> import MathOptInterface as MOI
julia> f(x, y) = x^2 + y^2
f (generic function with 1 method)
julia> function ∇f(g, x, y)
g .= 2 * x, 2 * y
return
end
∇f (generic function with 1 method)
julia> function ∇²f(H, x...)
H[1, 1] = H[2, 2] = 2.0
return
end
∇²f (generic function with 1 method)
julia> model = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}());
julia> MOI.set(model, MOI.UserDefinedFunction(:f, 2), (f,))
julia> MOI.set(model, MOI.UserDefinedFunction(:g, 2), (f, ∇f))
julia> MOI.set(model, MOI.UserDefinedFunction(:h, 2), (f, ∇f, ∇²f))
julia> x = MOI.add_variables(model, 2)
2-element Vector{MathOptInterface.VariableIndex}:
MOI.VariableIndex(1)
MOI.VariableIndex(2)
julia> MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
julia> obj_f = MOI.ScalarNonlinearFunction(:f, Any[x[1], x[2]])
f(MOI.VariableIndex(1), MOI.VariableIndex(2))
julia> MOI.set(model, MOI.ObjectiveFunction{typeof(obj_f)}(), obj_f)
julia> print(model)
Minimize ScalarNonlinearFunction:
f(v[1], v[2])
Subject to:
MathOptInterface.ListOfSupportedNonlinearOperators
— TypeListOfSupportedNonlinearOperators() <: AbstractModelAttribute
When queried with get
, return a Vector{Symbol}
listing the operators supported by the model. These operators may appear in the head
field of ScalarNonlinearFunction
.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ListOfSupportedNonlinearOperators,
)::Vector{Symbol}
Optimizer interface
MathOptInterface.AbstractOptimizer
— TypeAbstractOptimizer <: ModelLike
Abstract supertype for objects representing an instance of an optimization problem tied to a particular solver. This is typically a solver's in-memory representation. In addition to ModelLike
, AbstractOptimizer
objects let you solve the model and query the solution.
MathOptInterface.OptimizerWithAttributes
— Typestruct OptimizerWithAttributes
optimizer_constructor
params::Vector{Pair{AbstractOptimizerAttribute,<:Any}}
end
Object grouping an optimizer constructor and a list of optimizer attributes. Instances are created with instantiate
.
MathOptInterface.optimize!
— Functionoptimize!(optimizer::AbstractOptimizer)
Optimize the problem contained in optimizer
.
Before calling optimize!
, the problem should first be constructed using the incremental interface (see supports_incremental_interface
) or copy_to
.
MathOptInterface.optimize!
— Methodoptimize!(dest::AbstractOptimizer, src::ModelLike)::Tuple{IndexMap,Bool}
A "one-shot" call that copies the problem from src
into dest
and then uses dest
to optimize the problem.
Returns a tuple of an IndexMap
and a Bool
copied
.
- The
IndexMap
object translates variable and constraint indices from thesrc
model to the corresponding indices in thedest
optimizer. Seecopy_to
for details. - If
copied == true
,src
was copied todest
and then cached, allowing incremental modification if supported by the solver. - If
copied == false
, a cache of the model was not kept indest
. Therefore, only the solution information (attributes for whichis_set_by_optimize
is true) is available to query.
The main purpose of optimize!
method with two arguments is for use in Utilities.CachingOptimizer
.
Relationship to the single-argument optimize!
The default fallback of optimize!(dest::AbstractOptimizer, src::ModelLike)
is
function optimize!(dest::AbstractOptimizer, src::ModelLike)
index_map = copy_to(dest, src)
optimize!(dest)
return index_map, true
end
Therefore, subtypes of AbstractOptimizer
should either implement this two-argument method, or implement both copy_to(::Optimizer, ::ModelLike)
and optimize!(::Optimizer)
.
MathOptInterface.instantiate
— Functioninstantiate(
optimizer_constructor,
with_cache_type::Union{Nothing,Type} = nothing,
with_bridge_type::Union{Nothing,Type} = nothing,
)
Create an instance of an optimizer by either:
- calling
optimizer_constructor.optimizer_constructor()
and setting the parameters inoptimizer_constructor.params
ifoptimizer_constructor
is aOptimizerWithAttributes
- calling
optimizer_constructor()
ifoptimizer_constructor
is callable.
withcachetype
If with_cache_type
is not nothing
, then the optimizer is wrapped in a Utilities.CachingOptimizer
to store a cache of the model. This is most useful if the optimizer you are constructing does not support the incremental interface (see supports_incremental_interface
).
withbridgetype
If with_bridge_type
is not nothing
, the optimizer is wrapped in a Bridges.full_bridge_optimizer
, enabling all the bridges defined in the MOI.Bridges submodule with coefficient type with_bridge_type
.
In addition, if the optimizer created by optimizer_constructor
does not support the incremental interface (see supports_incremental_interface
), then, irrespective of with_cache_type
, the optimizer is wrapped in a Utilities.CachingOptimizer
to store a cache of the bridged model.
If with_cache_type
and with_bridge_type
are both not nothing
, then they must be the same type.
MathOptInterface.default_cache
— Functiondefault_cache(optimizer::ModelLike, ::Type{T}) where {T}
Return a new instance of the default model type to be used as cache for optimizer
in a Utilities.CachingOptimizer
for holding constraints of coefficient type T
. By default, this returns Utilities.UniversalFallback(Utilities.Model{T}())
. If copying from a instance of a given model type is faster for optimizer
then a new method returning an instance of this model type should be defined.
Optimizer attributes
MathOptInterface.AbstractOptimizerAttribute
— TypeAbstractOptimizerAttribute
Abstract supertype for attribute objects that can be used to set or get attributes (properties) of the optimizer.
Notes
The difference between AbstractOptimizerAttribute
and AbstractModelAttribute
lies in the behavior of is_empty
, empty!
and copy_to
. Typically optimizer attributes affect only how the model is solved.
MathOptInterface.SolverName
— TypeSolverName()
An AbstractOptimizerAttribute
for the string identifying the solver.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.SolverName)::String
MathOptInterface.SolverVersion
— TypeSolverVersion()
An AbstractOptimizerAttribute
for the string identifying the version of the solver.
Versioning systems
For solvers supporting semantic versioning, the SolverVersion
should be a string of the form "vMAJOR.MINOR.PATCH", so that it can be converted to a Julia VersionNumber
(for example, `VersionNumber("v1.2.3")).
We do not require Semantic Versioning because some solvers use alternate versioning systems. For example, CPLEX uses Calendar Versioning, so SolverVersion
will return a string like "202001"
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.SolverVersion)::String
MathOptInterface.Silent
— TypeSilent()
An AbstractOptimizerAttribute
for silencing the output of an optimizer.
When set
to true
, this attribute takes precedence over any other attribute controlling verbosity and requires the optimizer to produce no output.
The default value is false
which has no effect. In this case the verbosity is controlled by other optimizer-specific attributes.
Value and default
The provided value must be a Bool
.
The default value is false
.
Note
Every optimizer should have verbosity on by default. For instance, if a solver has a solver-specific log level attribute, the MOI implementation should set it to 1
by default. If the user sets Silent
to true
, then the log level should be set to 0
, even if the user specifically sets a value of log level. If the value of Silent
is false
then the log level set to the solver is the value given by the user for this solver-specific parameter or 1
if none is given.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.Silent)::Bool
MOI.set(::Optimizer, ::MOI.Silent, ::Bool)::Nothing
MOI.supports(::Optimizer, ::MOI.Silent)::Bool
MathOptInterface.TimeLimitSec
— TypeTimeLimitSec()
An AbstractOptimizerAttribute
for setting a time limit (in seconds) for a call to optimize!
.
Value and default
The provided limit must be a Union{Nothing,Real}
.
When set
to nothing
, it deactivates the time limit.
The default value is nothing
.
TerminationStatus
The optimizer may stop when the SolveTimeSec
is larger than the TimeLimitSec
. If stopped because of this limit, the TerminationStatus
must be TIME_LIMIT
.
Note that most optimizers do not strictly respect a time limit. Instead, they terminate at the first convenient time after the time limit has been exceeded. Thus, you may find that the SolveTimeSec
exceeds the TimeLimitSec
by a few seconds.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.TimeLimitSec)::Union{Nothing,Float64}
MOI.set(::Optimizer, ::MOI.TimeLimitSec, ::Union{Nothing,Real})::Nothing
MOI.supports(::Optimizer, ::MOI.TimeLimitSec)::Bool
MathOptInterface.ObjectiveLimit
— TypeObjectiveLimit()
An AbstractOptimizerAttribute
for setting a limit on the objective value.
Value and default
The provided limit must be a Union{Nothing,Real}
.
When set
to nothing
, the limit reverts to the solver's default.
The default value is nothing
.
TerminationStatus
The solver may stop when the ObjectiveValue
is better (lower for minimization, higher for maximization) than the ObjectiveLimit
. If stopped, because of this limit, the TerminationStatus
should be OBJECTIVE_LIMIT
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.ObjectiveLimit)::Union{Nothing,Float64}
MOI.set(::Optimizer, ::MOI.ObjectiveLimit, ::Union{Nothing,Real})::Nothing
MOI.supports(::Optimizer, ::MOI.ObjectiveLimit)::Bool
MathOptInterface.SolutionLimit
— TypeSolutionLimit()
An AbstractOptimizerAttribute
for setting a limit on the number of available feasible solutions.
Value and default
The provided limit must be a Union{Nothing,Int}
.
When set
to nothing
, the limit reverts to the solver's default.
The default value is nothing
.
Termination criteria
The solver may stop when the ResultCount
is larger than or equal to the SolutionLimit
. If stopped because of this attribute, the TerminationStatus
must be SOLUTION_LIMIT
.
Solution quality
The quality of the available solutions is solver-dependent. The set of resulting solutions is not guaranteed to contain an optimal solution.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.SolutionLimit)::Union{Nothing,Int}
MOI.set(::Optimizer, ::MOI.SolutionLimit, ::Union{Nothing,Int})::Nothing
MOI.supports(::Optimizer, ::MOI.SolutionLimit)::Bool
MathOptInterface.NodeLimit
— TypeNodeLimit()
An AbstractOptimizerAttribute
for setting a limit on the number of branch-and-bound nodes explored by a mixed-integer program (MIP) solver.
Value and default
The provided limit must be a Union{Nothing,Int}
.
When set
to nothing
, the limit reverts to the solver's default.
The default value is nothing
.
Termination criteria
The solver may stop when the NodeCount
is larger than or equal to the NodeLimit
. If stopped because of this attribute, the TerminationStatus
must be NODE_LIMIT
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.NodeLimit)::Union{Nothing,Int}
MOI.set(::Optimizer, ::MOI.NodeLimit, ::Union{Nothing,Int})::Nothing
MOI.supports(::Optimizer, ::MOI.NodeLimit)::Bool
MathOptInterface.RawOptimizerAttribute
— TypeRawOptimizerAttribute(name::String)
An AbstractOptimizerAttribute
for the solver-specific parameter identified by name
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.RawOptimizerAttribute)::Any
MOI.set(::Optimizer, ::MOI.RawOptimizerAttribute, ::Any)::Nothing
MOI.supports(::Optimizer, ::MOI.RawOptimizerAttribute)::Bool
MathOptInterface.NumberOfThreads
— TypeNumberOfThreads()
An AbstractOptimizerAttribute
for setting the number of threads used for an optimization.
Value and default
The provided value must be nothing
or a positive Int
.
When set
to nothing
, the value reverts to the solver's default.
The default value is nothing
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.NumberOfThreads)::Union{Nothing,Int}
MOI.set(::Optimizer, ::MOI.NumberOfThreads, ::Union{Nothing,Int})::Nothing
MOI.supports(::Optimizer, ::MOI.NumberOfThreads)::Bool
MathOptInterface.RawSolver
— TypeRawSolver()
An AbstractModelAttribute
for the object that may be used to access a solver-specific API for this optimizer.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.RawSolver)::Any
MathOptInterface.AbsoluteGapTolerance
— TypeAbsoluteGapTolerance()
An AbstractOptimizerAttribute
for setting the absolute gap tolerance for an optimization.
Definition
The mathematical definition of "absolute gap" and its allowed range are solver-dependent. However, most solvers that implement this attribute will stop once $|f - b| ≤ g_{abs}$, where $b$ is the best bound, $f$ is the best feasible objective value, and $g_{abs}$ is the absolute gap.
Value and default
The provided value must be a Union{Nothing,Float64}
.
When set to nothing
, the limit reverts to the solver's default.
TerminationStatus
The optimizer may stop when the absolute difference between ObjectiveValue
and ObjectiveBound
is smaller than the AbsoluteGapTolerance
. If stopped because of this limit, the TerminationStatus
may be OPTIMAL
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.AbsoluteGapTolerance)::Union{Nothing,Float64}
MOI.set(
::Optimizer,
::MOI.AbsoluteGapTolerance,
::Union{Nothing,Float64},
)::Nothing
MOI.supports(::Optimizer, ::MOI.AbsoluteGapTolerance)::Bool
MathOptInterface.RelativeGapTolerance
— TypeRelativeGapTolerance()
An AbstractOptimizerAttribute
for setting the relative gap tolerance for an optimization.
Definition
The mathematical definition of "relative gap" and its allowed range are solver-dependent. Typically, solvers expect a value between 0.0
and 1.0
.
Value and default
The provided value must be a Union{Nothing,Float64}
.
When set to nothing
, the limit reverts to the solver's default.
TerminationStatus
The optimizer may stop when the RelativeGap
is smaller than the RelativeGapTolerance
. If stopped because of this limit, the TerminationStatus
may be OPTIMAL
.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.RelativeGapTolerance)::Union{Nothing,Float64}
MOI.set(
::Optimizer,
::MOI.RelativeGapTolerance,
::Union{Nothing,Float64},
)::Nothing
MOI.supports(::Optimizer, ::MOI.RelativeGapTolerance)::Bool
MathOptInterface.AutomaticDifferentiationBackend
— TypeAutomaticDifferentiationBackend() <: AbstractOptimizerAttribute
An AbstractOptimizerAttribute
for setting the automatic differentiation backend used by the solver.
The value must be a subtype of Nonlinear.AbstractAutomaticDifferentiation
.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.AutomaticDifferentiationBackend,
)::MOI.Nonlinear.AbstractAutomaticDifferentiation
MOI.set(
::Optimizer,
::MOI.AutomaticDifferentiationBackend,
::MOI.Nonlinear.AbstractAutomaticDifferentiation,
)::Nothing
MOI.supports(::Optimizer, ::MOI.AutomaticDifferentiationBackend)::Bool
List of attributes useful for optimizers
MathOptInterface.TerminationStatus
— TypeTerminationStatus()
An AbstractModelAttribute
for the TerminationStatusCode
explaining why the optimizer stopped.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.TerminationStatus)::MOI.TerminationStatusCode
MathOptInterface.TerminationStatusCode
— TypeTerminationStatusCode
An Enum of possible values for the TerminationStatus
attribute.
This attribute explains why the optimizer stopped executing in the most recent call to optimize!
.
Values
The algorithm has not started.
The algorithm found a globally optimal solution.
The algorithm proved that no primal feasible solution exists.
The algorithm proved that no dual feasible solution exists.
To check if the primal problem is feasible, set the objective sense to FEASIBILITY_SENSE
and re-solve the problem.
If a primal feasible point does not exist, the original problem is both primal and dual infeasible.
If a primal feasible solution exists, this status typically implies that the problem is unbounded, with some technical exceptions (for example, if the problem is a conic optimization problem in which strong duality does not hold).
The technical exceptions do not apply to linear programs. The combination of DUAL_INFEASIBLE
and a primal feasible point means that the primal linear program is unbounded.
The algorithm converged to a stationary point, local optimal solution, could not find directions for improvement, or otherwise completed its search without global guarantees.
The algorithm converged to an infeasible point or otherwise completed its search without finding a feasible solution, without guarantees that no feasible solution exists.
If you know a primal feasible solution exists, use VariablePrimalStart
to provide a feasible starting point to the solver.
The algorithm stopped because it proved that the problem is infeasible or unbounded, without distinguishing between the two cases.
To distinguish between the two cases, set the objective sense to FEASIBILITY_SENSE
and re-solve the problem. If a primal feasible point exists, the original problem is unbounded. If a primal feasible point does not exist, the original problem is infeasible.
The algorithm found a globally optimal solution to relaxed tolerances.
The algorithm concluded that no feasible solution exists within relaxed tolerances.
The algorithm concluded that no dual bound exists for the problem within relaxed tolerances.
The algorithm converged to a stationary point, local optimal solution, or could not find directions for improvement within relaxed tolerances.
An iterative algorithm stopped after conducting the maximum number of iterations.
The algorithm stopped after a user-specified computation time.
This status may be returned in relation to the TimeLimitSec
attribute, or some other solver-specific attribute.
A branch-and-bound algorithm stopped because it explored a maximum number of nodes in the branch-and-bound tree.
This status may be returned in relation to the NodeLimit
attribute, or some other solver-specific attribute.
The algorithm stopped because it found the required number of solutions. This is often used in MIPs to get the solver to return the first feasible solution it encounters.
This status may be returned in relation to the SolutionLimit
attribute, or some other solver-specific attribute.
The algorithm stopped because it ran out of memory.
The algorithm stopped because it found a solution better than a minimum limit set by the user.
This status may be returned in relation to the ObjectiveLimit
attribute, or some other solver-specific attribute.
The algorithm stopped because the norm of an iterate became too large.
This typically means that the primal problem is unbounded, but that the solver could not prove so.
The algorithm stopped due to a limit not covered by one of the _LIMIT_
statuses above.
The algorithm stopped because it was unable to continue making progress towards the solution.
The algorithm stopped because it encountered unrecoverable numerical error.
The algorithm stopped because the model is invalid.
The reason for this return code is solver-specific, but common causes are that the problem has zero variables or constraints, or that the problem data contains an invalid number such as NaN
.
The algorithm stopped because it was provided an invalid option.
The algorithm stopped because of an interrupt signal.
This typically means that the solver was interrupted by the user with CTRL+C
.
The algorithm stopped because of an error not covered by one of the statuses defined above. Check the solver log for further details.
MathOptInterface.OPTIMIZE_NOT_CALLED
— ConstantOPTIMIZE_NOT_CALLED::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm has not started.
MathOptInterface.OPTIMAL
— ConstantOPTIMAL::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm found a globally optimal solution.
MathOptInterface.INFEASIBLE
— ConstantINFEASIBLE::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm proved that no primal feasible solution exists.
MathOptInterface.DUAL_INFEASIBLE
— ConstantDUAL_INFEASIBLE::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm proved that no dual feasible solution exists.
To check if the primal problem is feasible, set the objective sense to FEASIBILITY_SENSE
and re-solve the problem.
If a primal feasible point does not exist, the original problem is both primal and dual infeasible.
If a primal feasible solution exists, this status typically implies that the problem is unbounded, with some technical exceptions (for example, if the problem is a conic optimization problem in which strong duality does not hold).
The technical exceptions do not apply to linear programs. The combination of DUAL_INFEASIBLE
and a primal feasible point means that the primal linear program is unbounded.
MathOptInterface.LOCALLY_SOLVED
— ConstantLOCALLY_SOLVED::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm converged to a stationary point, local optimal solution, could not find directions for improvement, or otherwise completed its search without global guarantees.
MathOptInterface.LOCALLY_INFEASIBLE
— ConstantLOCALLY_INFEASIBLE::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm converged to an infeasible point or otherwise completed its search without finding a feasible solution, without guarantees that no feasible solution exists.
If you know a primal feasible solution exists, use VariablePrimalStart
to provide a feasible starting point to the solver.
MathOptInterface.INFEASIBLE_OR_UNBOUNDED
— ConstantINFEASIBLE_OR_UNBOUNDED::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because it proved that the problem is infeasible or unbounded, without distinguishing between the two cases.
To distinguish between the two cases, set the objective sense to FEASIBILITY_SENSE
and re-solve the problem. If a primal feasible point exists, the original problem is unbounded. If a primal feasible point does not exist, the original problem is infeasible.
MathOptInterface.ALMOST_OPTIMAL
— ConstantALMOST_OPTIMAL::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm found a globally optimal solution to relaxed tolerances.
MathOptInterface.ALMOST_INFEASIBLE
— ConstantALMOST_INFEASIBLE::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm concluded that no feasible solution exists within relaxed tolerances.
MathOptInterface.ALMOST_DUAL_INFEASIBLE
— ConstantALMOST_DUAL_INFEASIBLE::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm concluded that no dual bound exists for the problem within relaxed tolerances.
MathOptInterface.ALMOST_LOCALLY_SOLVED
— ConstantALMOST_LOCALLY_SOLVED::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm converged to a stationary point, local optimal solution, or could not find directions for improvement within relaxed tolerances.
MathOptInterface.ITERATION_LIMIT
— ConstantITERATION_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
An iterative algorithm stopped after conducting the maximum number of iterations.
MathOptInterface.TIME_LIMIT
— ConstantTIME_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped after a user-specified computation time.
This status may be returned in relation to the TimeLimitSec
attribute, or some other solver-specific attribute.
MathOptInterface.NODE_LIMIT
— ConstantNODE_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
A branch-and-bound algorithm stopped because it explored a maximum number of nodes in the branch-and-bound tree.
This status may be returned in relation to the NodeLimit
attribute, or some other solver-specific attribute.
MathOptInterface.SOLUTION_LIMIT
— ConstantSOLUTION_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because it found the required number of solutions. This is often used in MIPs to get the solver to return the first feasible solution it encounters.
This status may be returned in relation to the SolutionLimit
attribute, or some other solver-specific attribute.
MathOptInterface.MEMORY_LIMIT
— ConstantMEMORY_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because it ran out of memory.
MathOptInterface.OBJECTIVE_LIMIT
— ConstantOBJECTIVE_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because it found a solution better than a minimum limit set by the user.
This status may be returned in relation to the ObjectiveLimit
attribute, or some other solver-specific attribute.
MathOptInterface.NORM_LIMIT
— ConstantNORM_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because the norm of an iterate became too large.
This typically means that the primal problem is unbounded, but that the solver could not prove so.
MathOptInterface.OTHER_LIMIT
— ConstantOTHER_LIMIT::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped due to a limit not covered by one of the _LIMIT_
statuses above.
MathOptInterface.SLOW_PROGRESS
— ConstantSLOW_PROGRESS::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because it was unable to continue making progress towards the solution.
MathOptInterface.NUMERICAL_ERROR
— ConstantNUMERICAL_ERROR::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because it encountered unrecoverable numerical error.
MathOptInterface.INVALID_MODEL
— ConstantINVALID_MODEL::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because the model is invalid.
The reason for this return code is solver-specific, but common causes are that the problem has zero variables or constraints, or that the problem data contains an invalid number such as NaN
.
MathOptInterface.INVALID_OPTION
— ConstantINVALID_OPTION::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because it was provided an invalid option.
MathOptInterface.INTERRUPTED
— ConstantINTERRUPTED::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because of an interrupt signal.
This typically means that the solver was interrupted by the user with CTRL+C
.
MathOptInterface.OTHER_ERROR
— ConstantOTHER_ERROR::TerminationStatusCode
An instance of the TerminationStatusCode
enum.
About
The algorithm stopped because of an error not covered by one of the statuses defined above. Check the solver log for further details.
MathOptInterface.PrimalStatus
— TypePrimalStatus(result_index::Int = 1)
An AbstractModelAttribute
for the ResultStatusCode
of the primal result result_index
.
result_index
If result_index
is omitted, it defaults to 1.
See ResultCount
for information on how the results are ordered.
If result_index
is larger than the value of ResultCount
then NO_SOLUTION
is returned.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.PrimalStatus)::MOI.ResultStatusCode
MathOptInterface.DualStatus
— TypeDualStatus(result_index::Int = 1)
An AbstractModelAttribute
for the ResultStatusCode
of the dual result result_index
.
result_index
See ResultCount
for information on how the results are ordered.
If result_index
is larger than the value of ResultCount
then NO_SOLUTION
is returned.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.PrimalStatus)::MOI.ResultStatusCode
MathOptInterface.RawStatusString
— TypeRawStatusString()
An AbstractModelAttribute
for a solver specific string explaining why the optimizer stopped.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.RawStatusString)::MOI.String
MathOptInterface.ResultCount
— TypeResultCount()
An AbstractModelAttribute
for the number of results available.
Order of solutions
A number of attributes contain an index, result_index
, which is used to refer to one of the available results. Thus, result_index
must be an integer between 1
and the number of available results.
As a general rule, the first result (result_index = 1
) is the most important result (for example, an optimal solution or an infeasibility certificate). Other results will typically be alternate solutions that the solver found during the search for the first result.
If a (local) optimal solution is available, that is, TerminationStatus
is OPTIMAL
or LOCALLY_SOLVED
, the first result must correspond to the (locally) optimal solution. Other results may be alternative optimal solutions, or they may be other suboptimal solutions; use ObjectiveValue
to distinguish between them.
If a primal or dual infeasibility certificate is available, that is, TerminationStatus
is INFEASIBLE
or DUAL_INFEASIBLE
and the corresponding PrimalStatus
or DualStatus
is INFEASIBILITY_CERTIFICATE
, then the first result must be a certificate. Other results may be alternate certificates, or infeasible points.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.ResultCount)::Int
MathOptInterface.ObjectiveValue
— TypeObjectiveValue(result_index::Int = 1)
An AbstractModelAttribute
for the objective value of the primal solution result_index
.
PrimalStatus
Before quering this attribute you should first check PrimalStatus
to confirm that a primal solution is avaiable.
If the PrimalStatus
is NO_SOLUTION
the result of querying this attribute is undefined.
result_index
The optimizer may return multiple primal solutions. See ResultCount
for information on how the results are ordered.
If the solver does not have a primal value for the objective because the result_index
is beyond the available solutions (whose number is indicated by the ResultCount
attribute), getting this attribute must throw a ResultIndexBoundsError
.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.ObjectiveValue,
)::Union{T,Vector{T}} where {T<:Real}
MathOptInterface.DualObjectiveValue
— TypeDualObjectiveValue(result_index::Int = 1)
An AbstractModelAttribute
for the value of the objective function of the dual solution result_index
.
DualStatus
Before quering this attribute you should first check DualStatus
to confirm that a dual solution is avaiable.
If the DualStatus
is NO_SOLUTION
the result of querying this attribute is undefined.
result_index
The optimizer may return multiple dual solutions. See ResultCount
for information on how the results are ordered.
If the solver does not have a dual value for the objective because the result_index
is beyond the available solutions (whose number is indicated by the ResultCount
attribute), getting this attribute must throw a ResultIndexBoundsError
.
Implementation
Optimizers should implement the following methods:
MOI.get(
::Optimizer,
::MOI.DualObjectiveValue,
)::Union{T,Vector{T}} where {T<:Real}
MathOptInterface.ObjectiveBound
— TypeObjectiveBound()
An AbstractModelAttribute
for the best known bound on the optimal objective value.
MathOptInterface.RelativeGap
— TypeRelativeGap()
An AbstractModelAttribute
for the final relative optimality gap.
The definition of this gap is solver-dependent. However, most solvers implementing this attribute define the relative gap as some variation of $\frac{|b-f|}{|f|}$, where $b$ is the best bound and $f$ is the best feasible objective value.
MathOptInterface.SolveTimeSec
— TypeSolveTimeSec()
An AbstractModelAttribute
for the total elapsed solution time (in seconds) as reported by the optimizer.
MathOptInterface.SimplexIterations
— TypeSimplexIterations()
An AbstractModelAttribute
for the cumulative number of simplex iterations while solving a problem.
For a mixed-integer program (MIP), the return value is the total simplex iterations for all nodes.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.SimplexIterations)::Int64
MathOptInterface.BarrierIterations
— TypeBarrierIterations()
An AbstractModelAttribute
for the cumulative number of barrier iterations while solving a problem.
For a mixed-integer program (MIP), the return value is the total barrier iterations for all nodes.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.BarrierIterations)::Int64
MathOptInterface.NodeCount
— TypeNodeCount()
An AbstractModelAttribute
for the total number of branch-and-bound nodes explored while solving a mixed-integer program (MIP).
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.NodeCount)::Int64
ResultStatusCode
MathOptInterface.ResultStatusCode
— TypeResultStatusCode
An Enum of possible values for the PrimalStatus
and DualStatus
attributes.
The values indicate how to interpret the result vector.
Values
The result vector is empty.
The result vector is a feasible point.
The result vector is feasible if some constraint tolerances are relaxed.
The result vector is an infeasible point.
The result vector is an infeasibility certificate.
If the PrimalStatus
is INFEASIBILITY_CERTIFICATE
, then the primal result vector is a certificate of dual infeasibility.
If the DualStatus
is INFEASIBILITY_CERTIFICATE
, then the dual result vector is a proof of primal infeasibility.
NEARLY_INFEASIBILITY_CERTIFICATE
The result satisfies a relaxed criterion for a certificate of infeasibility.
If the PrimalStatus
is NEARLY_INFEASIBILITY_CERTIFICATE
, then the primal result vector is a certificate of dual infeasibility.
If the DualStatus
is NEARLY_INFEASIBILITY_CERTIFICATE
, then the dual result vector is a proof of primal infeasibility.
The result vector is an ill-posed certificate; see this article for details.
If the PrimalStatus
is REDUCTION_CERTIFICATE
, then the primal result vector is a proof that the dual problem is ill-posed.
If the DualStatus
is REDUCTION_CERTIFICATE
, then the dual result vector is a proof that the primal is ill-posed.
The result satisfies a relaxed criterion for an ill-posed certificate.
The result vector contains a solution with an unknown interpretation. Check the solver log for more details.
The result vector contains a solution with an interpretation not covered by one of the statuses defined above. Check the solver log for more details.
MathOptInterface.NO_SOLUTION
— ConstantNO_SOLUTION::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector is empty.
MathOptInterface.FEASIBLE_POINT
— ConstantFEASIBLE_POINT::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector is a feasible point.
MathOptInterface.NEARLY_FEASIBLE_POINT
— ConstantNEARLY_FEASIBLE_POINT::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector is feasible if some constraint tolerances are relaxed.
MathOptInterface.INFEASIBLE_POINT
— ConstantINFEASIBLE_POINT::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector is an infeasible point.
MathOptInterface.INFEASIBILITY_CERTIFICATE
— ConstantINFEASIBILITY_CERTIFICATE::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector is an infeasibility certificate.
If the PrimalStatus
is INFEASIBILITY_CERTIFICATE
, then the primal result vector is a certificate of dual infeasibility.
If the DualStatus
is INFEASIBILITY_CERTIFICATE
, then the dual result vector is a proof of primal infeasibility.
MathOptInterface.NEARLY_INFEASIBILITY_CERTIFICATE
— ConstantNEARLY_INFEASIBILITY_CERTIFICATE::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result satisfies a relaxed criterion for a certificate of infeasibility.
If the PrimalStatus
is NEARLY_INFEASIBILITY_CERTIFICATE
, then the primal result vector is a certificate of dual infeasibility.
If the DualStatus
is NEARLY_INFEASIBILITY_CERTIFICATE
, then the dual result vector is a proof of primal infeasibility.
MathOptInterface.REDUCTION_CERTIFICATE
— ConstantREDUCTION_CERTIFICATE::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector is an ill-posed certificate; see this article for details.
If the PrimalStatus
is REDUCTION_CERTIFICATE
, then the primal result vector is a proof that the dual problem is ill-posed.
If the DualStatus
is REDUCTION_CERTIFICATE
, then the dual result vector is a proof that the primal is ill-posed.
MathOptInterface.NEARLY_REDUCTION_CERTIFICATE
— ConstantNEARLY_REDUCTION_CERTIFICATE::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result satisfies a relaxed criterion for an ill-posed certificate.
MathOptInterface.UNKNOWN_RESULT_STATUS
— ConstantUNKNOWN_RESULT_STATUS::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector contains a solution with an unknown interpretation. Check the solver log for more details.
MathOptInterface.OTHER_RESULT_STATUS
— ConstantOTHER_RESULT_STATUS::ResultStatusCode
An instance of the ResultStatusCode
enum.
About
The result vector contains a solution with an interpretation not covered by one of the statuses defined above. Check the solver log for more details.
Conflict Status
MathOptInterface.compute_conflict!
— Functioncompute_conflict!(optimizer::AbstractOptimizer)
Computes a minimal subset of constraints such that the model with the other constraint removed is still infeasible.
Some solvers call a set of conflicting constraints an Irreducible Inconsistent Subsystem (IIS).
See also ConflictStatus
and ConstraintConflictStatus
.
Note
If the model is modified after a call to compute_conflict!
, the implementor is not obliged to purge the conflict. Any calls to the above attributes may return values for the original conflict without a warning. Similarly, when modifying the model, the conflict can be discarded.
MathOptInterface.ConflictStatus
— TypeConflictStatus()
An AbstractModelAttribute
for the ConflictStatusCode
explaining why [compute_conflict!
] stopped when computing the conflict.
Implementation
Optimizers should implement the following methods:
MOI.get(::Optimizer, ::MOI.ConflictStatus)::MOI.ConflictStatusCode
MathOptInterface.ConflictStatusCode
— TypeConflictStatusCode
An Enum of possible values for the ConflictStatus
attribute.
This attribute is meant to explain the reason why the conflict finder stopped executing in the most recent call to compute_conflict!
.
Values
The function compute_conflict!
has not yet been called.
There is no conflict because the problem is feasible.
The solver could not find a conflict.
The solver found a conflict.
MathOptInterface.COMPUTE_CONFLICT_NOT_CALLED
— ConstantCOMPUTE_CONFLICT_NOT_CALLED::ConflictStatusCode
An instance of the ConflictStatusCode
enum.
About
The function compute_conflict!
has not yet been called.
MathOptInterface.NO_CONFLICT_EXISTS
— ConstantNO_CONFLICT_EXISTS::ConflictStatusCode
An instance of the ConflictStatusCode
enum.
About
There is no conflict because the problem is feasible.
MathOptInterface.NO_CONFLICT_FOUND
— ConstantNO_CONFLICT_FOUND::ConflictStatusCode
An instance of the ConflictStatusCode
enum.
About
The solver could not find a conflict.
MathOptInterface.CONFLICT_FOUND
— ConstantCONFLICT_FOUND::ConflictStatusCode
An instance of the ConflictStatusCode
enum.
About
The solver found a conflict.
MathOptInterface.ConstraintConflictStatus
— TypeConstraintConflictStatus()
A constraint attribute to query the ConflictParticipationStatusCode
indicating whether the constraint participates in the conflict.
MathOptInterface.ConflictParticipationStatusCode
— TypeConflictParticipationStatusCode
An Enum for the value of the ConstraintConflictStatus
attribute.
This attribute is meant to indicate whether a given constraint participates or not in the last computed conflict.
Values
The constraint does not participate in the conflict.
The constraint participates in the conflict.
The solver was not able to prove whether the constraint is required to participate in the conflict.
MathOptInterface.NOT_IN_CONFLICT
— ConstantNOT_IN_CONFLICT::ConflictParticipationStatusCode
An instance of the ConflictParticipationStatusCode
enum.
About
The constraint does not participate in the conflict.
MathOptInterface.IN_CONFLICT
— ConstantIN_CONFLICT::ConflictParticipationStatusCode
An instance of the ConflictParticipationStatusCode
enum.
About
The constraint participates in the conflict.
MathOptInterface.MAYBE_IN_CONFLICT
— ConstantMAYBE_IN_CONFLICT::ConflictParticipationStatusCode
An instance of the ConflictParticipationStatusCode
enum.
About
The solver was not able to prove whether the constraint is required to participate in the conflict.