igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Cayley Tree


From: Tamas Nepusz
Subject: Re: [igraph] Cayley Tree
Date: Wed, 18 Nov 2009 22:33:45 +0000

> cayley.tree <- function(coord, depth) {
>  if (depth==0) return(graph.empty(1))
>  if (depth==1) return(graph.tree(4, 3, mode="undir"))
>  d <- coord-1
>  n1 <- (d^(depth+1)-1) / (d-1)
>  n2 <- (d^depth -1)/ (d-1)
>  g <- graph.tree(n1, d, mode="undir") %du% graph.tree(n2, d, mode="undir")
>  add.edges(g, c(0, n1))
> }
A similar function in Python (untested):

def cayley_tree(coord, depth):
    if depth == 0:
        return Graph(1)
    if depth == 1:
        return Graph.Tree(4, 3)
    d = coord - 1
    n1, n2 = d ** (depth+1) - 1, d ** depth - 1
    n1 /= d-1
    n2 /= d-1
    return Graph.Tree(n1, d) + Graph.Tree(n2, d) + (0, n1)
    
-- 
Tamas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]