@@ -21,7 +21,7 @@ def __init__(self, arg=None, metric=None, heuristic=None, verbose=False):
21
21
# we use a list and a dict, the list respects the order of adding
22
22
self ._vertexlist = []
23
23
self ._vertexdict = {}
24
- self ._edges = set ()
24
+ self ._edgelist = set ()
25
25
self ._verbose = verbose
26
26
if metric is None :
27
27
self .metric = 'L2'
@@ -213,8 +213,8 @@ def remove(self, x):
213
213
# remove an edge
214
214
215
215
# 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 )
218
218
219
219
# indicate that connectivity has changed
220
220
x .v1 ._connectivitychange = True
@@ -225,13 +225,13 @@ def remove(self, x):
225
225
x .v2 = None
226
226
227
227
# remove from list of all edges
228
- self ._edges .remove (x )
228
+ self ._edgelist .remove (x )
229
229
230
230
elif isinstance (x , Vertex ):
231
231
# remove a vertex
232
232
233
233
# remove all edges of this vertex
234
- for edge in copy .copy (x ._edges ):
234
+ for edge in copy .copy (x ._edgelist ):
235
235
self .remove (edge )
236
236
237
237
# remove from list and dict of all edges
@@ -245,7 +245,7 @@ def show(self):
245
245
for v in self ._vertexlist :
246
246
print (' ' + str (v ))
247
247
print ('edges:' )
248
- for e in self ._edges :
248
+ for e in self ._edgelist :
249
249
print (' ' + str (e ))
250
250
251
251
@property
@@ -266,7 +266,7 @@ def ne(self):
266
266
:return: Number of vertices
267
267
:rtype: int
268
268
"""
269
- return len (self ._edges )
269
+ return len (self ._edgelist )
270
270
271
271
@property
272
272
def nc (self ):
@@ -481,9 +481,9 @@ def edges(self):
481
481
482
482
:seealso: :meth:`Vertex.edges`
483
483
"""
484
- return self ._edges
484
+ return self ._edgelist
485
485
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 ):
487
487
"""
488
488
Plot the graph
489
489
@@ -770,7 +770,7 @@ def connectivity(self, vertices=None):
770
770
if vertices is None :
771
771
vertices = self
772
772
for n in vertices :
773
- c .append (len (n ._edges ))
773
+ c .append (len (n ._edgelist ))
774
774
return c
775
775
776
776
def degree (self ):
@@ -943,7 +943,7 @@ def samecomponent(self, v1, v2):
943
943
# # remove edges from neighbour's edge list
944
944
# for e in v.edges():
945
945
# next = e.next(v)
946
- # next._edges .remove(e)
946
+ # next._edgelist .remove(e)
947
947
# next._connectivitychange = True
948
948
949
949
# # remove references from the graph
@@ -953,7 +953,7 @@ def samecomponent(self, v1, v2):
953
953
# del self._vertexdict[key]
954
954
# break
955
955
956
- # v._edges = [] # remove all references to edges
956
+ # v._edgelist = [] # remove all references to edges
957
957
# --------------------------------------------------------------------------- #
958
958
959
959
def path_BFS (self , S , G , verbose = False , summary = False ):
@@ -1370,10 +1370,10 @@ def endpoints(self):
1370
1370
# edge object.
1371
1371
# """
1372
1372
# # 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)
1377
1377
1378
1378
# # indicate that connectivity has changed
1379
1379
# self.v1._connectivitychange = True
@@ -1393,20 +1393,20 @@ class Vertex:
1393
1393
Each vertex has:
1394
1394
- ``name``
1395
1395
- ``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
1397
1397
- ``coord`` the coordinate in an embedded graph (optional)
1398
1398
"""
1399
1399
1400
1400
def __init__ (self , coord = None , name = None ):
1401
- self ._edges = []
1401
+ self ._edgelist = []
1402
1402
if coord is None :
1403
1403
self .coord = None
1404
1404
else :
1405
1405
self .coord = np .r_ [coord ]
1406
1406
self .name = name
1407
1407
self .label = None
1408
1408
self ._connectivitychange = True
1409
- self ._edges = []
1409
+ self ._edgelist = []
1410
1410
self ._graph = None # reference to owning graph
1411
1411
# print('Vertex init', type(self))
1412
1412
@@ -1424,7 +1424,7 @@ def neighbours(self):
1424
1424
1425
1425
.. note:: For a directed graph the neighbours are those on edges leaving this vertex
1426
1426
"""
1427
- return [e .next (self ) for e in self ._edges ]
1427
+ return [e .next (self ) for e in self ._edgelist ]
1428
1428
1429
1429
def isneighbour (self , vertex ):
1430
1430
"""
@@ -1438,7 +1438,7 @@ def isneighbour(self, vertex):
1438
1438
For a directed graph this is true only if the edge is from ``self`` to
1439
1439
``vertex``.
1440
1440
"""
1441
- return vertex in [e .next (self ) for e in self ._edges ]
1441
+ return vertex in [e .next (self ) for e in self ._edgelist ]
1442
1442
1443
1443
def incidences (self ):
1444
1444
"""
@@ -1449,7 +1449,7 @@ def incidences(self):
1449
1449
1450
1450
.. note:: For a directed graph the edges are those leaving this vertex
1451
1451
"""
1452
- return [(e .next (self ), e ) for e in self ._edges ]
1452
+ return [(e .next (self ), e ) for e in self ._edgelist ]
1453
1453
1454
1454
def connect (self , dest , edge = None , cost = None , edgedata = None ):
1455
1455
"""
@@ -1485,9 +1485,9 @@ def connect(self, dest, edge=None, cost=None, edgedata=None):
1485
1485
e = edge
1486
1486
else :
1487
1487
e = Edge (self , dest , cost = cost , data = edgedata )
1488
+ self ._graph ._edgelist .add (e )
1488
1489
self ._connectivitychange = True
1489
1490
1490
- self ._graph ._edges .add (e )
1491
1491
return e
1492
1492
1493
1493
def edgeto (self , dest ):
@@ -1522,7 +1522,7 @@ def edges(self):
1522
1522
- For a non-directed graph the edges are those leaving or entering
1523
1523
this vertex
1524
1524
"""
1525
- return self ._edges
1525
+ return self ._edgelist
1526
1526
1527
1527
def heuristic_distance (self , v2 ):
1528
1528
return self ._graph .heuristic (self .coord - v2 .coord )
@@ -1612,9 +1612,9 @@ def connect(self, other, **kwargs):
1612
1612
1613
1613
# e = super().connect(other, **kwargs)
1614
1614
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 )
1618
1618
1619
1619
return e
1620
1620
@@ -1637,8 +1637,8 @@ def connect(self, other, **kwargs):
1637
1637
else :
1638
1638
raise TypeError ('bad argument' )
1639
1639
1640
- self ._edges .append (e )
1640
+ self ._edgelist .append (e )
1641
1641
return e
1642
1642
1643
1643
def remove (self ):
1644
- self ._edges = None # remove all references to edges
1644
+ self ._edgelist = None # remove all references to edges
0 commit comments