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.DomainRestrictions — TypeDomainRestrictions{P <: GeneralVariableRef}A DataType for storing interval domains that constrain particular infinite parameters to a subdomain relative to their full domain. This is used to define subdomains of DomainRestrictedConstraints. Note that the GeneralVariableRef must pertain to infinite parameters.
The constructor syntax is
DomainRestrictions(restrictions...)where each argument of restrictions is one of the following forms:
pref => valuepref => [lb, ub]pref => IntervalDomain(lb, ub)prefs => valueprefs => [lb, ub]prefs => IntervalDomain(lb, ub).
Note that pref and prefs must correspond to infinite parameters.
Fields
intervals::Dict{GeneralVariableRef, IntervalDomain}: A dictionary of interval bounds on infinite parameters.
JuMP.build_constraint — MethodJuMP.build_constraint(_error::Function, func, set,
restrictions::DomainRestrictions{GeneralVariableRef}
)::DomainRestrictedConstraintExtend JuMP.buid_constraint to handle including restrictions to its inherit infinite parameter domains 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 restrictions are incompadible with infinite parameter domains.
Example
julia> restrictions = DomainRestrictions(t => 0)
Subdomain restrictions (1): t = 0
julia> con = build_constraint(error, y + 2, MOI.LessThan(0.0), restrictions);InfiniteOpt.DomainRestrictedConstraint — TypeDomainRestrictedConstraint{C <: JuMP.AbstractConstraint,
P <: GeneralVariableRef
} <: JuMP.AbstractConstraintA DataType for creating a constraint with enforced DomainRestrictions. For example this may pertain to a boundary condition.
Fields
constraint::C: The optimization constraint.restrictions::DomainRestrictions{P}: The restrictions that determine the sub-domain of the constraint.
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_restrictions — Functionhas_domain_restrictions(cref::InfOptConstraintRef)::BoolReturn a Bool indicating if cref is limited to a sub-domain as defined by a DomainRestrictions object.
Example
julia> has_domain_restrictions(cref)
trueInfiniteOpt.domain_restrictions — Functiondomain_restrictions(cref::InfOptConstraintRef)::DomainRestrictions{GeneralVariableRef}Return the DomainRestrictions object associated with the constraint cref.
Example
julia> domain_restrictions(cref)
Subdomain restrictions (1): t ∈ [0, 2]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_restrictions — Functionset_domain_restrictions(cref::InfOptConstraintRef,
restrictions:DomainRestrictions{GeneralVariableRef};
[force::Bool = false])::NothingSpecify a new DomainRestrictions object restrictions for the constraint cref. Errors if cref already has restrictions and force = false. Where possible it is recommended to use add_domain_restrictions instead.
Example
julia> set_domain_restrictions(cref, DomainRestrictions(t => [0, 2]))
julia> domain_restrictions(cref)
Subdomain restrictions (1): t ∈ [0, 2]InfiniteOpt.add_domain_restrictions — Functionadd_domain_restrictions(cref::InfOptConstraintRef,
new_restrictions::DomainRestrictions{GeneralVariableRef}
)::NothingAdd additional domain restrictions to cref such that it is defined over the sub-domain based on pref from lower to upper.
julia> add_domain_restrictions(cref, DomainRestrictions(t => [0, 2]))
julia> domain_restrictions(cref)
Subdomain restrictions (1): t ∈ [0, 2]InfiniteOpt.delete_domain_restrictions — Functiondelete_domain_restrictions(cref::InfOptConstraintRef)::NothingDelete all the domain restrictions of the constraint cref. Note any restrictions that are needed for finite variables inside in cref will be unaffected.
Example
julia> @constraint(model, c1, y <= 42, DomainRestrictions(x => 0))
c1 : y(x) ≤ 42, ∀ x[1] = 0, x[2] = 0
julia> delete_domain_restrictions(c1)
julia> c1
c1 : y(x) ≤ 42, ∀ x[1] ∈ [-1, 1], x[2] ∈ [-1, 1]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