给定访问序列为’x0’,’x1’,’x2’,’x3’,’x4’,’x5’,’y5’,’y4’,’y3’,’y2’,’y1’,’y0’存在一条哈密顿回路,用python代码画用哈密顿图
时间: 2023-12-02 08:04:38 浏览: 152
```python
import networkx as nx
import matplotlib.pyplot as plt
# 创建一个无向图
G = nx.Graph()
# 添加节点
nodes = ['x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'y5', 'y4', 'y3', 'y2', 'y1', 'y0']
G.add_nodes_from(nodes)
# 添加边
edges = [('x0', 'x1'), ('x1', 'x2'), ('x2', 'x3'), ('x3', 'x4'), ('x4', 'x5'), ('x5', 'y5'), ('y5', 'y4'), ('y4', 'y3'), ('y3', 'y2'), ('y2', 'y1'), ('y1', 'y0'), ('y0', 'x0')]
G.add_edges_from(edges)
# 绘制哈密顿图
nx.draw(G, with_labels=True)
plt.show()
```
--相关问题--:
1. 什么是哈密顿回路?
2. 如何使用Python绘制
阅读全文