hamiltonian(Graph, Source, Destination)

版本 1.0.0.0 (3.1 KB) 作者: Pramit Biswas
This MATLAB function can be used to find Hamiltonian Path or Cycle
970.0 次下载
更新时间 2015/6/28

查看许可证

This MATLAB function c% Let us create the following graph
(1)--(2)--(3)-------(4)
| / \ | |
| / \ | |
| / \ | |
(5)-------(6) |
| |
| |
| |
(7)-------------------(8)

g=[0 1 0 0 1 0 0 0;
1 0 1 0 1 1 0 0;
0 1 0 1 0 1 0 0;
0 0 1 0 0 0 0 1;
1 1 0 0 0 1 1 0;
0 1 1 0 1 0 0 0;
0 0 0 0 1 0 0 1;
0 0 0 1 0 0 1 0]
s=5; % Source
d=1; % Destination
P = hamiltonianPath(g,s,d);

P will be an array mentioning the path/cycle, if path/cycle found; or a
string: 'No Path/Cycle Found', if path/cycle not found

#Note: This code can be used for finding Hamiltonian cycle also. For
that, make sure Source and Destination are same.

引用格式

Pramit Biswas (2024). hamiltonian(Graph, Source, Destination) (https://www.mathworks.com/matlabcentral/fileexchange/51610-hamiltonian-graph-source-destination), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R10
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Construction 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0