void NBS::initialise (const node_t num_nodes) { const Mat2Vec mat2vec (num_nodes); const size_t num_edges = mat2vec.vec_size(); ProgressBar progress ("Pre-computing statistical correlation matrix...", num_edges); adjacency.reset (new vector< vector<size_t> > (num_edges, vector<size_t>())); for (node_t row = 0; row != num_nodes; ++row) { for (node_t column = row; column != num_nodes; ++column) { const size_t index = mat2vec (row, column); vector<size_t>& vector = (*adjacency)[index]; vector.reserve (2 * (num_nodes-1)); // Should be able to expand from this edge to any other edge connected to either row or column for (node_t r = 0; r != num_nodes; ++r) { if (r != row) vector.push_back (mat2vec (r, column)); } for (node_t c = 0; c != num_nodes; ++c) { if (c != column) vector.push_back (mat2vec (row, c)); } ++progress; } } }
void remove_random_edge(uchar *adj) { uchar j; uchar r = (uchar) (random_rand() % TOT_NUM_NODES); uchar found = 0; for (j = 0; j < TOT_NUM_NODES && !found; j++) { if (adj[mat2vec(r, j)]) { found = 1; adj[mat2vec(r, j)] = 1; adj[mat2vec(j, r)] = 1; } } }
static void set_adj_matrix(uchar *adj) { uchar i, j; for (i = 0; i < TOT_NUM_NODES - 1; i++) { for (j = 0; j < TOT_NUM_NODES - 1; j++) { if (temp_adj_matrix[i][j]) { adj[mat2vec(i, j)] = 1; } } } }
int independent(int n,int mat[MAXN][MAXN]){ i64 vec[MAXN]; int i; max=1; sort(n,mat); for (i=0;i<n;i++) mat[i][i]=1; mat2vec(n,mat,vec); search(n,vec,n-1,0,(((i64)1)<<n)-1); return max; }
uchar choose_random_edge(uchar v1, uchar *adj) { uchar i, random_value, diff_zero = 0; uchar aux[TOT_NUM_NODES]; for (i = 0; i < TOT_NUM_NODES; i++) { if (adj[mat2vec(v1, i)]) { aux[diff_zero] = i; diff_zero++; } } if (!diff_zero) return 0; else { random_value = (uchar) (random_rand() % diff_zero); } return aux[random_value]; }
int clique(int n,int mat[MAXN][MAXN]){ i64 vec[MAXN]; int tmp[MAXN][MAXN],v[MAXN]={0},node[MAXN],m,i,j,k; for (max=1,i=0;i<n;i++) if (!v[i]){ m=0; flood(i,n,mat,v,m,node); if (m>max){ for (j=0;j<m;tmp[j][j]=0,j++) for (k=0;k<m;k++) tmp[j][k]=mat[node[j]][node[k]]; sort(m,tmp); mat2vec(m,tmp,vec); search(m,vec,m-1,0,(((i64)1)<<m)-1); } } return max; }
/** * %HENNEBURGGRAPH Randomly generates a rigid graph with Henneburg operations * @param adj Adjacency matrix */ void henneburgGraph(uchar *adj) { uchar i, op, v1, v2, v3; //Add first bar between first 2 nodes adj[mat2vec(0, 1)] = 1; adj[mat2vec(1, 0)] = 1; //Perform N-2 random Henneburg operations to generate graph for (i = 2; i < TOT_NUM_NODES; i++) { if (i > 2) op = (uchar) (random_rand() % 2) + 1; else op = 1; // Perform the 2-valent operation if (op == 1) { //Choose vertices v1 = (uchar) (random_rand() % i); v2 = (uchar) (random_rand() % i); while (v2 == v1) { v2 = (uchar) (random_rand() % i); } //% Add new edges adj[mat2vec(i, v1)] = 1; adj[mat2vec(v1, i)] = 1; adj[mat2vec(i, v2)] = 1; adj[mat2vec(v2, i)] = 1; } // Perform the 3-valent operation if (op == 2) { // Choose an edge v1 = (uchar) (random_rand() % i); v2 = choose_random_edge(v1, adj); // Choose a third vertex v3 = (uchar) (random_rand() % i); while (v3 == v1 || v3 == v2) { v3 = (uchar) (random_rand() % i); } //Remove edge (v1,v2) and add edges (v1,i), (v2,i), (v3,i) adj[mat2vec(v1, v2)] = 0; adj[mat2vec(v2, v1)] = 0; adj[mat2vec(v1, i)] = 1; adj[mat2vec(i, v1)] = 1; adj[mat2vec(v2, i)] = 1; adj[mat2vec(i, v2)] = 1; adj[mat2vec(v3, i)] = 1; adj[mat2vec(i, v3)] = 1; } } }