Constraints
A technical manual for constraints in InfiniteOpt. See the respective guide for more information.
Definition
Note that constraints are defined principally with JuMP.@constraint which originates from JuMP.jl. Below we show build methods for DomainRestrictedConstraints, but any JuMP.AbstractConstraint can be used.
InfiniteOpt.DomainRestriction — TypeDomainRestriction{F <: Function}Tag for specifiying restricted domains for constraints. These are created via
DomainRestriction(restriction_func::Function, parameter_refs...)where restrict_func is a function that accepts a support that follows the formatting of parameter_refs and returns Bool on whether that support should be included in the domain of the constraint.
Example
@infinite_parameter(model, t in [0, 1])
@infinite_parameter(model, x in [-1, 1])
@variable(model, y, Infinite(t, x))
restrict_func(t_s, x_s) = (0 <= t_s <= 0.5) && (x_s < 0)
restriction = DomainRestriction(restrict_func, t, x)
@constraint(model, y^2 >= 42, restriction)JuMP.build_constraint — MethodJuMP.build_constraint(
_error::Function,
func,
set::MOI.AbstractSet,
restriction::DomainRestriction
)::DomainRestrictedConstraintExtend JuMP.buid_constraint to handle including a restriction to its inherit infinite parameter domain in addition to the traditional func in set setup. This returns a DomainRestrictedConstraint that can then be added via JuMP.add_constraint. Errors if the restriction is not compatible with infinite parameter domains.
Example
@infinite_parameter(model, t in [0, 1])
@infinite_parameter(model, x in [-1, 1])
@variable(model, y, Infinite(t, x))
restrict_func(t_s, x_s) = (0 <= t_s <= 0.5) && (x_s < 0)
restriction = DomainRestriction(restrict_func, t, x)
con = build_constraint(error, y + 2, MOI.LessThan(0.0), restriction);InfiniteOpt.DomainRestrictedConstraint — TypeDomainRestrictedConstraint{C <: JuMP.AbstractConstraint,
F <: Function,
T <: JuMP.AbstractVariableRef
} <: JuMP.AbstractConstraintA DataType for creating a constraint with enforced restrictions on its domain. For example, this may pertain to excluding a boundary condition.
Fields
constraint::C: The optimization constraint.restrictions::ParameterFunction{F, VT}: ReturnsBoolwhether constraint
should be added at particular point in the infinite parameter domain.
JuMP.add_constraint — MethodJuMP.add_constraint(
model::InfiniteModel,
c::JuMP.AbstractConstraint,
[name::String = ""]
)::InfOptConstraintRefExtend JuMP.add_constraint to add a constraint c to an infinite model model with name name. Returns an appropriate constraint reference whose type depends on what variables are used to define the constraint. Errors if any variables do not belong to model. This is primarily used as an internal method for the constraint macros.
Example
julia> @infinite_parameter(model, t in [0, 10]);
julia> @variable(model, g, Infinite(t));
julia> @variable(model, x);
julia> constr = build_constraint(error, g + x, MOI.EqualTo(42));
julia> cref = add_constraint(model, constr, "name")
name : g(t) + x = 42.0, ∀ t ∈ [0, 10]InfiniteOpt.ConstraintData — TypeConstraintData{C <: JuMP.AbstractConstraint} <: AbstractDataObjectA mutable DataType for storing constraints and their data.
Fields
constraint::C: The constraint.group_int_idxs::Vector{Int}: The group integer indices of the parameter objects that the constraint depends on.name::String: The name used for printing.measure_indices::Vector{MeasureIndex}: Indices of dependent measures.is_info_constraint::Bool: Is this is constraint based on variable info (e.g., lower bound)
InfiniteOpt.InfOptConstraintIndex — TypeInOptConstraintIndex <: ObjectIndex
A DataType for storing the index of a constraint.
Fields
value::Int64: The index value.
InfiniteOpt.InfOptConstraintRef — TypeInfOptConstraintRefA DataType for constraints that are in InfiniteModels
Fields
model::InfiniteModel: Infinite model.index::InfOptConstraintIndex: Index of the constraint in model.
Queries
JuMP.owner_model — MethodJuMP.owner_model(cref::InfOptConstraintRef)::InfiniteModelExtend JuMP.owner_model to return the infinite model associated with cref.
Example
julia> model = owner_model(cref)
An InfiniteOpt Model
Minimization problem with:
Finite parameters: 0
Infinite parameter: 1
Variables: 3
Derivatives: 0
Measures: 0
Objective function type: GenericAffExpr{Float64, GeneralVariableRef}
`GenericAffExpr{Float64, GeneralVariableRef}`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint
`GenericAffExpr{Float64, GeneralVariableRef}`-in-`MathOptInterface.EqualTo{Float64}`: 1 constraint
`GeneralVariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 3 constraints
Names registered in the model: c1, c2, t, y, z
Transformation backend information:
Backend type: TranscriptionBackend
`t` transcribed over 10 supports
Solver: Ipopt
Transformation built and up-to-date: trueJuMP.index — MethodJuMP.index(cref::InfOptConstraintRef)::InfOptConstraintIndexExtend JuMP.index to return the index of an InfiniteOpt constraint cref.
Example
julia> index(cref)
InfOptConstraintIndex(2)JuMP.constraint_object — MethodJuMP.constraint_object(cref::InfOptConstraintRef)::JuMP.AbstractConstraintExtend JuMP.constraint_object to return the constraint object associated with cref.
Example
julia> @infinite_parameter(model, t in [0, 10]);
julia> @variable(model, x <= 1);
julia> cref = UpperBoundRef(x);
julia> obj = constraint_object(cref)
ScalarConstraint{GeneralVariableRef,MathOptInterface.LessThan{Float64}}(x,
MathOptInterface.LessThan{Float64}(1.0))JuMP.name — MethodJuMP.name(cref::InfOptConstraintRef)::StringExtend JuMP.name to return the name of an InfiniteOpt constraint.
Example
julia> name(cref)
"constr_name"JuMP.constraint_by_name — MethodJuMP.constraint_by_name(
model::InfiniteModel,
name::String
)::Union{InfOptConstraintRef, Nothing}Extend JuMP.constraint_by_name to return the constraint reference associated with name if one exists or returns nothing. Errors if more than one constraint uses the same name.
Example
julia> constraint_by_name(model, "constr_name")
constr_name : x + pt = 3.0JuMP.list_of_constraint_types — MethodJuMP.list_of_constraint_types(model::InfiniteModel)::Vector{Tuple{DataType, DataType}}Extend JuMP.list_of_constraint_types to return a list of tuples that contain all the used combinations of function types and set types in the model.
Example
julia> all_constraints(model)
3-element Array{Tuple{DataType,DataType},1}:
(GeneralVariableRef, MathOptInterface.LessThan{Float64})
(GeneralVariableRef, MathOptInterface.GreaterThan{Float64})
(GeneralVariableRef, MathOptInterface.Integer)JuMP.num_constraints — MethodJuMP.num_constraints(model::InfiniteModel, [function_type], [set_type])::IntExtend JuMP.num_constraints to return the number of constraints with a partiuclar function type and set type.
Example
julia> num_constraints(model, FiniteVariableRef, MOI.LessThan)
1
julia> num_constraints(model, FiniteVariableRef)
3
julia> num_constraints(model, MOI.LessThan)
2
julia> num_constraints(model)
4JuMP.all_constraints — MethodJuMP.all_constraints(
model::InfiniteModel,
[function_type],
[set_type]
)::Vector{InfOptConstraintRef}Extend JuMP.all_constraints to return a list of all the constraints with a particular function type and set type.
Example
julia> all_constraints(model, GeneralVariableRef, MOI.LessThan)
1-element Array{InfOptConstraintRef,1}:
x ≤ 1.0
julia> all_constraints(model, GeneralVariableRef)
3-element Array{InfOptConstraintRef,1}:
x ≥ 0.0
x ≤ 3.0
x integer
julia> all_constraints(model, MOI.GreaterThan)
3-element Array{InfOptConstraintRef,1}:
x ≥ 0.0
g(t) ≥ 0.0, ∀ t ∈ [0, 6]
g(0.5) ≥ 0.0
julia> all_constraints(model)
5-element Array{InfOptConstraintRef,1}:
x ≥ 0.0
x ≤ 3.0
x integer
g(t) ≥ 0.0, ∀ t ∈ [0, 6]
g(0.5) ≥ 0.0JuMP.is_valid — MethodJuMP.is_valid(model::InfiniteModel, cref::InfOptConstraintRef)::BoolExtend JuMP.is_valid to return Bool whether an InfiniteOpt constraint reference is valid.
Example
julia> is_valid(model, cref)
trueInfiniteOpt.parameter_refs — Methodparameter_refs(cref::InfOptConstraintRef)::TupleReturn the tuple of infinite parameter references that determine the infinite dependencies of cref.
Example
julia> parameter_refs(cref)
(t,)InfiniteOpt.has_domain_restriction — Functionhas_domain_restriction(cref::InfOptConstraintRef)::BoolReturn a Bool indicating if cref is limited to a sub-domain as defined by a DomainRestriction object.
Example
julia> has_domain_restriction(cref)
trueInfiniteOpt.domain_restriction — Functiondomain_restriction(cref::InfOptConstraintRef)::ParameterFunctionReturn the domain restriction formated as a ParameterFunction associated with the constraintcref. Errors if it does not have a domain restriction.
Example
julia> domain_restriction(cref)
restrict_func(t)JuMP.normalized_rhs — MethodJuMP.normalized_rhs(cref::InfOptConstraintRef)::Float64Return the right-hand side term of cref after JuMP has converted the constraint into its normalized form.
JuMP.normalized_coefficient — MethodJuMP.normalized_coefficient(cref::InfOptConstraintRef,
variable::GeneralVariableRef)::Float64Return the coefficient associated with variable in constraint after JuMP has normalized the constraint into its standard form.
InfiniteOpt.parameter_group_int_indices — Methodparameter_group_int_indices(cref::InfOptConstraintRef)::Vector{Int}Return the list of infinite parameter group integer indices used by cref.
InfiniteOpt.core_object — Methodcore_object(cref::InfOptConstraintRef)::JuMP.AbstractConstraintReturn the core underlying constraint object for cref. This is intended for the developer API. For general usage, JuMP.constraint_object should be used instead.
InfiniteOpt.is_variable_domain_constraint — Functionis_variable_domain_constraint(cref::InfOptConstraintRef)::BoolReturns a Bool whether cref was created based on a variable's domain. For instance, it could be the upper bound of a variable y(t) which is normally queried via UpperBoundRef. This is intended as a helper function for developers of new transformation backends which typically ignore these constraints, since they are taken care of when the variables are processed.
Modification
JuMP.set_name — MethodJuMP.set_name(cref::InfOptConstraintRef, name::String)::NothingExtend JuMP.set_name to specify the name of a constraint cref.
Example
julia> set_name(cref, "new_name")
julia> name(cref)
"new_name"InfiniteOpt.set_domain_restriction — Functionset_domain_restriction(
cref::InfOptConstraintRef,
restriction:DomainRestriction
)::NothingSpecify a new DomainRestriction object restriction for the constraint cref
Example
julia> restrict_func(t_s) = 0 <= t_s <= 0.5;
julia> set_domain_restriction(cref, DomainRestrictions(restrict_func, t))
julia> domain_restriction(cref)
restrict_func(t)InfiniteOpt.delete_domain_restriction — Functiondelete_domain_restriction(cref::InfOptConstraintRef)::NothingDelete the domain restriction of the constraint cref.
Example
julia> delete_domain_restriction(c1)JuMP.set_normalized_rhs — MethodJuMP.set_normalized_rhs(cref::InfOptConstraintRef, value::Real)::NothingSet the right-hand side term of constraint to value. Note that prior to this step, JuMP will aggregate all constant terms onto the right-hand side of the constraint. For example, given a constraint 2x + 1 <= 2, set_normalized_rhs(con, 4) will create the constraint 2x <= 4, not 2x + 1 <= 4.
julia> @constraint(model, con, 2x + 1 <= 2)
con : 2 x ≤ 1.0
julia> set_normalized_rhs(con, 4)
julia> con
con : 2 x ≤ 4.0JuMP.add_to_function_constant — MethodJuMP.add_to_function_constant(cref::InfOptConstraintRef, value::Real)::NothingAdd value to the function constant term. Note that for scalar constraints, JuMP will aggregate all constant terms onto the right-hand side of the constraint so instead of modifying the function, the set will be translated by -value. For example, given a constraint 2x <= 3, add_to_function_constant(c, 4) will modify it to 2x <= -1. ```
JuMP.set_normalized_coefficient — MethodJuMP.set_normalized_coefficient(cref::InfOptConstraintRef,
variable::GeneralVariableRef,
value::Real)::NothingSet the coefficient of variable in the constraint constraint to value. Note that prior to this step, JuMP will aggregate multiple terms containing the same variable. For example, given a constraint 2x + 3x <= 2, set_normalized_coefficient(con, x, 4) will create the constraint 4x <= 2.
julia> con
con : 5 x ≤ 2.0
julia> set_normalized_coefficient(con, x, 4)
julia> con
con : 4 x ≤ 2.0JuMP.delete — MethodJuMP.delete(model::InfiniteModel, cref::InfOptConstraintRef)::NothingExtend JuMP.delete to delete an InfiniteOpt constraint and all associated information. Errors if cref is invalid.
Example
julia> print(model)
Min measure(g(t)*t) + z
Subject to
z ≥ 0.0
g(t) + z ≥ 42.0, ∀ t ∈ [0, 6]
julia> delete(model, cref)
julia> print(model)
Min measure(g(t)*t) + z
Subject to
z ≥ 0.0