Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成森林的逻辑问题 #149

Open
weilycoder opened this issue Nov 26, 2024 · 0 comments
Open

生成森林的逻辑问题 #149

weilycoder opened this issue Nov 26, 2024 · 0 comments

Comments

@weilycoder
Copy link
Contributor

cyaron/cyaron/graph.py

Lines 538 to 553 in 23f6432

@staticmethod
def forest(point_count, tree_count, **kwargs):
"""
Return a forest with point_count vertexes and tree_count trees.
Args:
point_count: the count of vertexes
tree_count: the count of trees
"""
if tree_count <= 0 or tree_count > point_count:
raise ValueError("tree_count must be between 1 and point_count")
tree = list(Graph.tree(point_count, **kwargs).iterate_edges())
result = Graph(point_count, 0)
need_add = random.sample(tree, len(tree) - tree_count + 1)
for edge in need_add:
result.add_edge(edge.start, edge.end, weight=edge.weight)
return result

注意一下这一行:

result = Graph(point_count, 0)

作者将 Graph 的第二项参数错误地理解为边数并传入 $0$。实际上,这项参数指定了图是否有向。

同时,我们看到,这个函数并没有解析用户可能传入的 directed 参数并进行处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant