1

I have a Matrix let we call it A Matrix, A[10*10] nodes and this matrix Aij=Aji as you see. How can i can create from this matrix a matrix when a node connect another node randomly and it will be done for all nodes but for examle if x node connected y node y node will not connect x again

$$A=\begin{bmatrix}0&1&0&1&1&0&1&1&0&0 \\ 1&0& 0& 1& 1& 0& 1& 1& 0& 0 \\ 0& 0& 0& 1& 1& 1& 0& 1& 1& 1 \\ 1& 1& 1& 0& 1& 1& 1& 1& 1& 1 \\ 1& 1& 1& 1& 0& 1& 1& 1& 1& 1 \\ 0& 0& 1& 1& 1& 0& 0& 1& 1& 1 \\ 1& 1& 0& 1& 1& 0& 0& 1& 0& 0 \\ 1& 1& 1& 1& 1& 1& 1& 0& 1& 1 \\ 0& 0& 1& 1& 1& 1& 0& 1& 0& 1 \\ 0& 0& 1& 1& 1& 1& 0& 1& 1& 0 \end{bmatrix}$$

Bob
  • 869
doci
  • 121
  • Your question is very unclear. Could it be that this is an adjacency matrix of an undirected graph and you want to have a matrix where all edges are given random orientation? Note that in other cases talking about nodes and connecting makes little sense. – Karolis Juodelė Feb 01 '13 at 11:30
  • yes this is an Adj matrix of an undirected grafh and i want convert Adj matrix of directed grafh – doci Feb 01 '13 at 11:32
  • here is my code clear; rand('state', 5); numOfNodes = 10; envSize=1;
    txRange = 0.8;
    global xLocation;
    global yLocation;
    xLocation = rand(numOfNodes,1) * envSize; yLocation = rand(numOfNodes,1) * envSize; distMatrix = zeros(numOfNodes,numOfNodes); for i=1:numOfNodes for j=1:numOfNodes distMatrix(i,j)=sqrt((xLocation(i)-xLocation(j))^2 + (yLocation(i)-yLocation(j))^2); end end global A; A = ( distMatrix < txRange); figure(1); plot(xLocation, yLocation, '.'); return;
    – doci Feb 01 '13 at 11:41

1 Answers1

2

In an adjacency matrix $A_{ij} = 1$ means "there is an edge from node $i$ to node $j$". Adjacency matrix of a directed graph (without cycles of length $2$) will have $A_{ij} = 0$ or $A_{ji} = 0$. A way to enforce it is

for i = 1:numOfNodes
    for j = i+1:numOfNodes
        if(randomBoolean) A[i][j] = 0
        else A[j][i] = 0

Note that iteration goes through all pairs $i, j$ such that $i < j$. This ensures that a pair will only be oriented once.

Karolis Juodelė
  • 9,702
  • 1
  • 25
  • 39
  • If it better fits the problem, you can ignore randomBoolean, and direct each edge $i\to j$ whenever $i<j$.. – Berci Feb 01 '13 at 12:42
  • How do I pick randomly from every column a "1" regularly – doci Feb 02 '13 at 15:02
  • @dogukan, there should be a standard function for generating random numbers in whatever programming language you're using. I'm not sure why you want to pick something from each column. It's pairs of elements at $(i, j)$ and $(j, i)$ you need. – Karolis Juodelė Feb 02 '13 at 15:13