1234567891011121314151617181920212223242526272829303132 |
- #!/usr/bin/env python3
- # pip3 install graph-tools
- import random
- import graph_tools
- MAX_TIME = 100
- def main():
- g = graph_tools.Graph(directed=False)
- g.add_edge(1, 2)
- g.add_edge(1, 3)
- g.add_edge(2, 3)
- g.add_edge(3, 4)
- g.add_edge(4, 5)
- # 2
- # / \
- # 1 ----- 3 ----- 4 ----- 5
- t = 0
- v = g.random_vertex()
- while t <= MAX_TIME:
- print(t, v)
- neighbors = g.neighbors(v)
- v = random.choice(list(neighbors))
- t += 1
- if __name__ == "__main__":
- main()
|