Skip to content

Commit e8fcf0b

Browse files
committed
change _edges to _edgelist to be consistent with Vertex class
1 parent 49ab6f0 commit e8fcf0b

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

pgraph/PGraph.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, arg=None, metric=None, heuristic=None, verbose=False):
2121
# we use a list and a dict, the list respects the order of adding
2222
self._vertexlist = []
2323
self._vertexdict = {}
24-
self._edges = set()
24+
self._edgelist = set()
2525
self._verbose = verbose
2626
if metric is None:
2727
self.metric = 'L2'
@@ -213,8 +213,8 @@ def remove(self, x):
213213
# remove an edge
214214

215215
# remove edge from the edgelist of connected vertices
216-
x.v1._edges.remove(x)
217-
x.v2._edges.remove(x)
216+
x.v1._edgelist.remove(x)
217+
x.v2._edgelist.remove(x)
218218

219219
# indicate that connectivity has changed
220220
x.v1._connectivitychange = True
@@ -225,13 +225,13 @@ def remove(self, x):
225225
x.v2 = None
226226

227227
# remove from list of all edges
228-
self._edges.remove(x)
228+
self._edgelist.remove(x)
229229

230230
elif isinstance(x, Vertex):
231231
# remove a vertex
232232

233233
# remove all edges of this vertex
234-
for edge in copy.copy(x._edges):
234+
for edge in copy.copy(x._edgelist):
235235
self.remove(edge)
236236

237237
# remove from list and dict of all edges
@@ -245,7 +245,7 @@ def show(self):
245245
for v in self._vertexlist:
246246
print(' ' + str(v))
247247
print('edges:')
248-
for e in self._edges:
248+
for e in self._edgelist:
249249
print(' ' + str(e))
250250

251251
@property
@@ -266,7 +266,7 @@ def ne(self):
266266
:return: Number of vertices
267267
:rtype: int
268268
"""
269-
return len(self._edges)
269+
return len(self._edgelist)
270270

271271
@property
272272
def nc(self):
@@ -481,9 +481,9 @@ def edges(self):
481481
482482
:seealso: :meth:`Vertex.edges`
483483
"""
484-
return self._edges
484+
return self._edgelist
485485

486-
def plot(self, colorcomponents=True, vertex=None, edge=None, text={}, block=True, ax=None):
486+
def plot(self, colorcomponents=True, vertex=None, edge=None, text={}, block=False, ax=None):
487487
"""
488488
Plot the graph
489489
@@ -770,7 +770,7 @@ def connectivity(self, vertices=None):
770770
if vertices is None:
771771
vertices = self
772772
for n in vertices:
773-
c.append(len(n._edges))
773+
c.append(len(n._edgelist))
774774
return c
775775

776776
def degree(self):
@@ -943,7 +943,7 @@ def samecomponent(self, v1, v2):
943943
# # remove edges from neighbour's edge list
944944
# for e in v.edges():
945945
# next = e.next(v)
946-
# next._edges.remove(e)
946+
# next._edgelist.remove(e)
947947
# next._connectivitychange = True
948948

949949
# # remove references from the graph
@@ -953,7 +953,7 @@ def samecomponent(self, v1, v2):
953953
# del self._vertexdict[key]
954954
# break
955955

956-
# v._edges = [] # remove all references to edges
956+
# v._edgelist = [] # remove all references to edges
957957
# --------------------------------------------------------------------------- #
958958

959959
def path_BFS(self, S, G, verbose=False, summary=False):
@@ -1370,10 +1370,10 @@ def endpoints(self):
13701370
# edge object.
13711371
# """
13721372
# # remove this edge from the edge list of both end nodes
1373-
# if self in self.v1._edges:
1374-
# self.v1._edges.remove(self)
1375-
# if self in self.v2._edges:
1376-
# self.v2._edges.remove(self)
1373+
# if self in self.v1._edgelist:
1374+
# self.v1._edgelist.remove(self)
1375+
# if self in self.v2._edgelist:
1376+
# self.v2._edgelist.remove(self)
13771377

