Skip to content

Commit 0ae2aec

Browse files
committed
add Graph.connected
1 parent fc4aec8 commit 0ae2aec

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cyaron/graph.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def graph(point_count, edge_count, **kwargs):
290290
@staticmethod
291291
def DAG(point_count, edge_count, **kwargs):
292292
"""DAG(point_count, edge_count, **kwargs) -> Graph
293-
Factory method. Return a graph with point_count vertexes and edge_count edges.
293+
Factory method. Return a directed connected graph with point_count vertexes and edge_count edges.
294294
int point_count -> the count of vertexes
295295
int edge_count -> the count of edges
296296
**kwargs(Keyword args):
@@ -352,7 +352,7 @@ def DAG(point_count, edge_count, **kwargs):
352352
@staticmethod
353353
def UDAG(point_count, edge_count, **kwargs):
354354
"""UDAG(point_count, edge_count, **kwargs) -> Graph
355-
Factory method. Return a graph with point_count vertexes and edge_count edges.
355+
Factory method. Return a undirected connected graph with point_count vertexes and edge_count edges.
356356
int point_count -> the count of vertexes
357357
int edge_count -> the count of edges
358358
**kwargs(Keyword args):
@@ -402,6 +402,18 @@ def UDAG(point_count, edge_count, **kwargs):
402402
i += 1
403403

404404
return graph
405+
406+
@staticmethod
407+
def connected(point_count, edge_count, directed=False, **kwargs):
408+
"""connected(point_count, edge_count, **kwargs) -> Graph
409+
Factory method. Return a connected graph with point_count vertexes
410+
int point_count -> the count of vertexes
411+
bool directed -> whether the graph is directed
412+
"""
413+
if directed:
414+
return Graph.DAG(point_count, edge_count, **kwargs)
415+
else:
416+
return Graph.UDAG(point_count, edge_count, **kwargs)
405417

406418
@staticmethod
407419
def hack_spfa(point_count, **kwargs):

0 commit comments

Comments
 (0)