API Documentation

OptiGraph Methods

Plasmo.OptiGraphType
OptiGraph

The core modeling object of Plasmo.jl. An optigraph represents an optimization model as a set of OptiNode and OptiEdge objects.

source
Plasmo.OptiNodeType
OptiNode{GT<:AbstractOptiGraph} <: AbstractOptiNode

A data structure meant to encapsulate variables, constraints, an objective function, and other model data. An optinode is "lightweight" in the sense that it does not directly contain model data, but instead acts as an interface that maps to a backend where the model data is stored. This avoids the need to generate memory overhead through container structures in cases when a node contains very little model data.

source
Plasmo.OptiEdgeType
OptiEdge{GT<:AbstractOptiGraph} <: AbstractOptiEdge

A data structure meant to encapsulate linking constraints and other model data. An optiedge is "lightweight" in the sense that it does not directly contain model data, but instead acts as an interface that maps to a backend where the model data is stored. This avoids the need to generate memory overhead through container structures in cases when a node contains very little model data.

source
Plasmo.@optinodeMacro
@optinode(optigraph, expr...)

Add a new optinode to optigraph. The expression expr can either be

  • of the form nodename creating a single optinode with the variable name varname
  • of the form nodename[...] or [...] creating a container of optinodes using JuMP Containers
source
Plasmo.@linkconstraintMacro
@linkconstraint(graph::OptiGraph, expr)

Add a linking constraint described by the expression expr.

@linkconstraint(graph::OptiGraph, ref[i=..., j=..., ...], expr)

Add a group of linking constraints described by the expression expr parametrized by i, j, ...

The @linkconstraint macro works the same way as the JuMP.@constraint macro.

source
Plasmo.@nodevariablesMacro
@nodevariables(iterable, expr...)

Call the JuMP.@variable macro for each optinode in a given container

source
Plasmo.set_to_node_objectivesFunction
set_to_node_objectives(graph::OptiGraph)

Set the graph objective to the summation of all of its optinode objectives. Assumes the objective sense is an MOI.MIN_SENSE and accounts for the sense of node objectives accordingly.

Note that building nonlinear objective functions is much slower than linear or quadratic because nonlienar expressions cannot be updated in place.

source
Plasmo.graph_backendFunction
graph_backend(graph::OptiGraph)

Return the intermediate backend used to map the optigraph to an optimizer. Plasmo.jl currently only supports a backend to MathOptInterface.jl optimizers, but future versions intend to support GraphOptInterface.jl as a structured backend.

source
graph_backend(node::OptiNode)

Return the GraphMOIBackend that holds the associated node model attributes

source
graph_backend(edge::OptiEdge)

Return the GraphMOIBackend that holds the associated edge model attributes

source
Plasmo.graph_indexFunction
graph_index(ref::RT) where {RT<:Union{NodeVariableRef,ConstraintRef}}

Return the the corresponding variable or constraint index corresponding to a reference.

source
graph_index(
    backend::GraphMOIBackend, 
    ref::RT
) where {RT<:Union{NodeVariableRef,ConstraintRef}}

Return the actual variable or constraint index of the backend model that corresponds to the local index of a node or edge.

source
Plasmo.source_graphFunction
source_graph(node::OptiNode)

Return the optigraph that contains the optinode. This is the optigraph that defined said node and stores node object dictionary data.

source
source_graph(edge::OptiEdge)

Return the optigraph that contains the optiedge. This is the optigraph that defined said edge and stores edge object dictionary data.

source
Plasmo.add_subgraphFunction
add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg,gensym()))

Create and add a new subgraph to the optigraph graph.

source
add_subgraph(graph::OptiGraph; name::Symbol=Symbol(:sg,gensym()))

Add an existing subgraph to an optigraph. The subgraph cannot already be part of another optigraph. It also should not have nodes that already exist in the optigraph.

source
Plasmo.all_subgraphsFunction
all_subgraphs(graph::OptiGraph)::Vector{OptiGraph}

Retrieve all subgraphs of graph. Includes subgraphs within other subgraphs.

source
Plasmo.num_local_subgraphsFunction
num_local_subgraphs(graph::OptiGraph)::Int

Retrieve the number of local subgraphs in graph. Does not include graph in subgraphs.

source
Plasmo.num_subgraphsFunction
num_subgraphs(graph::OptiGraph)::Int

Retrieve the total number of subgraphs in graph. Include subgraphs within subgraphs.

