@@ -66,7 +66,9 @@ def _add_edges(self, edges):
66
66
self ._add_edge (* edge )
67
67
68
68
def add_loops (self ):
69
- """Add all loops to edges."""
69
+ """
70
+ Add all loops to edges
71
+ """
70
72
self ._add_edges ((x , x ) for x in self .vertices )
71
73
72
74
@property
@@ -120,25 +122,42 @@ def cycle(length, directed=False):
120
122
return Graph (edges = edges , directed = directed )
121
123
122
124
123
- def complete_graph (size , loops = True ):
124
- """ Produces a complete graph of specificies size.
125
-
126
- See https://en.wikipedia.org/wiki/Complete_graph for details.
125
+ def complete_graph (size , loops = True , directed = False ):
126
+ """
127
+ Produces a complete graph of size `length`.
128
+ https://en.wikipedia.org/wiki/Complete_graph
127
129
128
130
Parameters
129
131
----------
130
132
size: int
131
133
Number of vertices in the cycle
132
134
loops: bool, True
133
- Should the graph contain cycles?
135
+ attach loops at each node?
136
+ directed: bool, False
137
+ Is the graph directed?
134
138
135
139
Returns
136
140
-------
137
141
a Graph object for the complete graph
138
142
"""
139
143
edges = [(i , j ) for i in range (size ) for j in range (i + 1 , size )]
140
- graph = Graph (edges = edges , directed = False )
144
+ graph = Graph (directed = directed , edges = edges )
145
+ if loops :
146
+ graph .add_loops ()
147
+ return graph
148
+
141
149
150
+ def attached_complete_graphs (length , loops = True , directed = False ):
151
+ edges = []
152
+ # Two complete graphs
153
+ for cluster in range (2 ):
154
+ for i in range (length ):
155
+ for j in range (i + 1 , length ):
156
+ edges .append (("{}:{}" .format (cluster , i ),
157
+ "{}:{}" .format (cluster , j )))
158
+ # Attach at one node
159
+ edges .append (("0:0" , "1:0" ))
160
+ graph = Graph (directed = directed , edges = edges )
142
161
if loops :
143
162
graph .add_loops ()
144
163
0 commit comments