class Graphlb::DataStructures::UnDirectedGraph

Overview

An undirected graph is a graph that is made up of a set of vertices connected by edges, where the edges have a not direction and weight are associated with the edges.

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

Defined in:

graphlb/data_structures/undirectedgraph.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

@param : to_node

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

@param : to_node.

@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]