source
Plasmo.add_nodeFunction
add_node(
    graph::OptiGraph; label=Symbol(graph.label, Symbol(".n"), length(graph.optinodes)+1
)

Add a new optinode to graph. By default, the node label is set to be "n<i+1>" where "i" is the number of nodes in the graph.

source
add_node(graph::OptiGraph, node::OptiNode)

Add an existing optinode (created in another optigraph) to graph. This copies model data from the other graph to the new graph.

source
Plasmo.get_nodeFunction
get_node(graph::OptiGraph, idx::Int)

Retrieve the optinode in graph at the given index.

source
Plasmo.local_nodesFunction
local_nodes(graph::OptiGraph)::Vector{<:OptiNode}

Retrieve the optinodes defined within the optigraph graph. This does not return nodes that exist in subgraphs.

source
Plasmo.all_nodesFunction
all_nodes(graph::OptiGraph)::Vector{<:OptiNode}

Recursively collect all optinodes in graph by traversing each of its subgraphs.

source
Plasmo.collect_nodesFunction
collect_nodes(jump_func::T where T <: JuMP.AbstractJuMPScalar)

Retrieve the optinodes contained in a JuMP expression.

source
Plasmo.num_nodesFunction
num_nodes(graph::OptiGraph)::Int

Return the total number of nodes in graph by recursively checking subgraphs.

source
Plasmo.num_local_variablesFunction
num_local_variables(graph::OptiGraph)

Return the number of local variables in graph. Does not include variables in subgraphs.

source
Plasmo.add_edgeFunction
add_edge(
    graph::OptiGraph,
    nodes::OptiNode...;
    label=Symbol(graph.label, Symbol(".e"), length(graph.optiedges) + 1),
)

Add a new optiedge to graph that connects nodes. By default, the edge label is set to be "e<i+1>" where "i" is the number of edges in the graph.

source
add_edge(graph::OptiGraph, edge::OptiEdge)

Add an existing optiedge (created in another optigraph) to graph. This copies model data from the other graph to the new graph.

source
Plasmo.get_edgeFunction
get_edge(graph::OptiGraph, nodes::Set{<:OptiNode})

Retrieve the optiedge in graph. that connects nodes.

source
get_edge(graph::OptiGraph, nodes::OptiNode...)

Convenience method. Retrieve the optiedge in graph that connects nodes.

source
Plasmo.get_edge_by_indexFunction
get_edge_by_index(graph::OptiGraph, idx::Int64)

Retrieve the optiedge in graph that corresponds to the given index.

source
Plasmo.has_edgeFunction
has_edge(graph::OptiGraph, nodes::Set{<:OptiNode})

Return whether an edge that connects nodes exists in the graph.

source
Plasmo.local_edgesFunction
local_edges(graph::OptiGraph)

Retrieve the edges that exists in graph. Does not return edges that exist in subgraphs.

source
Plasmo.all_edgesFunction
all_edges(graph::OptiGraph)::Vector{<:OptiNode}

Recursively collect all optiedges in graph by traversing each of its subgraphs.

source
Plasmo.num_edgesFunction
num_edges(graph::OptiGraph)::Int

Return the total number of nodes in graph by recursively checking subgraphs.

source
Plasmo.num_local_link_constraintsFunction
num_local_link_constraints(
    graph::OptiGraph,
    func_type::Type{<:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}}},
    set_type::Type{<:MOI.AbstractSet},
)

Retrieve the number of local linking constraints with function func_type and set set_type in graph. Does not include linking constraints in subgraphs.

source
num_local_link_constraints(graph::OptiGraph)

Retrieve the number of local linking constraints (all constraint types) in graph. Does not include linking constraints in subgraphs.

source
Plasmo.num_link_constraintsFunction
num_link_constraints(
    graph::OptiGraph,
    func_type::Type{<:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}}},
    set_type::Type{<:MOI.AbstractSet},
)

Retrieve the total number of linking constraints with function func_type and set set_type in graph. Includes constraints in subgraphs.

source
num_link_constraints(graph::OptiGraph)

Retrieve the number of local linking constraints (all constraint types) in graph. Does not include constraints in subgraphs.

source
Plasmo.local_link_constraintsFunction
local_link_constraints(
    graph::OptiGraph,
    func_type::Type{<:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}}},
    set_type::Type{<:MOI.AbstractSet},
)

Retrieve the local linking constraints with function func_type and set set_type in graph. Does not include linking constraints in subgraphs.

source
local_link_constraints(graph::OptiGraph)

Retrieve the local linking constraints (all constraint types) in graph. Does not include constraints in subgraphs.

source
Plasmo.all_link_constraintsFunction
all_link_constraints(
    graph::OptiGraph,
    func_type::Type{<:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}}},
    set_type::Type{<:MOI.AbstractSet},
)

