Skip to content

Commit 0ff2909

Browse files
committed
modified docs
1 parent 2956049 commit 0ff2909

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

pydatastructs/graphs/adjacency_list.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,24 @@ def remove_vertex(self, name):
5252
node_obj.adjacent.remove(name)
5353

5454
def add_edge(self, source, target, cost=None):
55+
error_msg = "Vertex %s is not present in the graph. \
56+
Call Graph.add_vertex() to add a new \
57+
vertex. Graph.add_edge is only responsible \
58+
for adding edges and it will not add new \
59+
vertices on its own. This is done to maintain \
60+
clear separation between the functionality of \
61+
the two methods."
5562
if not hasattr(self, source):
56-
raise ValueError("Vertex %s is not present in the graph."
57-
" Call Graph.add_vertex() to add a new"
58-
" vertex. Graph.add_edge is only responsible"
59-
" for adding edges and it will not add new"
60-
" vertices on its own. This is done to maintain"
61-
" clear separation between the functionality of"
62-
" the two methods." %(source))
63-
elif not hasattr(self, target):
64-
raise ValueError("Vertex %s is not present in the graph."
65-
" Call Graph.add_vertex() to add a new"
66-
" vertex. Graph.add_edge is only responsible"
67-
" for adding edges and it will not add new"
68-
" vertices on its own. This is done to maintain"
69-
" clear separation between the functionality of"
70-
" the two methods." %(target))
71-
else:
72-
source, target = self.__getattribute__(source), \
73-
self.__getattribute__(target)
74-
source.add_adjacent_node(target.name)
75-
if cost is not None:
76-
self.edge_weights[source.name + "_" + target.name] = \
77-
GraphEdge(source, target, cost)
63+
raise ValueError(error_msg %(source))
64+
if not hasattr(self, target):
65+
raise ValueError(error_msg %(target))
66+
67+
source, target = self.__getattribute__(source), \
68+
self.__getattribute__(target)
69+
source.add_adjacent_node(target.name)
70+
if cost is not None:
71+
self.edge_weights[source.name + "_" + target.name] = \
72+
GraphEdge(source, target, cost)
7873

7974
def get_edge(self, source, target):
8075
return self.edge_weights.get(

pydatastructs/graphs/graph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ class Graph(object):
5252
5353
Note
5454
====
55+
5556
Steps to create a graph:
57+
5658
1. Create nodes (AdjacencyListGraphNode or AdjacencyListMatrixNode)
59+
5760
2. Add nodes to the graph
61+
5862
3. Add edges b/w these nodes
5963
6064
"""

0 commit comments

Comments
 (0)