Incidence graph
MathProgIncidence.get_bipartite_incidence_graph
— Functionget_bipartite_incidence_graph(
model,
include_inequality = false,
include_active_inequalities = false,
tolerance = 0.0,
)
Return the bipartite incidence graph of (scalar) variables and constraints in the JuMP model.
Arguments
model::JuMP.Model
: Model whose incidence graph is constructedinclude_inequality::Bool
: Whether all inequality constraints should be included in the graphinclude_active_inequalities::Bool
: Whether only active inequality constraints should be included in the graph. Constraint activity is determined using the most recent solution.include_active_inequalities
andinclude_inequality
are mutually exclusive.tolerance::Float64
: Tolerance for deciding whether an inequality constraint is active
Returns
This function returns a tuple (graph, con_node_map, var_node_map)
graph
– a tuple(A, B, E)
whereA
andB
contain the integer nodes in the bipartite sets for constraints and variables andE
contains edges in the form of tuples of integers(a, b)
, wherea
is inA
andb
is inB
.con_node_map
– aDict
mapping JuMPConstraintRef
s to nodesvar_node_map
– aDict
mapping JuMPVariableRef
s to nodes
The constraints in the graph are all the (by default, equality) constraints in the model, and the variables are those that participate in these constraints (not all variables in the model).
Example
julia> using JuMP
julia> import MathProgIncidence
julia> m = Model();
julia> @variable(m, v[1:3]);
julia> @constraint(m, eq_1, v[1] + v[3]^2 == 1.0);
julia> @NLconstraint(m, eq_2, v[1]*v[2]^1.5 == 2.0);
julia> graph, con_node_map, var_node_map = MathProgIncidence.get_bipartite_incidence_graph(m);
julia> A, B, E = graph;
julia> M = length(A);
julia> N = length(B);
julia> imat = zeros(M, N);
julia> for (a, b) in E
imat[a, b-M] = 1.0;
end
julia> display(imat)
2×3 Matrix{Float64}:
1.0 1.0 0.0
0.0 1.0 1.0
Convention
The returned graph follows a convention where, for a JuMP model with N constraints and M variables, the first N nodes are constraints and nodes N+1 through N+M are variables. Nodes are always contiguous integers starting at 1.
Methods
Methods are implemented that accept a JuMP Model
, a vector of ConstraintRef
s, and vectors of ConstraintRef
s and VariableRef
s. If variables are provided, then only these variables participate in the graph, regardless of which variables participate in the constraints.