Created
March 23, 2015 06:41
-
-
Save framp/99bdc800e73166fd751b to your computer and use it in GitHub Desktop.
Generates the adjacency map of an harary graph with n nodes and k-connected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Generates the adjacency map of an harary graph with n nodes and k-connected | |
function hararyGraph(n, k){ | |
var adj = [] | |
if (k>=n) k=n-1 | |
var hn = Math.ceil(n/2) | |
var hk = Math.floor(k/2) | |
var rk = hk*2 | |
for (var i=1; i<=n; i++){ | |
adj[i-1] = [] | |
for (var j=1; j<=hk; j++) | |
adj[i-1].push(i+j-(i+j>n)*n-1, i-j+(i<=j)*n-1) | |
if (k-rk) | |
adj[i-1].push(i+hn-(i+hn>n)*n-1) | |
} | |
return adj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment