class Graphlb::DataStructures::DirectedGraph

Overview

A directed graph (or digraph) is a graph that is made up of a set of vertices connected by edges, where the edges have a direction and weight associated with them.

The class provides various methods which can be used to define/modify a simple directed graph with edge-weight Associated to each edge. Here we are using the adjacency list approach to define a directed graph which can be modified later as per convience

Defined in:

graphlb/data_structures/directedgraph.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

creats a graph whith no vertices and edges(empty-graph)


[View source]

Instance Method Detail

def add_edge(from_node : Node, to_node : Node, weight) #

Creates an edge between the nodes provided as the parametes.

If the form_node and to_node_ are same then also the node is created witha cycle in the graph.

If any of the from_node or to_node is not found in the graph a exception is raised.

@param : from_node, the vertex from which the directed edge starts.

@param : to_node, the vertex to which the directed edge ends.

@param : weight, the weight of the edge created

@return : the list of all edges of the from_node


[View source]
def add_vertex(name) #

Creates a new vertex with in the graph.

The vertex name is expected to be unique to differentiate between the vertex within the graph and perform operations on them.

@param [String] name, to define the name of the vertex hwich is expected to be unique.

@return [Vertex] newly created node.


[View source]
def get_vertices #

returns informaton about all the vertices inside the graph

@return : list of all vertices/nodes in the graph


[View source]
def remove_edge(from_node : Node, to_node : Node) #

Removes the edge form the from_node to the to_node present in the graph

If the form_node and to_node_ are same and the edge is present between them the edge is removed else excetion is raised

If any of the from_node or to_node is not found in the graph a exception is raised.

If edge between the from_node and the to_node is not found in the graph a exception is raised

@param : from_node, the node from which the edge starts,

@param : to_node, the node where the edge ends,

@return : list of all edges from the from node


[View source]
def vertices : Array(Graphlb::DataStructures::Node) #

All the vertices of the graph are stored in this variables


[View source]