The following is a MATLAB script to create a ** k**-connected Harary Graph of

**-nodes. Clearly the inputs required are**

*n**(no of nodes) and*

**n***(degree of each node).*

**k**Also, while the code is a MATLAB script the basic technique to generate the adjacency matrix of the graph can be easily adopted to other languages like C, C++ or Java etc. (The code used the Bioinformatics toolbox of Matlab to display the graph. Check that you have it in your Matlab installation via ‘*ver*‘ command which would list the installed packages.)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
% Create a k-regular Harary graph % INPUTs: n - # nodes, k - degree of each vertex % OUTPUTs: adj - the adjacency matrix of k-regular directed Harary graph % AJ, Last updated: October 6, 2013 % Sample run: adj = kregularHarary(8,4) %% function kregularHarary - main function in this file. function adj = kregularHarary(n,k) adj=[]; %preliminary check if k>n-1; fprintf('a simple graph with n nodes and k>n-1 does not exist\n'); return; end if mod(k,2)==0 adj = hararyEven(n,k); else adj = hararyEven(n,k-1); adj = hararyOdd(n,adj); end % Get only the lower triangular matrix out of adj % this is required to prevent Matlab from creating double edges. adj_tri = tril(adj); bg2=biograph(adj_tri); bg2.layoutType = 'equilibrium'; bg2.showarrows = 'off'; view(bg2); end %% function hararyOdd (local function) % updates the adjacency matrix for a Harary graph for which k is odd % returns adj - the updated adjacency matrix function adj = hararyOdd(n,adj) if mod(n,2) == 0 halfDist = n/2; else halfDist = (n+1)/2; end for i=1:n nextNode = i+halfDist; if nextNode > n nextNode = nextNode - n; end adj(i,nextNode)=1; end end %% function harayEvn (local function) % creates a harary graph for even degree regularity % reutrns the adjacency matrix for the Haray Graph (n,k) where k is even function adj = hararyEven(n,k) adj=zeros(n,n); halfK = k/2; fprintf('halfK value : %d',halfK); for i=1:n for j=1:halfK nextNode = i+j; if (nextNode > n) nextNode = nextNode - n; end prevNode = i-j; if (prevNode <= 0) prevNode = prevNode + n; end adj(i, nextNode) = 1; adj(i, prevNode) = 1; end end end |

A sample run of the above code is shown below:

The generated graph output for the above code would be like this:

Wonderful work! This is the type of info that should be shared

across the internet. Shame on the seek engines for now not positioning this publish upper!

Come on over and consult with my website .

Thank you =)

Everything is very open with a precise description of the issues.

It was truly informative. Your site is useful. Thanks for sharing!

Hi, There’s no doubt that your web site might be having internet browser compatibility problems.

Whenever I take a look at your website in Safari, it looks fine however when opening in I.E., it’s got some overlapping

issues. I simply wanted to provide you with a quick heads up!

Besides that, wonderful blog!

Thanks for pointing that out. We’ll have a look at that.