Graphs
We work with various graph structures in this package, including directed and undirected graphs, as well as specialized graph types for specific applications.
VLDataScienceMachineLearningPackage.children
— Functionfunction children(graph::T, node::MyGraphNodeModel) -> Set{Int64} where T <: AbstractGraphModel
Returns the set of child node IDs for a given node in the graph.
Arguments
graph::T
: The graph to search whereT <: AbstractGraphModel
.node::MyGraphNodeModel
: The node to find children for.
Returns
Set{Int64}
: The set of child node IDs.
VLDataScienceMachineLearningPackage.weight
— Functionfunction weight(graph::T, source::Int64, target::Int64, edgemodels::Dict{Int64, MyGraphEdgeModel}) -> Any where T <: AbstractGraphModel
Returns the weight of the edge between two nodes in the graph.
Arguments
graph::T
: The graph to search whereT <: AbstractGraphModel
.source::Int64
: The ID of the source node.target::Int64
: The ID of the target node.
Returns
Any
: The weight of the edge between the source and target nodes. We have this asAny
to allow for flexibility in edge weights, which can be of any type.
function weight(graph::T, source::Int64, target::Int64) -> Float64 where T <: AbstractGraphModel
This function returns the weight of the edge between two nodes in a graph model.
Arguments
graph::T
: the graph model to search. This is a subtype ofAbstractGraphModel
.source::Int64
: the source node id.target::Int64
: the target node id.
Returns
- the weight of the edge between the source and target nodes.
VLDataScienceMachineLearningPackage.walk
— Functionfunction walk(graph::T, startnode::MyGraphNodeModel, algorithm::AbstractGraphTraversalAlgorithm;
verbose::Bool = false) where T <: AbstractGraphModel
The walk
function traverses the graph starting from a given node using the specified algorithm (either Depth-First Search or Breadth-First Search). It maintains a set of visited nodes to avoid cycles and ensure that each node is processed only once.
Arguments
graph::T
: The graph to traverse.startnode::MyGraphNodeModel
: The node to start the traversal from.algorithm::AbstractGraphTraversalAlgorithm
: The algorithm to use for the traversal. This can be either an instance ofDepthFirstSearchAlgorithm
orBreadthFirstSearchAlgorithm
. Default isBreadthFirstSearchAlgorithm
.verbose::Bool
: Whether to print verbose output (default is false).
Returns
Array{Int64,1}
: The collection of visited node IDs in the order they were visited.
VLDataScienceMachineLearningPackage.findshortestpath
— Functionfindshortestpath(graph::T, start::MyGraphNodeModel;
algorithm::AbstractGraphSearchAlgorithm = BellmanFordAlgorithm()) where T <: AbstractGraphModel
The function computes the shortest paths from a starting node to all other nodes in a graph model.
Arguments
graph::T
: the graph model to search. This is a subtype ofAbstractGraphModel
.start::MyGraphNodeModel
: the node to start the search from.algorithm::MyAbstractGraphSearchAlgorithm
: the algorithm to use for the search. The default isBellmanFordAlgorithm
, but it can also beDijkstraAlgorithm
.
Returns
- a tuple of two dictionaries: the first dictionary contains the distances from the starting node to all other nodes, and the second dictionary contains the previous node in the shortest path from the starting node to all other nodes.