Modifications
MathOptInterface.modify
— Functionmodify(
model::ModelLike,
ci::ConstraintIndex,
change::AbstractFunctionModification,
)
Apply the modification specified by change
to the function of constraint ci
.
An ModifyConstraintNotAllowed
error is thrown if modifying constraints is not supported by the model model
.
Example
julia> import MathOptInterface as MOI
julia> model = MOI.Utilities.Model{Float64}();
julia> x = MOI.add_variable(model);
julia> ci = MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(1.0));
julia> MOI.modify(model, ci, MOI.ScalarConstantChange(10.0))
julia> print(model)
Feasibility
Subject to:
ScalarAffineFunction{Float64}-in-EqualTo{Float64}
10.0 + 1.0 v[1] == 1.0
modify(
model::ModelLike,
cis::AbstractVector{<:ConstraintIndex},
changes::AbstractVector{<:AbstractFunctionModification},
)
Apply multiple modifications specified by changes
to the functions of constraints cis
.
A ModifyConstraintNotAllowed
error is thrown if modifying constraints is not supported by model
.
Example
julia> import MathOptInterface as MOI
julia> model = MOI.Utilities.Model{Float64}();
julia> x = MOI.add_variables(model, 2);
julia> ci = MOI.add_constraint.(model, 1.0 .* x, MOI.EqualTo(1.0));
julia> MOI.modify(model, ci, MOI.ScalarCoefficientChange.(x, [2.0, 0.5]))
julia> print(model)
Feasibility
Subject to:
ScalarAffineFunction{Float64}-in-EqualTo{Float64}
0.0 + 2.0 v[1] == 1.0
0.0 + 0.5 v[2] == 1.0
modify(model::ModelLike, ::ObjectiveFunction, change::AbstractFunctionModification)
Apply the modification specified by change
to the objective function of model
. To change the function completely, call set
instead.
An ModifyObjectiveNotAllowed
error is thrown if modifying objectives is not supported by the model model
.
Example
julia> import MathOptInterface as MOI
julia> model = MOI.Utilities.Model{Float64}();
julia> x = MOI.add_variable(model);
julia> MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
julia> f = 1.0 * x;
julia> attr = MOI.ObjectiveFunction{typeof(f)}()
MathOptInterface.ObjectiveFunction{MathOptInterface.ScalarAffineFunction{Float64}}()
julia> MOI.set(model, attr, f)
julia> MOI.modify(model, attr, MOI.ScalarConstantChange(10.0))
julia> print(model)
Minimize ScalarAffineFunction{Float64}:
10.0 + 1.0 v[1]
Subject to:
modify(
model::ModelLike,
attr::ObjectiveFunction,
changes::AbstractVector{<:AbstractFunctionModification},
)
Apply multiple modifications specified by changes
to the functions of constraints cis
.
A ModifyObjectiveNotAllowed
error is thrown if modifying objective coefficients is not supported by model
.
Example
Example
julia> import MathOptInterface as MOI
julia> model = MOI.Utilities.Model{Float64}();
julia> x = MOI.add_variables(model, 2);
julia> MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
julia> f = 1.0 * x[1] + 1.0 * x[2];
julia> attr = MOI.ObjectiveFunction{typeof(f)}()
MathOptInterface.ObjectiveFunction{MathOptInterface.ScalarAffineFunction{Float64}}()
julia> MOI.set(model, attr, f)
julia> MOI.modify(model, attr, MOI.ScalarCoefficientChange.(x, [2.0, 0.5]))
julia> print(model)
Minimize ScalarAffineFunction{Float64}:
0.0 + 2.0 v[1] + 0.5 v[2]
Subject to:
MathOptInterface.AbstractFunctionModification
— TypeAbstractFunctionModification
An abstract supertype for structs which specify partial modifications to functions, to be used for making small modifications instead of replacing the functions entirely.
MathOptInterface.ScalarConstantChange
— TypeScalarConstantChange{T}(new_constant::T)
A struct used to request a change in the constant term of a scalar-valued function.
Applicable to ScalarAffineFunction
and ScalarQuadraticFunction
.
MathOptInterface.VectorConstantChange
— TypeVectorConstantChange{T}(new_constant::Vector{T})
A struct used to request a change in the constant vector of a vector-valued function.
Applicable to VectorAffineFunction
and VectorQuadraticFunction
.
MathOptInterface.ScalarCoefficientChange
— TypeScalarCoefficientChange{T}(variable::VariableIndex, new_coefficient::T)
A struct used to request a change in the linear coefficient of a single variable in a scalar-valued function.
Applicable to ScalarAffineFunction
and ScalarQuadraticFunction
.
MathOptInterface.ScalarQuadraticCoefficientChange
— TypeScalarQuadraticCoefficientChange{T}(
variable_1::VariableIndex,
variable_2::VariableIndex,
new_coefficient::T,
)
A struct used to request a change in the quadratic coefficient of a ScalarQuadraticFunction
.
Scaling factors
A ScalarQuadraticFunction
has an implicit 0.5
scaling factor in front of the Q
matrix. This modification applies to terms in the Q
matrix.
If variable_1 == variable_2
, this modification sets the corresponding diagonal element of the Q
matrix to new_coefficient
.
If variable_1 != variable_2
, this modification is equivalent to setting both the corresponding upper- and lower-triangular elements of the Q
matrix to new_coefficient
.
As a consequence:
- to modify the term
x^2
to become2x^2
,new_coefficient
must be4
- to modify the term
xy
to become2xy
,new_coefficient
must be2
MathOptInterface.MultirowChange
— TypeMultirowChange{T}(
variable::VariableIndex,
new_coefficients::Vector{Tuple{Int64,T}},
) where {T}
A struct used to request a change in the linear coefficients of a single variable in a vector-valued function.
New coefficients are specified by (output_index, coefficient)
tuples.
Applicable to VectorAffineFunction
and VectorQuadraticFunction
.