Identifying variables in constraints

MathProgIncidence.identify_unique_variablesFunction
identify_unique_variables(constraints::Vector{JuMP.ConstraintRef})::Vector{JuMP.VariableRef}

Return a vector of variables that participate in the provided constraints.

Each variable appears at most one time in the returned vector.

Example

julia> using JuMP

julia> import MathProgIncidence

julia> m = Model();

julia> @variable(m, v[1:3]);

julia> @constraint(m, eq_1, v[2] == 1);

julia> @NLconstraint(m, eq_2, v[2]*v[3]^1.5 == 2);

julia> vars = MathProgIncidence.identify_unique_variables([eq_1, eq_2]);

julia> display(vars)
2-element Vector{VariableRef}:
 v[2]
 v[3]
identify_unique_variables(
    model::JuMP.Model,
    include_inequality = false,
    include_active_inequalities = false,
    tolerance = 0.0,
)

Return a vector of variables that participate in constraints in the model.

Each variable appears at most one time in the returned vector.

Optional keyword arguments

  • include_inequality: Whether to include variables that participate in any inequality constraints
  • include_active_inequalities: Whether to include variables that participate active inequality constraints (at the latest solution). include_active_inequalities and include_inequality are mutually exclusive.
  • tolerance: Tolerance used to determine if an inequality constraint is active
identify_unique_variables(constraint::JuMP.ConstraintRef)

Return a vector containing the variables that participate in this constraint.

Each variable appears at most one time in the returned vector.

identify_unique_variables(
    constraint::JuMP.ConstraintRef,
    index::JuMP.ConstraintIndex,
)::Vector{JuMP.VariableRef}

Return a vector containing the variables that participate in this constraint.

Each variable appears at most one time in the returned vector. The index argument is provided so we know whether we have a "regular" constraint or a nonlinear constraint.

identify_unique_variables(
    constraint::JuMP.ConstraintRef,
    index::MathOptInterface.Nonlinear.ConstraintIndex,
)::Vector{JuMP.VariableRef}

Return a vector containing the variables that participate in this constraint.

Each variable appears at most one time in the returned vector. The index argument is provided so we know whether we have a "regular" constraint or a nonlinear constraint.

identify_unique_variables(fcn)::Vector{JuMP.VariableIndex}

Return the variables that appear in the provided MathOptInterface function.

No variable will appear more than once.

Implementation

Only ScalarNonlinearFunction, ScalarQuadraticFunction, and ScalarAffineFunction are supported. This can be changed there is demand for other functions. These methods are implemented by first identifying all variables that participate in the function, then filtering out duplicate variables.

identify_unique_variables(term)

Return the variables that participate in the provided term of a MathOptInterface function.

A variable appears at most one time in the returned vector.

Implementation

Currently implemented only for ScalarAffineTerm and ScalarQuadraticTerm.

MathProgIncidence._get_variable_termsFunction
_get_variable_terms(fcn)

Return a tuple of vectors of terms for the provided MathOptInterface function.

Implementation

Currently implemented only for ScalarQuadraticFunction and ScalarAffineFunction.