Generating the adjacency matrix for a network