Description Usage Arguments Details Value Author(s) References See Also Examples
zigzag
 Constructs hamiltonian paths where each pair (i,j)
appears in at least one of the hamiltonians.
hpaths
 Returns a hamiltonian decomposition on the complete graph with n nodes. See Details.
permute_hpaths
 Returns a modified version of paths
, where vertices
are relabelled so that the first hamiltonian is path1
.
1 2 3 
n 
a positive integer. For 
matrix 
if 
cycle 
If 
path1 
A vector This will be the first hamiltonian of the returned hamiltonian decomposition. 
paths 
A matrix where each row is a hamiltonian. 
... 
Ignored. 
hpaths

From graph theory we know that for odd n, the complete graph decomposes into (n1)/2 edge distinct hamiltonian
cycles, while for even n the graph decomposes into n/2 edge distinct hamiltonian paths.
The default behaviour of the function hpaths
is to produce the cycle decomposition for odd n and the path
decomposition for even n.
However, if a TRUE
value is supplied as argument cycle, the returned paths are cycles, and the result is a true decomposition for odd n, but for even n the last hamiltonian has some duplicate edges.
If a FALSE
value is supplied as argument cycle, the returned paths are open, and the result is a true decomposition
for even n, but for odd n the last hamiltonian has some duplicate edges.
A numeric matrix where each row contains a permutation of 1..n, or these rows concatenated into a vector if matrix=FALSE
.
C.B. Hurley and R.W. Oldford
D.E. Lucas (1892), Recreations Matematiques, Vol II. Gauthier Villars, Paris.
Also see overview
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  require(PairViz)
zigzag(7)
hpaths(7) # the rows form a decomp. into hamiltonian cycles
# Now concatenate the rows and close the path
hpaths(7,matrix=FALSE)
# Form a decomposition into hamiltonian cycles this decomposition is not exact, as the last row duplicates edges
hpaths(7,cycle=FALSE)
# For even n, the default is a decomposition into hamiltonian paths, not cycles.
hpaths(6)
# If cycles are required for even n, the decomposition will not be exact and the last row duplicates edges
hpaths(6,cycle=TRUE)
# If you want to specify the first hamiltonian of the decomposition, use
hpaths(1:7)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.