Retrieve all linking constraints with function func_type and set set_type in graph. Does not include constraints in subgraphs.

source
all_link_constraints(graph::OptiGraph)

Retrieve all linking constraints (all constraint types) in graph. Includes linking constraints in subgraphs.

source
Plasmo.num_local_constraintsFunction
num_local_constraints(
    graph::OptiGraph,
    func_type::Type{<:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}}},
    set_type::Type{<:MOI.AbstractSet},
)

Retrieve the number of local constraints with function func_type and set set_type in graph. Does not include constraints in subgraphs.

source
num_local_constraints(graph::OptiGraph)

Retrieve the number of local constraints (all constraint types) in graph. Does not include constraints in subgraphs.

source
Plasmo.local_constraintsFunction
local_constraints(
    graph::OptiGraph,
    func_type::Type{<:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}}},
    set_type::Type{<:MOI.AbstractSet},
)

Retrieve the local constraints with function func_type and set set_type in graph. Does not include constraints in subgraphs.

source
local_constraints(graph::OptiGraph)

Retrieve the local constraints (all constraint types) in graph. Does not include constraints in subgraphs.

source
Plasmo.local_elementsFunction
local_elements(graph::OptiGraph)

Retrieve the local elements (nodes and edges) in graph. Does not include elements in subgraphs.

source
Plasmo.all_elementsFunction
local_elements(graph::OptiGraph)

Retrieve all elements (nodes and edges) in graph. Includes elements in subgraphs.

source
Base.getindexMethod
Base.getindex(graph::OptiGraph, idx::Int)

Get the optinode at the given index.

source

JuMP.jl Extended Methods

JuMP.nameFunction
JuMP.name(graph::OptiGraph)

Return the name of graph.

source
JuMP.set_nameFunction
JuMP.set_name(graph::OptiGraph, name::Symbol)

Set the name of graph to name.

source
JuMP.indexFunction
JuMP.index(graph::OptiGraph, nvref::NodeVariableRef)

Return the backend model index of node variable nvref

source
JuMP.backendFunction
JuMP.backend(graph::OptiGraph)

Return the backend model object for graph.

source
JuMP.valueFunction
JuMP.value(graph::OptiGraph, nvref::NodeVariableRef; result::Int=1)

Return the primal value of nvref in graph. Note that this value is specific to the optimizer solution to the graph. The nvref can have different values for different optigraphs it is contained in.

source
JuMP.add_variableFunction
JuMP.add_variable(node::OptiNode, v::JuMP.AbstractVariable, name::String="")

Add variable v to optinode node. This function supports use of the @variable JuMP macro. Optionally add a base_name to the variable for printing.

source
JuMP.start_valueFunction
JuMP.start_value(graph::OptiGraph, nvref::NodeVariableRef)

Return the start value for variable nvref in graph. Note that different graphs can have different start values for node variables.

source
JuMP.set_start_valueFunction
JuMP.set_start_value(
    graph::OptiGraph, 
    nvref::NodeVariableRef, 
    value::Union{Nothing,Real}
)

Set the start value of variable nvref in graph. Note that different graphs can have different start values for node variables.

source
JuMP.add_constraintFunction
JuMP.add_constraint(graph::OptiGraph, con::JuMP.AbstractConstraint, name::String="")

Add a new constraint to graph. This method is called internall when a user uses the JuMP.@constraint macro.

source
JuMP.add_constraint(node::OptiNode, con::JuMP.AbstractConstraint, name::String="")

Add a constraint con to optinode node. This function supports use of the @constraint JuMP macro.

source
JuMP.num_constraintsFunction
JuMP.num_constraints(
    graph::OptiGraph,
    func_type::Type{<:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}}},
    set_type::Type{<:MOI.AbstractSet},
)

Return all the number of contraints in graph with func_type and set_type.

source
JuMP.num_constraints(graph::OptiGraph; count_variable_in_set_constraints=true)

Return the total number of constraints in graph. If count_variable_in_set_constraints is set to true, this also includes variable bound constraints.

source
JuMP.num_constraints(
element::OptiElement,
function_type::Type{
    <:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}},
},set_type::Type{<:MOI.AbstractSet})::Int64

Return the total number of constraints on an element.

source
JuMP.all_constraintsFunction
JuMP.all_constraints(
    graph::OptiGraph,
    func_type::Type{
        <:Union{JuMP.AbstractJuMPScalar,Vector{<:JuMP.AbstractJuMPScalar}},
    },
    set_type::Type{<:MOI.AbstractSet}
)

Return all of the constraints in graph with func_type and set_type.

