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.childrenFunction
function 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 where T <: AbstractGraphModel.
  • node::MyGraphNodeModel: The node to find children for.

Returns

  • Set{Int64}: The set of child node IDs.
source
VLDataScienceMachineLearningPackage.weightFunction
function 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 where T <: 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 as Any to allow for flexibility in edge weights, which can be of any type.
source
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 of AbstractGraphModel.
  • source::Int64: the source node id.
  • target::Int64: the target node id.

Returns

  • the weight of the edge between the source and target nodes.
source
VLDataScienceMachineLearningPackage.walkFunction
function 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 of DepthFirstSearchAlgorithm or BreadthFirstSearchAlgorithm. Default is BreadthFirstSearchAlgorithm.
  • 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.
source
VLDataScienceMachineLearningPackage.findshortestpathFunction
findshortestpath(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 of AbstractGraphModel.
  • start::MyGraphNodeModel: the node to start the search from.
  • algorithm::MyAbstractGraphSearchAlgorithm: the algorithm to use for the search. The default is BellmanFordAlgorithm, but it can also be DijkstraAlgorithm.

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.
source