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}}
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 askey
, holds all the connected nodes asvalue
of 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 T
Constructor 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 T
Checks whether a node is in the Graph
.
TenNetLib.addnode!
— Methodfunction addnode!(graph::Graph{T}, node::T) where T
Adds a node to the Graph
.
TenNetLib.addedge!
— Methodfunction 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.
TenNetLib.isneighbor
— Methodfunction isneighbor(graph::Graph{T}, node1::T, node2::T)::Bool where T
Checks whether node1
and node2
are connected by an edge.
TenNetLib.bfs
— Methodfunction 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.
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 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.
TenNetLib.shortest_path
— Methodfunction shortest_path(graph::Graph{T}, source::T, destination::T) where T
Returns 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 T
Returns the next node in the shortest path between source
and destination
in a Graph
. Optionally, finds n
th next-node in the path.
TenNetLib.has_cycle
— Methodfunction has_cycle(graph::Graph{T}) where T
Checks 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 T
Finds 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 T
Finds 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 T
Shallow copy of Graph
.
Base.getindex
— Methodfunction Base.getindex(graph::Graph{T}, node::T) where T
Returns 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 T
Sets the edges=neighbors
for a given node::T
as an index.
Base.:==
— Methodfunction Base.:(==)(graph1::Graph{T}, graph2::Graph{T}) where T
Equality between two Graph
objects.