source
JuMP.all_constraints(graph::OptiGraph)

Return all of the constraints in graph (all function and set types).

source
JuMP.objective_valueFunction
JuMP.objective_value(graph::OptiGraph)

Retrieve the current objective value on optigraph graph.

source
JuMP.dual_objective_valueFunction
JuMP.dual_objective_value(graph::OptiGraph; result::Int=1)

Return the dual objective value for graph. Specify result for cases when a solver returns multiple results.

source
JuMP.objective_boundFunction
JuMP.objective_bound(graph::OptiGraph)

Return the objective bound for the current solution for graph.

source
JuMP.set_objectiveFunction
JuMP.set_objective(
    graph::OptiGraph, 
    sense::MOI.OptimizationSense, 
    func::JuMP.AbstractJuMPScalar
)

Set the objective function and objective sense for graph. This method is called internally when a user uses the JuMP.@objective macro.

source
JuMP.set_objective_coefficientFunction
JuMP.set_objective_coefficient(
    graph::OptiGraph, 
    variable::NodeVariableRef, 
    coeff::Real
)

Set the objective function coefficient for variable to coefficient coeff.

source
JuMP.set_optimizerFunction
JuMP.set_optimizer(
    graph::OptiGraph, 
    JuMP.@nospecialize(optimizer_constructor); 
    add_bridges::Bool=true
)

Set the optimizer on graph by passing an optimizer_constructor.

source
JuMP.set_optimizer(
    node::OptiNode, 
    JuMP.@nospecialize(optimizer_constructor); 
    add_bridges::Bool=true
)

Set the optimizer for an optinode.This internally creates a new optigraph that is used to optimize the node. Calling this method on a node returns the newly created graph.

source
JuMP.add_nonlinear_operatorFunction
JuMP.add_nonlinear_operator(
    graph::OptiGraph,
    dim::Int,
    f::Function,
    args::Vararg{Function,N};
    name::Symbol=Symbol(f),
) where {N}

Add a nonlinear operator to a graph.

source
JuMP.optimize!Function
JuMP.optimize!(
    graph::OptiGraph;
    kwargs...,
)

Optimize graph using the current set optimizer.

source
JuMP.termination_statusFunction
JuMP.termination_status(graph::OptiGraph)

Return the solver termination status of graph if a solver has been executed.

source
JuMP.primal_statusFunction
JuMP.primal_status(graph::OptiGraph; result::Int=1)

Return the primal status of graph if a solver has been executed.

source
JuMP.dual_statusFunction
JuMP.dual_status(graph::OptiGraph; result::Int=1)

Return the dual status of graph if a solver has been executed.

source
JuMP.relative_gapFunction
JuMP.relative_gap(graph::OptiGraph)

Return the relative gap in the current solution for graph.

source
JuMP.constraint_ref_with_indexFunction
JuMP.constraint_ref_with_index(
element::OptiElement, 
idx::MOI.ConstraintIndex{<:MOI.AbstractScalarFunction, <:MOI.AbstractScalarSet}
)

Return a ConstraintRef given an optigraph element and MOI.ConstraintIndex. Note that the index is the index corresponding to the graph backend, not the element index.

source
JuMP.constraint_ref_with_index(backend::GraphMOIBackend, idx::MOI.Index)

Return the constraint reference (or variable reference) associated with the graph index in backend. Returns a JuMP.ConstraintRef (or NodeVariableRef) object.

source

Interop with JuMP.jl

Plasmo.set_jump_modelFunction
Set a JuMP.Model to `node`. This copies the model data over and does not mutate

the model in any way.

source

Graph Projections

Plasmo.GraphProjectionType
GraphProjection

A mapping between OptiGraph elements (nodes and edges) and elements in a graph projection. A graph projection can be for example a hypergraph, a bipartite graph or a standard graph.

source
Plasmo.hyper_projectionFunction
hyper_projection(graph::OptiGraph)

Retrieve a hypergraph representation of the optigraph graph. Returns a GraphProjection that maps elements between the optigraph and the projected graph.

source
Plasmo.edge_hyper_projectionFunction
edge_hyper_projection(graph::OptiGraph)

Retrieve an edge-hypergraph representation of the optigraph graph. This is sometimes called the dual-hypergraph representation of a hypergraph.

source
Plasmo.clique_projectionFunction
clique_projection(graph::OptiGraph)

Retrieve a standard graph representation of graph. The projection contains a standard Graphs.Graph and a mapping between its elements and the given optigraph. This projection works by creating an edge for each pair of nodes in each hyperedge.

