int Graph::_GetComponent(int i,int * row) { MyStack * stack; int n=0,j,tmp,result[1000],result_e[1000],neib_no=0,k; stack = new MyStack; row[n++] = i; stack->stack_push(i,0); while(stack->stack_pop(&j,&tmp)!=-1) { neib_no = GetNeighborNodeAndEdge(j, result,result_e); for(k=0;k<neib_no;k++) { if(node_list[result[k]].color==0 && edge_list[result_e[k]].weight > 0.5) // hasn't been dried { row[n++] = result[k]; stack->stack_push(result[k],0); node_list[result[k]].color=1; } } }; row[n] = -1; delete stack; return n; }
int Graph::_GetComponentAff(double *A,int size,bool * node_list,int i,int * row) { MyStack * stack; int n=0,j,tmp,k; stack = new MyStack(size); row[n++] = i; stack->stack_push(i,0); while(stack->stack_pop(&j,&tmp)!=-1) { for(k=0;k<size;k++) { if(A[j*size+k]>0.0000001 && node_list[k]==false) { row[n++] = k; stack->stack_push(k,0); node_list[k] = true; } } }; row[n] = -1; delete stack; return n+1; }
// reachability test, from ni -> nj, according to weight bool Graph::Reachable(int ni, int nj) { MyStack * stack; int tmp,result[1000],result_e[1000],neib_no=0,k; int nt,i; for(i=0;i<node_num;i++) NODE_PTR(i)->color = 0; stack = new MyStack; stack->stack_push(ni,0); NODE_PTR(i)->color = 1; while(stack->stack_pop(&nt,&tmp)!=-1) { neib_no = GetNeighborNodeAndEdge(nt, result,result_e); for(k=0;k<neib_no;k++) { if(result[k]==nj && EDGE_PTR(result_e[k])->weight > 0.5) { delete stack; return true; } if(NODE_PTR(result[k])->color==0 && EDGE_PTR(result_e[k])->weight > 0.5) // hasn't been dried { stack->stack_push(result[k],0); NODE_PTR(result[k])->color=1; } } }; delete stack; return false; }