<< find_path Paths - Cycles max_cap_path >>

metanet >> metanet > Paths - Cycles > hamilton

hamilton

hamiltonian circuit of a graph

Calling Sequence

cir = hamilton(g)

Parameters

g

a graph_data_structure.

cir

integer row vector

Description

A Hamiltonian circuit, is a graph circuit through a graph that visits each node exactly once.

hamilton finds an hamiltonian circuit (if it exists) of the directed graph g.

Examples

ta=[2  1 3 2 2 4 4 5 6 7 8 8 9 10 10 10 10 11 12 13 13 14 15 16 16 17 17];
he=[1 10 2 5 7 3 2 4 5 8 6 9 7 7 11 13 15 12 13  9 14 11 16 1 17 14 15];
g=make_graph('foo',1,17,ta,he);
g.nodes.graphics.x=[283 163 63 57 164 164 273 271 339 384 504 513 439 623 631 757 642]/2;
g.nodes.graphics.y=[59 133 223 318 227 319 221 324 432 141 209 319 428 443 187 151 301]/2;
show_graph(g);
cir=hamilton(g)
hilite_edges(cir);

ta=[1,1,2,5,4,3,14,13,12,11,10,9,8,7,6 ,15,17,16,18,20,19,13,6,19];
he=[3,2,5,4,3,14,15,12,11,10,9 ,8,7,6,15,17,16,18,20,19,17,14,1,13];
g=make_graph('foo',1,20,ta,he);
g.nodes.graphics.x=[-30,-182,161,64,-116,-25,-79,-128,-97,-94,-19,47,66,98,24,-61,13,-64,32,-16];
g.nodes.graphics.y=[198,94,90,-107,-96,144,103,78,13,-63,-48,-76,23,77,103,76,78,11,13,-15];
show_graph(g,'new');
cir=hamilton(g)
hilite_edges(cir);

Report an issue
<< find_path Paths - Cycles max_cap_path >>