source
Plasmo.edge_clique_projectionFunction
edge_clique_projection(graph::OptiGraph)

Retrieve the edge-graph representation of optigraph graph. This is sometimes called the line graph of a hypergraph.

source
Plasmo.bipartite_projectionFunction
bipartite_graph(graph::OptiGraph)

Create a bipartite graph representation from graph. The bipartite graph contains two sets of vertices corresponding to optinodes and optiedges respectively.

source

Partitioning and Aggregation

Plasmo.PartitionType
Partition

A data structure that describes a (possibly recursive) graph partition.

source
Plasmo.assemble_optigraphFunction
assemble_optigraph(nodes::Vector{<:OptiNode}, edges::Vector{OptiEdge})

Create a new optigraph from a collection of nodes and edges.

source
Assemble a new optigraph from a given `Partition`.
source
Plasmo.apply_partition!Function
apply_partition!(graph::OptiGraph, partition::Partition)

Generate subgraphs in an optigraph using a partition.

source
Plasmo.aggregateFunction
aggregate(graph::OptiGraph; name=gensym())

Aggregate an optigraph into a graph containing a single optinode. An optional name can be used to name the new optigraph. Returns the new optinode (which points to a new graph with source_graph(node)) and a mapping from the original graph variables and constraints to the new node variables and constraints.

source
Plasmo.aggregate_to_depthFunction
aggregate_to_depth(graph::OptiGraph, max_depth::Int64=0)

Aggregate graph by converting subgraphs into optinodes. The max_depth determines how many levels of subgraphs remain in the new aggregated optigraph. For example, a max_depth of 0 signifies there should be no subgraphs in the aggregated optigraph. Return a new aggregated optigraph and reference map that maps elements from the old optigraph to the new aggregate optigraph.

source
Plasmo.aggregate_to_depth!Function
aggregate_to_depth!(graph::OptiGraph, max_depth::Int64=0)

Aggregate graph by converting subgraphs into optinodes. The max_depth determines how many levels of subgraphs remain in the new aggregated optigraph. For example, a max_depth of 0 signifies there should be no subgraphs in the aggregated optigraph. This version of the method modifies the optigraph and transforms it into the aggregated version.

source

Graph Topology

Graphs.all_neighborsFunction
Graphs.all_neighbors(hyper::HyperGraphProjection, node::OptiNode)

Retrieve the optinode neighbors of node in the optigraph graph. Uses an underlying hypergraph to query for neighbors.

source
Graphs.induced_subgraphFunction
Graphs.induced_subgraph(graph::OptiGraph, nodes::Vector{OptiNode})

Create an induced subgraph of optigraph given a vector of optinodes.

source
Graphs.neighborhoodFunction
neighborhood(
    hyper::HyperGraphProjection, 
    nodes::Vector{OptiNode}, 
    distance::Int64
)::Vector{OptiNode}

Return the optinodes within distance of the given nodes in the optigraph graph.

source
Plasmo.incident_edgesFunction
incident_edges(hyper::HyperGraphProjection, nodes::Vector{OptiNode})

Retrieve incident edges to a set of optinodes.

incident_edges(hyper::HyperGraphProjection, node::OptiNode)

Retrieve incident edges to a single optinode.

source
Plasmo.induced_edgesFunction
induced_edges(graph::OptiGraph, nodes::Vector{OptiNode})

Retrieve induced edges to a set of optinodes.

source
Plasmo.identify_edgesFunction
identify_edges(hyper::HyperGraphProjection, node_vectors::Vector{Vector{OptiNode}})

Identify induced edges and edge separators from a vector of optinode partitions.

Arguments

  • hyper::HyperGraphProjection: A HyperGraphProjection obtained from hyper_projection.
  • node_vectors::Vector{Vector{OptiNode}}: A vector of vectors that contain OptiNodes.

Returns

  • partition_optiedges::Vector{Vector{OptiEdge}}: The OptiEdge vectors for each partition.
  • cross_optiedges::Vector{OptiEdge}: A vector of optiedges that cross partitions.
source
Plasmo.identify_nodesFunction
identify_nodes(hyper::HyperGraphProjection, node_vectors::Vector{Vector{OptiEdge}})

Identify induced nodes and node separators from a vector of optiedge partitions.

source
Plasmo.expandFunction
expand(hyper::HyperGraphProjection, subgraph::OptiGraph, distance::Int64)

Return a new expanded subgraph given the optigraph graph and an existing subgraph subgraph. The returned subgraph contains the expanded neighborhood within distance of the given subgraph.

source

<!– @docs PlasmoPlots.layout_plot PlasmoPlots.matrix_plot –>