Skip to content

Instantly share code, notes, and snippets.

@framp
Created March 23, 2015 06:41
Show Gist options
  • Save framp/99bdc800e73166fd751b to your computer and use it in GitHub Desktop.
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
//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