about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/graph/assignEdgeNums.m
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/graph/assignEdgeNums.m')
-rw-r--r--sourcecodes/bnt-master/graph/assignEdgeNums.m32
1 files changed, 32 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/graph/assignEdgeNums.m b/sourcecodes/bnt-master/graph/assignEdgeNums.m
new file mode 100644
index 00000000..5d9a2a0d
--- /dev/null
+++ b/sourcecodes/bnt-master/graph/assignEdgeNums.m
@@ -0,0 +1,32 @@
+function [edge_id, nedges] = assignEdgeNums(adj_mat)
+% give each edge a unique number
+% we number (i,j) for j>i first, in row, column order.
+% Then we number the reverse links
+
+nnodes = length(adj_mat);
+edge_id = zeros(nnodes);
+e = 1;
+for i=1:nnodes
+  for j=i+1:nnodes
+    if adj_mat(i,j)
+      edge_id(i,j) = e;
+      e = e+1;
+    end
+  end
+end
+
+nedges = e-1;
+tmp = edge_id;
+ndx = find(tmp);
+tmp(ndx) = tmp(ndx)+nedges;
+edge_id = edge_id + triu(tmp)';
+
+
+if 0
+ndx = find(adj_mat);
+nedges = length(ndx);
+nnodes = length(adj_mat);
+edge_id = zeros(1, nnodes*nnodes);
+edge_id(ndx) = 1:nedges; 
+edge_id = reshape(edge_id, nnodes, nnodes);
+end