Skip to content

Commit 1d7dc6b

Browse files
weilycoderMr-Python-in-China
authored andcommitted
Fix forest generation
1 parent 23f6432 commit 1d7dc6b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cyaron/graph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,10 @@ def forest(point_count, tree_count, **kwargs):
545545
"""
546546
if tree_count <= 0 or tree_count > point_count:
547547
raise ValueError("tree_count must be between 1 and point_count")
548-
tree = list(Graph.tree(point_count, **kwargs).iterate_edges())
549-
result = Graph(point_count, 0)
550-
need_add = random.sample(tree, len(tree) - tree_count + 1)
548+
tree = Graph.tree(point_count, **kwargs)
549+
tree_edges = list(tree.iterate_edges())
550+
result = Graph(point_count, tree.directed)
551+
need_add = random.sample(tree_edges, len(tree_edges) - tree_count + 1)
551552
for edge in need_add:
552553
result.add_edge(edge.start, edge.end, weight=edge.weight)
553554
return result

0 commit comments

Comments
 (0)