@@ -66,7 +66,9 @@ def _add_edges(self, edges):
6666 self ._add_edge (* edge )
6767
6868 def add_loops (self ):
69- """Add all loops to edges."""
69+ """
70+ Add all loops to edges
71+ """
7072 self ._add_edges ((x , x ) for x in self .vertices )
7173
7274 @property
@@ -120,25 +122,42 @@ def cycle(length, directed=False):
120122 return Graph (edges = edges , directed = directed )
121123
122124
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
127129
128130 Parameters
129131 ----------
130132 size: int
131133 Number of vertices in the cycle
132134 loops: bool, True
133- Should the graph contain cycles?
135+ attach loops at each node?
136+ directed: bool, False
137+ Is the graph directed?
134138
135139 Returns
136140 -------
137141 a Graph object for the complete graph
138142 """
139143 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+
141149
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 )
142161 if loops :
143162 graph .add_loops ()
144163
0 commit comments