class Graphlb::DataStructures::DirectedGraph
- Graphlb::DataStructures::DirectedGraph
- Reference
- Object
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.crConstructors
-
.new
creats a graph whith no vertices and edges(empty-graph)
Instance Method Summary
-
#add_edge(from_node : Node, to_node : Node, weight)
Creates an edge between the nodes provided as the parametes.
-
#add_vertex(name)
Creates a new vertex with in the graph.
-
#get_vertices
returns informaton about all the vertices inside the graph
-
#remove_edge(from_node : Node, to_node : Node)
Removes the edge form the from_node to the to_node present in the graph
-
#vertices : Array(Graphlb::DataStructures::Node)
All the vertices of the graph are stored in this variables
Constructor Detail
Instance Method Detail
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
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.
returns informaton about all the vertices inside the graph
@return : list of all vertices/nodes in the graph
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
All the vertices of the graph are stored in this variables