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

Support for generating graphs randomly based on a degree sequence. #159

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

weilycoder
Copy link
Contributor

@weilycoder weilycoder commented Dec 15, 2024

支持根据度数序列生成图。

import random
from cyaron.graph import *

random.seed(0, 2)

print(Graph.from_degree_sequence([2, 2, 1, 1, 1, 1]).to_str(output=Edge.unweighted_edge))
print()
print(Graph.from_degree_sequence([(1, 2), (1, 1), (1, 0)]).to_str(output=Edge.unweighted_edge))

根据输入度数序列的不同格式,会返回有向图或无向图。

上述代码输出:

1 2
1 5
2 6
3 4

1 2
1 3
2 1

还没写测试。

@weilycoder
Copy link
Contributor Author

随机的方法是先根据序列贪心地生成一张图,再随机打乱。

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

Successfully merging this pull request may close these issues.

1 participant