ModelGraph

ModelGraph

Constructor

The ModelGraph is the primary object for creating graph-based models in Plasmo.jl. A ModelGraph is a collection of ModelNodes which are connected by LinkConstraints (i.e. edges) over variables. One way to think of the structure of a ModelGraph is a HyperGraph wherein edges represent linking constraints that can link multiple ModelNode variables.

A ModelGraph does not require any arguments to construct:

mg = ModelGraph()

A ModelGraph solver can be specified upon construction using the solver keyword argument. A solver can be any JuMP compatible solver or a Plasmo.jl provided solver (see solvers section). For example, we could construct a ModelGraph that uses the IpoptSolver from the Ipopt package:

graph = ModelGraph(solver = IpoptSolver())

Adding Nodes

Nodes can be added to a ModelGraph using the add_node! function. By default, a node contains an empty JuMP Model object.

n1 = add_node!(graph)

A model can be set upon creation by providing a second argument. For example:

model = JuMP.Model()
n1 = add_node!(graph,model)  #sets model to n1

where model is a JuMP Model object. We can also set a model on a node after construction:

setmodel(n1,model)

This can be helpful in instances where a user wants to swap out a model on a node without changing the graph topology. Keep in mind however that swapping out a model will by default remove any link-constraints that involve that node. Also note that any single JuMP Model can only be assigned to a single node.

We can also iterate over the nodes in a ModelGraph using the getnodes function. For example

for node in getnodes(graph)
    println(node)
end

will print the string for every node in the ModelGraph graph.

ModelNodes can also be retrieved based on their index within a ModelGraph or vic versa. For example, since n1 was the first node added to mg, it will have an index of 1.

n1 == getnode(mg,1)   #will return true
getindex(graph,n1) == 1  #will also return true

Variables within a JuMP Model can be accessed directly from their enclosing node.

jump_model = Model()
@variable(jump_model,x >= 0)
setmodel(n1,jump_model)
println(n1[:x])    #accesses variable x on jump_model

Adding LinkConstraints

LinkConstraints are linear constraints that couple variables across different ModelNodes. The simplest way to add LinkConstraints is to use the @linkconstraint macro. This macro accepts the same input as a JuMP @constraint macro and creates linear constraints over multiple nodes within the same graph.

jump_2 = Model()
@variable(jump_2,x >= 0)
n2 = add_node!(graph,jump_2)

@linkconstraint(graph,n1[:x] == n2[:x])  #creates a linear constraint between nodes n1 and n2

Subgraph Structures

It is possible to create subgraphs within a ModelGraph object. This is helpful when a user wants to develop to separate systems and link them together within a higher level graph.

(Section TBD)

Methods

ModelGraph

The ModelGraph contains the following useful methods:

ModelGraph()

The ModelGraph Type. Represents a graph containing models (nodes) and the linkconstraints (edges) between them. A ModelGraph wraps a BasePlasmoGraph and can use its methods. A ModelGraph also wraps a LinkModel object which extends a JuMP AbstractModel to provide model management functions.

source

Get the ModelGraph objective value

source

Get node objective value

source

Get the current created JuMP model for the ModelGraph. Only created when solving using a JuMP compliant solver.

source
JuMP.setsolverMethod.

setsolver(model::AbstractModelGraph,solver::AbstractMathProgSolver)

Set the graph solver to use an AbstractMathProg compliant solver

source
JuMP.setsolverMethod.

setsolver(model::AbstractModelGraph,solver::AbstractPlasmoSolver)

Set the graph solver to use an AbstractMathProg compliant solver

source

Get the ModelGraph solver

source

ModelNode

ModelNodes contain methods for managing their contained JuMP models.

The ModelNode type

ModelNode()

Creates an empty ModelNode. Does not add it to a graph.

source

add_node!(graph::AbstractModelGraph)

Add a ModelNode to a ModelGraph.

source

setmodel(node::ModelNode,m::AbstractModel)

Set the model on a node. This will delete any link-constraints the node is currently part of

source

is_nodevar(node::ModelNode,var::AbstractJuMPScalar)

Check whether a JuMP variable belongs to a ModelNode

source

getnode(model::AbstractModel)

Get the ModelNode corresponding to a JuMP Model

source

getnode(model::AbstractModel)

Get the ModelNode corresponding to a JuMP Variable

source

LinkConstraints

getlinkconstraints(graph::AbstractModelGraph)

Return Array of all LinkConstraints in the ModelGraph graph

source

getsimplelinkconstraints(model::AbstractModelGraph)

Retrieve link-constraints that only connect two nodes"

source

gethyperlinkconstraints(model::AbstractModelGraph)

Retrieve link-constraints that connect three or more nodes"

source

getalllinkconstraints(graph::AbstractModelGraph)

Get a list containing every link constraint in the graph, including its subgraphs

source

Add a single link-constraint to the ModelGraph

source

Add a vector of link-constraints to the ModelGraph

source

getlinkconstraints(graph::AbstractModelGraph,node::ModelNode)

Return Array of LinkConstraints for the node

source

getlinkconstraints(node::ModelNode)

Return a Dictionary of LinkConstraints for each graph the node is a member of

source