The Graph object
TenNetLib.jl defines its own undirected graph object, the Graph. Currently only used for the Tree Tensor Network (TTN) codes.
TenNetLib.Graph — Typemutable struct Graph{T}
nodes::Set{T}
edges::Dict{T, Set{T}}
endUndirected 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 askey, holds all the connected nodes asvalueof theDict.
TenNetLib.Graph — Methodfunction Graph{T}()Contructor of empty Graph.
TenNetLib.Graph — Methodfunction Graph{T}(nodes::Set{T}) where T
function Graph{T}(nodes::Vector{T}) where TConstructor of Graph with a list of nodes and empty edges.
nodes: Intial nodes.
TenNetLib.getnodes — Methodfunction getnodes(graph::Graph{T}) where T = copy(graph.nodes)Returns (shallow copy of) nodes in the Graph.
TenNetLib.hasnode — Methodfunction hasnode(graph::Graph{T}, node::T) where TChecks whether a node is in the Graph.
TenNetLib.addnode! — Methodfunction addnode!(graph::Graph{T}, node::T) where TAdds a node to the Graph.
TenNetLib.addedge! — Methodfunction addedge!(graph::Graph{T}, node1::T, node2::T) where TAdds an edge between node1 and node2. If node1 or node2 are not present in the Graph, they are added.
TenNetLib.isneighbor — Methodfunction isneighbor(graph::Graph{T}, node1::T, node2::T)::Bool where TChecks whether node1 and node2 are connected by an edge.
TenNetLib.bfs — Methodfunction bfs(graph::Graph{T},
source::T,
destination::Union{Nothing, T} = nothing) where TPerforms a 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.
TenNetLib.nodes_from_bfs — Methodfunction 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 TReturns the Vector of nodes in the BFS path from the source (optionally, towards the destinations). If reverse=true returns the reverse order of nodes.
TenNetLib.shortest_path — Methodfunction shortest_path(graph::Graph{T}, source::T, destination::T) where TReturns the shortest path between source and destination in a Graph.
TenNetLib.nextnode_in_path — Methodfunction nextnode_in_path(graph::Graph{T}, source::T, destination::T, n=1) where TReturns the next node in the shortest path between source and destination in a Graph. Optionally, finds nth next-node in the path.
TenNetLib.has_cycle — Methodfunction has_cycle(graph::Graph{T}) where TChecks whether a Graph has cycles/loops in it.
TenNetLib.find_sum_central_node — Methodfunction 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 TFinds the sum central node node of a Graph. Optionally, when nodes is specified, finds the central node with respect to the nodes.
TenNetLib.find_eccentric_central_node — Methodfunction 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 TFinds the eccentric central node of a Graph. Optionally, when nodes is specified, finds the central node with respect to the nodes.
Base.copy — Methodfunction Base.copy(graph::Graph{T}) where TShallow copy of Graph.
Base.getindex — Methodfunction Base.getindex(graph::Graph{T}, node::T) where TReturns the edges for a given node::T as an index.
Base.setindex! — Methodfunction Base.setindex!(graph::Graph{T}, neighbors::Set{T}, node::T) where T
function Base.setindex!(graph::Graph{T}, neighbors::Vector{T}, node::T) where TSets the edges=neighbors for a given node::T as an index.
Base.:== — Methodfunction Base.:(==)(graph1::Graph{T}, graph2::Graph{T}) where TEquality between two Graph objects.