The Graph object

TenNetLib.jl defines its own undirected graph object, the Graph. Currently only used for the Tree Tensor Network (TTN) codes.

TenNetLib.GraphType
mutable struct Graph{T}
    nodes::Set{T}
    edges::Dict{T, Set{T}}
end

Undirected graph where nodes are of type T.

  • nodes::Set{T}: Holds the nodes of the graph.
  • edges::Dict{T, Set{T}}: Holds the edges of the graph. For a given node as key, holds all the connected nodes as value of the Dict.
source
TenNetLib.GraphMethod
function Graph{T}(nodes::Set{T}) where T
function Graph{T}(nodes::Vector{T}) where T

Constructor of Graph with a list of nodes and empty edges.

  • nodes: Intial nodes.
source
TenNetLib.getnodesMethod
function getnodes(graph::Graph{T}) where T = copy(graph.nodes)

Returns (shallow copy of) nodes in the Graph.

source
TenNetLib.hasnodeMethod
function hasnode(graph::Graph{T}, node::T) where T

Checks whether a node is in the Graph.

source
TenNetLib.addedge!Method
function addedge!(graph::Graph{T}, node1::T, node2::T) where T

Adds an edge between node1 and node2. If node1 or node2 are not present in the Graph, they are added.

source
TenNetLib.isneighborMethod
function isneighbor(graph::Graph{T}, node1::T, node2::T)::Bool where T

Checks whether node1 and node2 are connected by an edge.

source
TenNetLib.bfsMethod
function bfs(graph::Graph{T},
             source::T,
             destination::Union{Nothing, T} = nothing) where T

Performs a full BFS starting from the node source (and optionally, to the destination).

Return values

  • ::Dict{T, Int}: Distances of nodes (key) in the BFS path.
  • ::Dict{T, T}: Parents of nodes (key) in the BFS path.
source
TenNetLib.nodes_from_bfsMethod
function nodes_from_bfs(graph::Graph{T}, source::T;
                        reverse::Bool = false) where T

function nodes_from_bfs(graph::Graph{T}, source::T,
                        destinations::Union{Set{T}, Vector{T}};
                        reverse::Bool = false) where T

Returns the Vector of nodes in the BFS path from the source (optionally, towards the destinations). If reverse=true returns the reverse order of nodes.

source
TenNetLib.shortest_pathMethod
function shortest_path(graph::Graph{T}, source::T, destination::T) where T

Returns the shortest path between source and destination in a Graph.

source
TenNetLib.nextnode_in_pathMethod
function nextnode_in_path(graph::Graph{T}, source::T, destination::T, n=1) where T

Returns the next node in the shortest path between source and destination in a Graph. Optionally, finds nth next-node in the path.

source
TenNetLib.has_cycleMethod
function has_cycle(graph::Graph{T}) where T

Checks whether a Graph has cycles/loops in it.

source
TenNetLib.find_sum_central_nodeMethod
function find_sum_central_node(graph::Graph{T}) where T
function find_sum_central_node(graph::Graph{T}, nodes::Set{T}) where T
function find_sum_central_node(graph::Graph{T}, nodes::Vector{T}) where T

Finds the sum central node node of a Graph. Optionally, when nodes is specified, finds the central node with respect to the nodes.

source
TenNetLib.find_eccentric_central_nodeMethod
function find_eccentric_central_node(graph::Graph{T}) where T
function find_eccentric_central_node(graph::Graph{T}, nodes::Set{T}) where T
function find_eccentric_central_node(graph::Graph{T}, nodes::Vector{T}) where T

Finds the eccentric central node of a Graph. Optionally, when nodes is specified, finds the central node with respect to the nodes.

source
Base.copyMethod
function Base.copy(graph::Graph{T}) where T

Shallow copy of Graph.

source
Base.getindexMethod
function Base.getindex(graph::Graph{T}, node::T) where T

Returns the edges for a given node::T as an index.

source
Base.setindex!Method
function Base.setindex!(graph::Graph{T}, neighbors::Set{T}, node::T) where T
function Base.setindex!(graph::Graph{T}, neighbors::Vector{T}, node::T) where T

Sets the edges=neighbors for a given node::T as an index.

source
Base.:==Method
function Base.:(==)(graph1::Graph{T}, graph2::Graph{T}) where T

Equality between two Graph objects.

source