13781378
# # indicate that connectivity has changed
13791379
# self.v1._connectivitychange = True
@@ -1393,20 +1393,20 @@ class Vertex:
13931393
Each vertex has:
13941394
- ``name``
13951395
- ``label`` an int indicating which graph component contains it
1396-
- ``_edges`` a list of edge objects that connect this vertex to others
1396+
- ``_edgelist`` a list of edge objects that connect this vertex to others
13971397
- ``coord`` the coordinate in an embedded graph (optional)
13981398
"""
13991399

14001400
def __init__(self, coord=None, name=None):
1401-
self._edges = []
1401+
self._edgelist = []
14021402
if coord is None:
14031403
self.coord = None
14041404
else:
14051405
self.coord = np.r_[coord]
14061406
self.name = name
14071407
self.label = None
14081408
self._connectivitychange = True
1409-
self._edges = []
1409+
self._edgelist = []
14101410
self._graph = None # reference to owning graph
14111411
# print('Vertex init', type(self))
14121412

@@ -1424,7 +1424,7 @@ def neighbours(self):
14241424
14251425
.. note:: For a directed graph the neighbours are those on edges leaving this vertex
14261426
"""
1427-
return [e.next(self) for e in self._edges]
1427+
return [e.next(self) for e in self._edgelist]
14281428

14291429
def isneighbour(self, vertex):
14301430
"""
@@ -1438,7 +1438,7 @@ def isneighbour(self, vertex):
14381438
For a directed graph this is true only if the edge is from ``self`` to
14391439
``vertex``.
14401440
"""
1441-
return vertex in [e.next(self) for e in self._edges]
1441+
return vertex in [e.next(self) for e in self._edgelist]
14421442

14431443
def incidences(self):
14441444
"""
@@ -1449,7 +1449,7 @@ def incidences(self):
14491449
14501450
.. note:: For a directed graph the edges are those leaving this vertex
14511451
"""
1452-
return [(e.next(self), e) for e in self._edges]
1452+
return [(e.next(self), e) for e in self._edgelist]
14531453

14541454
def connect(self, dest, edge=None, cost=None, edgedata=None):
14551455
"""
@@ -1485,9 +1485,9 @@ def connect(self, dest, edge=None, cost=None, edgedata=None):
14851485
e = edge
14861486
else:
14871487
e = Edge(self, dest, cost=cost, data=edgedata)
1488+
self._graph._edgelist.add(e)
14881489
self._connectivitychange = True
14891490

1490-
self._graph._edges.add(e)
14911491
return e
14921492

14931493
def edgeto(self, dest):
@@ -1522,7 +1522,7 @@ def edges(self):
15221522
- For a non-directed graph the edges are those leaving or entering
15231523
this vertex
15241524
"""
1525-
return self._edges
1525+
return self._edgelist
15261526

15271527
def heuristic_distance(self, v2):
15281528
return self._graph.heuristic(self.coord - v2.coord)
@@ -1612,9 +1612,9 @@ def connect(self, other, **kwargs):
16121612

16131613
# e = super().connect(other, **kwargs)
16141614

1615-
self._edges.append(e)
1616-
other._edges.append(e)
1617-
self._graph._edges.add(e)
1615+
self._edgelist.append(e)
1616+
other._edgelist.append(e)
1617+
self._graph._edgelist.add(e)
16181618

16191619
return e
16201620

@@ -1637,8 +1637,8 @@ def connect(self, other, **kwargs):
16371637
else:
16381638
raise TypeError('bad argument')
16391639

1640-
self._edges.append(e)
1640+
self._edgelist.append(e)
16411641
return e
16421642

16431643
def remove(self):
1644-
self._edges = None # remove all references to edges
1644+
self._edgelist = None # remove all references to edges

0 commit comments

Comments
 (0)