//================================================================================ void ATHRenderPass::PreExecute() { if( m_bDepthDirty ) { SortNodes(); } }
struct node* InsertNodeWithId(struct node **anchor_ptr, int id){ if(nodedebugsw == 1) printf("Checking if node with id: %d is already in the list. ", id); if((*anchor_ptr) == 0){ struct node *newnode_ptr; newnode_ptr = malloc(sizeof(struct node)); if(newnode_ptr == 0){ if(nodedebugsw == 1) printf("Cannot allocate memory for newnode_ptr\n"); return 0; } newnode_ptr->nextobject_ptr = 0; newnode_ptr->pos = 0; newnode_ptr->id = id; (*anchor_ptr) = newnode_ptr; if(nodedebugsw == 1) printf("Not in list\n. Adding node to the beginning of the list with attributes: id:%d, pos:%d\n", (*anchor_ptr)->id, (*anchor_ptr)->pos); return newnode_ptr; } else{ struct node *cnt_ptr = (*anchor_ptr); while(cnt_ptr->id != id && cnt_ptr->nextobject_ptr != 0){ cnt_ptr = cnt_ptr->nextobject_ptr; if(nodedebugsw == 1) printf(". "); } if(cnt_ptr->id != id && cnt_ptr->nextobject_ptr == 0){ struct node *newnode_ptr; newnode_ptr = malloc(sizeof(struct node)); if(newnode_ptr == 0){ if(nodedebugsw == 1) printf("Cannot allocate memory for newnode_ptr\n"); return 0; } else{ newnode_ptr->nextobject_ptr = 0; newnode_ptr->id = id; cnt_ptr->nextobject_ptr=newnode_ptr; SortNodes((*anchor_ptr)); if(nodedebugsw == 1) printf("Adding node with id:%d to the end of the list with attributes: id:%d, pos:%d\n", cnt_ptr->nextobject_ptr->id, \ cnt_ptr->nextobject_ptr->id, cnt_ptr->nextobject_ptr->pos); return newnode_ptr; } } if(cnt_ptr->id == id){ if(nodedebugsw == 1) printf("Found node with id:%d. No need to add new node\n",id); return cnt_ptr; } return 0; } }
int DeleteNodeById(struct node **anchor_ptr, int id){ if((*anchor_ptr) == 0){ if(nodedebugsw == 1) printf("Couldn't delete node with id:%d. list is empty\n", id); return 0; } if((*anchor_ptr)->id == id){ struct node *del_ptr; del_ptr = (*anchor_ptr); (*anchor_ptr) = (*anchor_ptr)->nextobject_ptr; free(del_ptr); SortNodes((*anchor_ptr)); if(nodedebugsw == 1) printf("Deleted node with id:%d on pos 0\n", id); return 1; } else{ struct node *cnt_ptr; cnt_ptr = (*anchor_ptr); while(cnt_ptr->nextobject_ptr != 0 && cnt_ptr->nextobject_ptr->id != id) cnt_ptr = cnt_ptr->nextobject_ptr; if(cnt_ptr->nextobject_ptr == 0){ if(nodedebugsw == 1) printf("Couldn't delete node with id:%d. Wanted node is not in list\n", id); return 0; } else{ struct node *del_ptr; del_ptr = cnt_ptr->nextobject_ptr; cnt_ptr->nextobject_ptr = cnt_ptr->nextobject_ptr->nextobject_ptr; free(del_ptr); SortNodes((*anchor_ptr)); if(nodedebugsw == 1) printf("Deleted node with id:%d\n", id); return 1; } } }
int DeleteNodeByPos(struct node **anchor_ptr, int nmbr){ if((*anchor_ptr) == 0){ if(nodedebugsw == 1) printf("Couldn't delete node at pos:%d. list is empty\n", nmbr); return 0; } if((*anchor_ptr)->pos == 0){ struct node *del_ptr; del_ptr = (*anchor_ptr); (*anchor_ptr) = (*anchor_ptr)->nextobject_ptr; free(del_ptr); SortNodes((*anchor_ptr)); if(nodedebugsw == 1) printf("Deleted node at pos:%d\n", nmbr); return 1; } else{ struct node *cnt_ptr = (*anchor_ptr); while(cnt_ptr->nextobject_ptr != 0 && cnt_ptr->nextobject_ptr->pos != nmbr) cnt_ptr = cnt_ptr->nextobject_ptr; if(cnt_ptr->nextobject_ptr == 0){ if(nodedebugsw == 1) printf("Couldn't delete node at pos:%d. Wanted node is not in list\n", nmbr); return 0; } else{ struct node *del_ptr; del_ptr = cnt_ptr->nextobject_ptr; cnt_ptr->nextobject_ptr = cnt_ptr->nextobject_ptr->nextobject_ptr; free(del_ptr); SortNodes((*anchor_ptr)); if(nodedebugsw == 1) printf("Deleted node at pos:%d\n", nmbr); return 1; } } }
bool TContainerHolder::RestoreFromStorage() { std::vector<std::shared_ptr<TKeyValueNode>> nodes; auto holder_lock = ScopedLock(); TError error = Storage->ListNodes(nodes); if (error) { L_ERR() << "Can't list key-value nodes: " << error << std::endl; return false; } auto name2node = SortNodes(nodes); bool restored = false; for (auto &pair : name2node) { auto node = pair.second; auto name = pair.first; L_ACT() << "Found " << name << " container in kvs" << std::endl; kv::TNode n; error = node->Load(n); if (error) continue; restored = true; error = Restore(holder_lock, name, n); if (error) { L_ERR() << "Can't restore " << name << ": " << error << std::endl; Statistics->RestoreFailed++; node->Remove(); continue; } // FIXME since v1.0 we need to cleanup kvalue nodes with old naming if (TKeyValueStorage::Get(n, P_RAW_NAME, name)) node->Remove(); } if (restored) { for (auto &c: Containers) { if (c.second->IsLostAndRestored()) { ScheduleCgroupSync(); break; } } } return restored; }
int FEASolver::Cuthill() { FILE *fp; int i,n0,n1,n; long int j,k; int newwide,*newnum,**ocon; int *numcon,*nxtnum; char infile[256]; // read in connectivity from nodefile sprintf(infile,"%s.edge",PathName.c_str()); if((fp=fopen(infile,"rt"))==NULL) { //MsgBox("Couldn't open %s",infile); printf("Couldn't open %s",infile); return FALSE; } fscanf(fp,"%li",&k); // read in number of lines fscanf(fp,"%li",&j); // read in boundarymarker flag; // allocate storage for numbering nxtnum=(int *)calloc(NumNodes,sizeof(int)); newnum=(int *)calloc(NumNodes,sizeof(int)); numcon=(int *)calloc(NumNodes,sizeof(int)); ocon=(int **)calloc(NumNodes,sizeof(int *)); // initialize node array; for(i=0; i<NumNodes; i++) { newnum[i] = -1; } // allocate space for connections; ocon[0]=(int *)calloc(2*k,sizeof(int)); // with first pass, figure out how many connections // there are for each node; for(i=0; i<k; i++) { fscanf(fp,"%li",&j); fscanf(fp,"%i",&n0); fscanf(fp,"%i",&n1); fscanf(fp,"%li",&j); numcon[n0]++; numcon[n1]++; } // mete out connection storage space; for(i=1,n=0; i<NumNodes; i++) { n+=numcon[i-1]; ocon[i]=ocon[0]+n; } // on second pass through file, store connections; rewind(fp); fscanf(fp,"%li",&k); // read in number of lines fscanf(fp,"%li",&j); // read in boundarymarker flag; for(i=0; i<k; i++) { fscanf(fp,"%li",&j); fscanf(fp,"%i",&n0); fscanf(fp,"%i",&n1); fscanf(fp,"%li",&j); ocon[n0][nxtnum[n0]]=n1; nxtnum[n0]++; ocon[n1][nxtnum[n1]]=n0; nxtnum[n1]++; } fclose(fp); remove(infile); // sort connections in order of increasing connectivity; // I'm lazy, so I'm doing a bubble sort; for(n0=0; n0<NumNodes; n0++) { for(i=1; i<numcon[n0]; i++) for(j=1; j<numcon[n0]; j++) if(numcon[ocon[n0][j]]<numcon[ocon[n0][j-1]]) { n1=ocon[n0][j]; ocon[n0][j]=ocon[n0][j-1]; ocon[n0][j-1]=n1; } } // search for a node to start with; j=numcon[0]; n0=0; for(i=1; i<NumNodes; i++) { if(numcon[i]<j) { j=numcon[i]; n0=i; } if(j==2) i=k; // break out if j==2, // because this is the best we can do } // do renumbering algorithm; for(i=0; i<NumNodes; i++) nxtnum[i]=-1; newnum[n0]=0; n=1; nxtnum[0]=n0; do { // renumber in order of increasing number of connections; for(i=0; i<numcon[n0]; i++) { if (newnum[ocon[n0][i]]<0) { newnum[ocon[n0][i]]=n; nxtnum[n]=ocon[n0][i]; n++; } } // need to catch case in which problem is multiply // connected and still renumber right. if(nxtnum[newnum[n0]+1]<0) { // WarnMessage("Multiply Connected!"); // exit(0); // first, get a node that hasn't been visited yet; for(i=0; i<NumNodes; i++) if(newnum[i]<0) { j=numcon[i]; n0=i; i=NumNodes; } // now, get a new starting node; for(i=0; i<NumNodes; i++) { if((newnum[i]<0) && (numcon[i]<j)) { j=numcon[i]; n0=i; } if(j==2) i=NumNodes; // break out if j==2, // because this is the // best we can do } // now, set things to restart; newnum[n0]=n; nxtnum[n]=n0; n++; } else n0=nxtnum[newnum[n0]+1]; } while(n<NumNodes); // remap connectivities; for(i=0; i<NumNodes; i++) for(j=0; j<numcon[i]; j++) ocon[i][j]=newnum[ocon[i][j]]; // remap (anti)periodic boundary points for(i=0; i<NumPBCs; i++) { pbclist[i].x=newnum[pbclist[i].x]; pbclist[i].y=newnum[pbclist[i].y]; } // find new bandwidth; // PBCs f**k up the banding, som could have to do // something like: // if(NumPBCs!=0) BandWidth=0; // else{ // but if we apply the PCBs the last thing before the // solver is called, we can take advantage of banding // speed optimizations without messing things up. for(n0=0,newwide=0; n0<NumNodes; n0++) { for(i=0; i<numcon[n0]; i++) if(abs(newnum[n0]-ocon[n0][i])>newwide) { newwide=abs(newnum[n0]-ocon[n0][i]); } } BandWidth=newwide+1; // } // free up the variables that we needed during the routine.... free(numcon); free(nxtnum); free(ocon[0]); free(ocon); // new mapping remains in newnum; // apply this mapping to elements first. for(i=0; i<NumEls; i++) for(j=0; j<3; j++) meshele[i].p[j]=newnum[meshele[i].p[j]]; // // now, sort nodes based on newnum; // for(i=0; i<NumNodes; i++) // { // while(newnum[i]!=i) // { // CNode swap; // // j=newnum[i]; // n=newnum[j]; // newnum[j]=newnum[i]; // newnum[i]=n; // swap=meshnode[j]; // meshnode[j]=meshnode[i]; // meshnode[i]=swap; // } // } // virtual method that must be overridden by child classes // as the mesh nodes class type varies SortNodes (newnum); free(newnum); SortElements(); return TRUE; }
///' Calculate the network properties ///' ///' @details ///' \subsection{Input expectations:}{ ///' Note that this function expects all inputs to be sensible, as checked by ///' the R function 'checkUserInput' and processed by 'networkProperties'. ///' ///' These requirements are: ///' \itemize{ ///' \item{The ordering of node names across 'data' and 'net' is consistent.} ///' \item{The columns of 'data' are the nodes.} ///' \item{'net' is a square matrix, and its rownames are identical to its ///' column names.} ///' \item{'moduleAssigments' is a named character vector, where the names ///' represent node labels found in the discovery dataset. Unlike ///' 'PermutationProcedure', these may include nodes that are not ///' present in 'data' and 'net'.} ///' \item{The module labels specified in 'modules' must occur in ///' 'moduleAssignments'.} ///' } ///' } ///' ///' @param data data matrix from the dataset in which to calculate the network ///' properties. ///' @param net adjacency matrix of network edge weights between all pairs of ///' nodes in the dataset in which to calculate the network properties. ///' @param moduleAssignments a named character vector containing the module ///' each node belongs to in the discovery dataset. ///' @param modules a character vector of modules for which to calculate the ///' network properties for. ///' ///' @return a list containing the summary profile, node contribution, module ///' coherence, weighted degree, and average edge weight for each 'module'. ///' ///' @keywords internal // [[Rcpp::export]] Rcpp::List NetProps ( Rcpp::NumericMatrix data, Rcpp::NumericMatrix net, Rcpp::CharacterVector moduleAssignments, Rcpp::CharacterVector modules ) { // First, scale the matrix data unsigned int nSamples = data.nrow(); unsigned int nNodes = data.ncol(); arma::mat scaledData = Scale(data.begin(), nSamples, nNodes); R_CheckUserInterrupt(); // convert the colnames / rownames to C++ equivalents const std::vector<std::string> nodeNames (Rcpp::as<std::vector<std::string>>(colnames(net))); const std::vector<std::string> sampleNames (Rcpp::as<std::vector<std::string>>(rownames(data))); /* Next, we need to create two mappings: * - From node IDs to indices in the dataset of interest * - From modules to node IDs * - From modules to only node IDs present in the dataset of interest */ const namemap nodeIdxMap = MakeIdxMap(nodeNames); const stringmap modNodeMap = MakeModMap(moduleAssignments); const stringmap modNodePresentMap = MakeModMap(moduleAssignments, nodeIdxMap); // What modules do we actually want to analyse? const std::vector<std::string> mods (Rcpp::as<std::vector<std::string>>(modules)); R_CheckUserInterrupt(); // Calculate the network properties for each module std::string mod; // iterators unsigned int mNodesPresent, mNodes; arma::uvec nodeIdx, propIdx, nodeRank; namemap propIdxMap; std::vector<std::string> modNodeNames; arma::vec WD, SP, NC; // results containers double avgWeight, coherence; Rcpp::NumericVector degree, summary, contribution; // for casting to R equivalents Rcpp::List results; // final storage container for (auto mi = mods.begin(); mi != mods.end(); ++mi) { // What nodes are in this module? mod = *mi; modNodeNames = GetModNodeNames(mod, modNodeMap); // initialise results containers with NA values for nodes not present in // the dataset we're calculating the network properties in. degree = Rcpp::NumericVector(modNodeNames.size(), NA_REAL); contribution = Rcpp::NumericVector(modNodeNames.size(), NA_REAL); summary = Rcpp::NumericVector(nSamples, NA_REAL); avgWeight = NA_REAL; coherence = NA_REAL; degree.names() = modNodeNames; contribution.names() = modNodeNames; // Create a mapping between node names and the result vectors propIdxMap = MakeIdxMap(modNodeNames); // Get just the indices of nodes that are present in the requested dataset nodeIdx = GetNodeIdx(mod, modNodePresentMap, nodeIdxMap); mNodesPresent = nodeIdx.n_elem; // And a mapping of those nodes to the initialised vectors propIdx = GetNodeIdx(mod, modNodePresentMap, propIdxMap); mNodes = propIdx.n_elem; // Calculate the properties if the module has nodes in the test dataset if (nodeIdx.n_elem > 0) { // sort the node indices for sequential memory access nodeRank = SortNodes(nodeIdx.memptr(), mNodesPresent); WD = WeightedDegree(net.begin(), nNodes, nodeIdx.memptr(), mNodesPresent); WD = WD(nodeRank); // reorder results avgWeight = AverageEdgeWeight(WD.memptr(), WD.n_elem); R_CheckUserInterrupt(); SP = SummaryProfile(scaledData.memptr(), nSamples, nNodes, nodeIdx.memptr(), mNodesPresent); R_CheckUserInterrupt(); NC = NodeContribution(scaledData.memptr(), nSamples, nNodes, nodeIdx.memptr(), mNodesPresent, SP.memptr()); NC = NC(nodeRank); // reorder results coherence = ModuleCoherence(NC.memptr(), mNodesPresent); R_CheckUserInterrupt(); // Convert NaNs to NAs SP.elem(arma::find_nonfinite(SP)).fill(NA_REAL); NC.elem(arma::find_nonfinite(NC)).fill(NA_REAL); if (!arma::is_finite(coherence)) { coherence = NA_REAL; } // Fill results vectors Fill(degree, WD.memptr(), mNodesPresent, propIdx.memptr(), mNodes); Fill(contribution, NC.memptr(), mNodesPresent, propIdx.memptr(), mNodes); summary = Rcpp::NumericVector(SP.begin(), SP.end()); } summary.names() = sampleNames; results.push_back( Rcpp::List::create( Rcpp::Named("summary") = summary, Rcpp::Named("contribution") = contribution, Rcpp::Named("coherence") = coherence, Rcpp::Named("degree") = degree, Rcpp::Named("avgWeight") = avgWeight ) ); } results.names() = mods; return(results); }
///' Calculate the network properties, data matrix not provided ///' ///' @details ///' \subsection{Input expectations:}{ ///' Note that this function expects all inputs to be sensible, as checked by ///' the R function 'checkUserInput' and processed by 'networkProperties'. ///' ///' These requirements are: ///' \itemize{ ///' \item{'net' is a square matrix, and its rownames are identical to its ///' column names.} ///' \item{'moduleAssigments' is a named character vector, where the names ///' represent node labels found in the discovery dataset. Unlike ///' 'PermutationProcedure', these may include nodes that are not ///' present in 'data' and 'net'.} ///' \item{The module labels specified in 'modules' must occur in ///' 'moduleAssignments'.} ///' } ///' } ///' ///' @param net adjacency matrix of network edge weights between all pairs of ///' nodes in the dataset in which to calculate the network properties. ///' @param moduleAssignments a named character vector containing the module ///' each node belongs to in the discovery dataset. ///' @param modules a character vector of modules for which to calculate the ///' network properties for. ///' ///' @return a list containing the summary profile, node contribution, module ///' coherence, weighted degree, and average edge weight for each 'module'. ///' ///' @keywords internal // [[Rcpp::export]] Rcpp::List NetPropsNoData ( Rcpp::NumericMatrix net, Rcpp::CharacterVector moduleAssignments, Rcpp::CharacterVector modules ) { // convert the colnames / rownames to C++ equivalents const std::vector<std::string> nodeNames (Rcpp::as<std::vector<std::string>>(colnames(net))); unsigned int nNodes = net.ncol(); R_CheckUserInterrupt(); /* Next, we need to create two mappings: * - From node IDs to indices in the dataset of interest * - From modules to node IDs * - From modules to only node IDs present in the dataset of interest */ const namemap nodeIdxMap = MakeIdxMap(nodeNames); const stringmap modNodeMap = MakeModMap(moduleAssignments); const stringmap modNodePresentMap = MakeModMap(moduleAssignments, nodeIdxMap); // What modules do we actually want to analyse? const std::vector<std::string> mods (Rcpp::as<std::vector<std::string>>(modules)); R_CheckUserInterrupt(); // Calculate the network properties for each module std::string mod; // iterators unsigned int mNodesPresent, mNodes; arma::uvec nodeIdx, propIdx, nodeRank; namemap propIdxMap; std::vector<std::string> modNodeNames; arma::vec WD; // results containers double avgWeight; Rcpp::NumericVector degree; // for casting to R equivalents Rcpp::List results; // final storage container for (auto mi = mods.begin(); mi != mods.end(); ++mi) { // What nodes are in this module? // modNodeNames = names(moduleAssignments[moduleAssignments == mod]) mod = *mi; modNodeNames = GetModNodeNames(mod, modNodeMap); // initialise results containers with NA values for nodes not present in // the dataset we're calculating the network properties in. degree = Rcpp::NumericVector(modNodeNames.size(), NA_REAL); avgWeight = NA_REAL; degree.names() = modNodeNames; // Create a mapping between node names and the result vectors propIdxMap = MakeIdxMap(modNodeNames); // Get just the indices of nodes that are present in the requested dataset nodeIdx = GetNodeIdx(mod, modNodePresentMap, nodeIdxMap); mNodesPresent = nodeIdx.n_elem; // And a mapping of those nodes to the initialised vectors propIdx = GetNodeIdx(mod, modNodePresentMap, propIdxMap); mNodes = propIdx.n_elem; // Calculate the properties if the module has nodes in the test dataset if (nodeIdx.n_elem > 0) { // sort the node indices for sequential memory access nodeRank = SortNodes(nodeIdx.memptr(), mNodesPresent); WD = WeightedDegree(net.begin(), nNodes, nodeIdx.memptr(), mNodesPresent); WD = WD(nodeRank); // reorder results avgWeight = AverageEdgeWeight(WD.memptr(), WD.n_elem); R_CheckUserInterrupt(); // Fill the results vectors appropriately Fill(degree, WD.memptr(), mNodesPresent, propIdx.memptr(), mNodes); } results.push_back( Rcpp::List::create( Rcpp::Named("degree") = degree, Rcpp::Named("avgWeight") = avgWeight ) ); } results.names() = mods; return(results); }
int main(int argc, char **argv) { osFile fh; uint32_t total,areas,totaldupes; time_t firsttime,t; uint32_t DayStatsWritten; char buf[200],date[30],date2[30]; struct DiskAreaStats dastat; struct DiskNodeStats dnstat; struct StatsNode *sn; struct NodeStatsNode *nsn; struct jbList StatsList; struct jbList NodesList; uint32_t c,num,tot; uint16_t total8days[8]; char sortmode; struct tm *tp; char *monthnames[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","???"}; signal(SIGINT,breakfunc); if(!osInit()) exit(OS_EXIT_ERROR); if(argc > 1 && (strcmp(argv[1],"?")==0 || strcmp(argv[1],"-h")==0 || strcmp(argv[1],"--help")==0 || strcmp(argv[1],"help")==0 || strcmp(argv[1],"/h")==0 || strcmp(argv[1],"/?")==0 )) { printargs(args); osEnd(); exit(OS_EXIT_OK); } if(!parseargs(args,argc,argv)) { osEnd(); exit(OS_EXIT_ERROR); } sortmode='a'; if(args[ARG_SORT].data) sortmode=tolower(((char *)args[ARG_SORT].data)[0]); if(!strchr("amtdlu",sortmode)) { printf("Unknown sort mode %c\n",sortmode); osEnd(); exit(OS_EXIT_ERROR); } if(args[ARG_NOAREAS].data && args[ARG_NONODES].data) { printf("Nothing to do\n"); osEnd(); exit(OS_EXIT_ERROR); } printf("CrashStats "VERSION" © " COPYRIGHT " Johan Billing\n"); if(!(fh=osOpen(args[ARG_FILE].data,MODE_OLDFILE))) { uint32_t err=osError(); printf("Error opening %s\n",(char *)args[ARG_FILE].data); printf("Error: %s\n",osErrorMsg(err)); osEnd(); exit(OS_EXIT_ERROR); } osRead(fh,buf,4); buf[4]=0; if(strcmp(buf,STATS_IDENTIFIER)!=0) { printf("Unknown format of stats file\n"); osClose(fh); osEnd(); exit(OS_EXIT_ERROR); } osRead(fh,&DayStatsWritten,sizeof(uint32_t)); total=0; totaldupes=0; firsttime=0; areas=0; for(c=0;c<8;c++) total8days[c]=0; jbNewList(&StatsList); jbNewList(&NodesList); osRead(fh,&num,sizeof(uint32_t)); c=0; if(!args[ARG_NOAREAS].data) { while(c<num && osRead(fh,&dastat,sizeof(struct DiskAreaStats))==sizeof(struct DiskAreaStats)) { if(!args[ARG_GROUP].data || CheckFlags(dastat.Group,args[ARG_GROUP].data)) { if(!(sn=osAlloc(sizeof(struct StatsNode)))) { printf("Out of memory\n"); jbFreeList(&StatsList); osClose(fh); osEnd(); exit(OS_EXIT_ERROR); } jbAddNode(&StatsList,(struct jbNode *)sn); strcpy(sn->Tagname,dastat.Tagname); sn->Dupes=dastat.Dupes; sn->Total=dastat.TotalTexts; sn->FirstTime=dastat.FirstTime; sn->LastTime=dastat.LastTime; memcpy(&sn->Last8Days[0],&dastat.Last8Days[0],8*sizeof(uint16_t)); sn->Average=CalculateAverage(&dastat.Last8Days[0],dastat.TotalTexts,DayStatsWritten,sn->FirstTime / (24*60*60)); } if(dastat.FirstTime!=0) if(firsttime==0 || firsttime > dastat.FirstTime) firsttime=dastat.FirstTime; c++; } } else { while(c<num && osRead(fh,&dastat,sizeof(struct DiskAreaStats))==sizeof(struct DiskAreaStats)) c++; } osRead(fh,&num,sizeof(uint32_t)); c=0; if(!args[ARG_NONODES].data) { while(c<num && osRead(fh,&dnstat,sizeof(struct DiskNodeStats))==sizeof(struct DiskNodeStats)) { if(!(nsn=osAlloc(sizeof(struct NodeStatsNode)))) { printf("Out of memory\n"); jbFreeList(&NodesList); jbFreeList(&StatsList); osClose(fh); osEnd(); exit(OS_EXIT_ERROR); } jbAddNode(&NodesList,(struct jbNode *)nsn); Copy4D(&nsn->Node,&dnstat.Node); nsn->GotNetmails=dnstat.GotNetmails; nsn->GotNetmailBytes=dnstat.GotNetmailBytes; nsn->SentNetmails=dnstat.SentNetmails; nsn->SentNetmailBytes=dnstat.SentNetmailBytes; nsn->GotEchomails=dnstat.GotEchomails; nsn->GotEchomailBytes=dnstat.GotEchomailBytes; nsn->SentEchomails=dnstat.SentEchomails; nsn->SentEchomailBytes=dnstat.SentEchomailBytes; nsn->Dupes=dnstat.Dupes; nsn->Days=DayStatsWritten-dnstat.FirstTime % (24*60*60); if(nsn->Days==0) nsn->Days=1; nsn->FirstTime=dnstat.FirstTime; if(dnstat.FirstTime!=0) if(firsttime==0 || firsttime > dnstat.FirstTime) firsttime=dnstat.FirstTime; c++; } } else { while(c<num && osRead(fh,&dnstat,sizeof(struct DiskNodeStats))==sizeof(struct DiskNodeStats)) c++; } osClose(fh); t=(time_t)DayStatsWritten * 24*60*60; tp=localtime(&firsttime); sprintf(date,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100); tp=localtime(&t); sprintf(date2,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100); printf("\nStatistics from %s to %s\n",date,date2); if(!ctrlc && !args[ARG_NOAREAS].data) { Sort(&StatsList,'a'); Sort(&StatsList,sortmode); printf("\n"); if(args[ARG_LAST7].data) { printf("Area "); for(c=1;c<8;c++) { t=(DayStatsWritten-c)*24*60*60; tp=localtime(&t); printf(" %02d",tp->tm_mday); } printf(" Total\n============================================================================\n"); if(!ctrlc) { for(sn=(struct StatsNode *)StatsList.First;sn && !ctrlc;sn=sn->Next) { tot=0; for(c=1;c<8;c++) tot+=sn->Last8Days[c]; printf("%-33.33s %4d %4d %4d %4d %4d %4d %4d : %5d\n", sn->Tagname, sn->Last8Days[1], sn->Last8Days[2], sn->Last8Days[3], sn->Last8Days[4], sn->Last8Days[5], sn->Last8Days[6], sn->Last8Days[7], tot); for(c=1;c<8;c++) total8days[c]+=sn->Last8Days[c]; areas++; } if(!ctrlc) { tot=0; for(c=1;c<8;c++) tot+=total8days[c]; printf("=============================================================================\n"); sprintf(buf,"Totally in all %u areas",areas); printf("%-33.33s %4d %4d %4d %4d %4d %4d %4d : %5d\n", buf, total8days[1], total8days[2], total8days[3], total8days[4], total8days[5], total8days[6], total8days[7], tot); } } } else { printf("Area First Last Msgs Msgs/day Dupes\n"); printf("============================================================================\n"); if(!ctrlc) { for(sn=(struct StatsNode *)StatsList.First;sn && !ctrlc;sn=sn->Next) { if(sn->LastTime==0) { strcpy(date2,"<Never>"); } else { tp=localtime(&sn->LastTime); sprintf(date2,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100); } if(sn->FirstTime==0) { strcpy(date,"<Never>"); } else { tp=localtime(&sn->FirstTime); sprintf(date,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100); } for(c=0;c<8;c++) total8days[c]+=sn->Last8Days[c]; total+=sn->Total; totaldupes+=sn->Dupes; areas++; printf("%-29.30s %-9.9s %-9.9s %7d %7d %7d\n",sn->Tagname,date,date2,sn->Total,sn->Average,sn->Dupes); } } if(!ctrlc) { printf("============================================================================\n"); sprintf(buf,"Totally in all %u areas",areas); printf("%-42s %7d %7d %7d\n", buf, total, CalculateAverage(&total8days[0],total,DayStatsWritten,firsttime / (24*60*60)), totaldupes); } } } if(!ctrlc && !args[ARG_NONODES].data) { SortNodes(&NodesList); printf("\n"); printf("Nodes statistics\n"); printf("================\n"); for(nsn=(struct NodeStatsNode *)NodesList.First;nsn && !ctrlc;nsn=nsn->Next) { if(nsn->FirstTime==0) { strcpy(date,"<Never>"); } else { tp=localtime(&nsn->FirstTime); sprintf(date,"%0d-%s-%0d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100); } sprintf(buf,"%u:%u/%u.%u",nsn->Node.Zone,nsn->Node.Net,nsn->Node.Node,nsn->Node.Point); printf("%-30.40s Statistics since: %s\n\n",buf,date); printf(" Sent netmails: %u/%s\n",nsn->SentNetmails,unit(nsn->SentNetmailBytes)); printf(" Received netmails: %u/%s\n",nsn->GotNetmails,unit(nsn->GotNetmailBytes)); printf(" Sent echomails: %u/%s\n",nsn->SentEchomails,unit(nsn->SentEchomailBytes)); printf(" Received echomails: %u/%s\n",nsn->GotEchomails,unit(nsn->GotEchomailBytes)); printf(" Dupes: %u\n",nsn->Dupes); printf("\n"); } } if(ctrlc) { printf("*** Break\n"); } else { printf("\n"); } jbFreeList(&StatsList); jbFreeList(&NodesList); osEnd(); exit(OS_EXIT_OK); }
///' Calculate the intermediate network properties in the discovery dataset ///' ///' These properties are need at every permutation: so they will be computed ///' once. ///' ///' @details ///' \subsection{Input expectations:}{ ///' Note that this function expects all inputs to be sensible, as checked by ///' the R function 'checkUserInput' and processed by 'modulePreservation'. ///' ///' These requirements are: ///' \itemize{ ///' \item{The ordering of node names across 'dData', 'dCorr', and 'dNet' is ///' consistent.} ///' \item{The columns of 'dData' are the nodes.} ///' \item{'dData' has been scaled by 'Scale'.} ///' \item{'dCorr' and 'dNet' are square matrices, and their rownames are ///' identical to their column names.} ///' \item{'moduleAssigments' is a named character vector, where the names ///' represent node labels found in the discovery dataset (e.g. 'dNet').} ///' } ///' } ///' ///' @param dData scaled data matrix from the \emph{discovery} dataset. ///' @param dCorr matrix of correlation coefficients between all pairs of ///' variables/nodes in the \emph{discovery} dataset. ///' @param dNet adjacency matrix of network edge weights between all pairs of ///' nodes in the \emph{discovery} dataset. ///' @param tNodeNames a character vector of node names in the test dataset ///' @param moduleAssignments a named character vector containing the module ///' each node belongs to in the discovery dataset. ///' @param modules a character vector of modules for which to calculate the ///' module preservation statistics. ///' ///' @return a list containing three lists: a list of weighted degree vectors, ///' a list of correlation coefficient vectors, and a list of node ///' contribution vectors. There is one vector for each module in each list. ///' ///' @keywords internal // [[Rcpp::export]] Rcpp::List IntermediateProperties ( Rcpp::NumericMatrix dData, Rcpp::NumericMatrix dCorr, Rcpp::NumericMatrix dNet, Rcpp::CharacterVector tNodeNames, Rcpp::CharacterVector moduleAssignments, Rcpp::CharacterVector modules ) { // First, scale the matrix data unsigned int nSamples = dData.nrow(); unsigned int nNodes = dData.ncol(); R_CheckUserInterrupt(); // convert the colnames / rownames to C++ equivalents const std::vector<std::string> dNames (Rcpp::as<std::vector<std::string>>(colnames(dNet))); const std::vector<std::string> tNames (Rcpp::as<std::vector<std::string>>(tNodeNames)); /* Next, we need to create three mappings: * - From node IDs to indices in the discovery dataset. * - From modules to all node IDs. * - From modules to just node IDs present in the test dataset. */ const namemap dIdxMap = MakeIdxMap(dNames); const stringmap modNodeMap = MakeModMap(moduleAssignments); const namemap tIdxMap = MakeIdxMap(tNames); const stringmap modNodePresentMap = MakeModMap(moduleAssignments, tIdxMap); // What modules do we actually want to analyse? const std::vector<std::string> mods (Rcpp::as<std::vector<std::string>>(modules)); // We only need to iterate through modules which have nodes in the test // dataset std::vector<std::string> modsPresent; for (auto it = mods.begin(); it != mods.end(); ++it) { if (modNodePresentMap.count(*it) > 0) { modsPresent.push_back(*it); } } R_CheckUserInterrupt(); Rcpp::List degree; Rcpp::List corr; Rcpp::List contribution; // Calculate the network properties in the discovery dataset. std::string mod; unsigned int mNodes; arma::uvec dIdx, dRank; arma::vec dSP, dWD, dCV, dNC; for (auto mi = modsPresent.begin(); mi != modsPresent.end(); ++mi) { // Get the node indices in the discovery dataset for this module mod = *mi; dIdx = GetNodeIdx(mod, modNodePresentMap, dIdxMap); mNodes = dIdx.n_elem; R_CheckUserInterrupt(); // Calculate the network properties and insert into their storage containers dCV = CorrVector(dCorr.begin(), nNodes, dIdx.memptr(), mNodes); R_CheckUserInterrupt(); // Sort node indices for sequential memory access dRank = SortNodes(dIdx.memptr(), mNodes); dWD = WeightedDegree(dNet.begin(), nNodes, dIdx.memptr(), mNodes); dWD = dWD(dRank); // reorder R_CheckUserInterrupt(); dSP = SummaryProfile(dData.begin(), nSamples, nNodes, dIdx.memptr(), mNodes); R_CheckUserInterrupt(); dNC = NodeContribution(dData.begin(), nSamples, nNodes, dIdx.memptr(), mNodes, dSP.memptr()); dNC = dNC(dRank); // reorder results R_CheckUserInterrupt(); // Cast to R-vectors and add to results lists corr.push_back(Rcpp::NumericVector(dCV.begin(), dCV.end())); degree.push_back(Rcpp::NumericVector(dWD.begin(), dWD.end())); contribution.push_back(Rcpp::NumericVector(dNC.begin(), dNC.end())); } degree.names() = modsPresent; corr.names() = modsPresent; contribution.names() = modsPresent; return Rcpp::List::create( Rcpp::Named("degree") = degree, Rcpp::Named("corr") = corr, Rcpp::Named("contribution") = contribution ); }
struct node* InsertNodeAtPos(struct node **anchor_ptr, int pos){ if(nodedebugsw == 1) printf("Checking if adding node to pos:%d is possible. ", pos); if((*anchor_ptr) == 0){ if(pos == 0){ struct node *newnode_ptr; newnode_ptr = malloc(sizeof(struct node)); if(newnode_ptr == 0){ printf("Cannot allocate memory for newnode_ptr\n"); return 0; } newnode_ptr->nextobject_ptr = 0; newnode_ptr->pos = pos; newnode_ptr->id = 0; (*anchor_ptr) = newnode_ptr; if(nodedebugsw == 1) printf("List is empty. Adding node to the beginning of the list with attributes: id:%d, pos:%d\n", (*anchor_ptr)->id, (*anchor_ptr)->pos); return newnode_ptr; } else{ if(nodedebugsw == 1) printf("Couldn't add node to pos:%d because the list is empty\n", pos); return 0; } } else{ struct node *cnt_ptr; cnt_ptr = (*anchor_ptr); struct node *newnode_ptr; while(cnt_ptr->nextobject_ptr != 0){ cnt_ptr = cnt_ptr->nextobject_ptr; } while(cnt_ptr->nextobject_ptr != 0 && cnt_ptr->nextobject_ptr->pos != pos ){ cnt_ptr = cnt_ptr->nextobject_ptr; if(nodedebugsw == 1) printf(". "); } if(cnt_ptr->nextobject_ptr->pos == pos && cnt_ptr->nextobject_ptr == 0){ newnode_ptr = malloc(sizeof(struct node)); if(newnode_ptr == 0){ if(nodedebugsw == 1) printf("Cannot allocate memory for newnode_ptr\n"); return 0; } newnode_ptr->nextobject_ptr = 0; newnode_ptr->pos = pos; cnt_ptr->nextobject_ptr=newnode_ptr; SortNodes((*anchor_ptr)); if(nodedebugsw == 1) printf("Added node at pos:%d at the end of the list\n", pos); return newnode_ptr; } if(cnt_ptr->nextobject_ptr->pos == pos && cnt_ptr->nextobject_ptr != 0){ newnode_ptr = malloc(sizeof(struct node)); if(newnode_ptr == 0){ if(nodedebugsw == 1) printf("Cannot allocate memory for newnode_ptr\n"); return 0; } newnode_ptr->nextobject_ptr = cnt_ptr->nextobject_ptr; cnt_ptr->nextobject_ptr = newnode_ptr; SortNodes((*anchor_ptr)); if(nodedebugsw == 1) printf("Added node at pos:%d on the list\n", pos); return newnode_ptr; } return 0; } }