📄 graphcreate.c
字号:
#include "graphcreate.h"#define DBG_LVL 0int getGraph(int index, graphs *graph, int *gap, int **iphi) { int Gnum, i, j, k,node, socket; if ( ( index <= 0 ) ) { PR_DBG( 0, "Don't know about code %i\n", index ); return -1; } Gnum=index-1; i=0; (*graph).vnodenum=codes[Gnum][i]; i++; (*graph).cnodenum=codes[Gnum][i]; i++; (*graph).rate=1.0-((double)(*graph).cnodenum)/((double)(*graph).vnodenum); (*graph).vdegreesnum=codes[Gnum][i]; i++; (*graph).cdegreesnum=codes[Gnum][i]; i++; (*graph).vmaxdegree=codes[Gnum][i]; i++; (*graph).cmaxdegree=codes[Gnum][i]; i++; /* allocate memory for nodes */ PR_DBG( 3 , "allocating nodelists and degreelists\n"); (*graph).vnodelist=(vnode *)swr_malloc(sizeof(vnode)*(*graph).vnodenum); (*graph).cnodelist=(cnode *)swr_malloc(sizeof(cnode)*(*graph).cnodenum); /* enter the degreelist */ (*graph).vdegreelist=(degreelist *)swr_malloc(sizeof(degreelist)); (*graph).cdegreelist=(degreelist *)swr_malloc(sizeof(degreelist)); /* assign vnodelist */ for (j=0; j<(*graph).vdegreesnum; j++) { (*(*graph).vdegreelist).degree[j]=codes[Gnum][i]; i++; (*(*graph).vdegreelist).numofnodes[j]=codes[Gnum][i]; i++; } /* assign cnodelist */ for (j=0; j<(*graph).cdegreesnum; j++) { (*(*graph).cdegreelist).degree[j]=codes[Gnum][i]; i++; (*(*graph).cdegreelist).numofnodes[j]=codes[Gnum][i]; i++; } /* assign vnodes */ PR_DBG( 3 , "allocating vnodeedgelists\n") for (node=0; node<(*graph).vnodenum; node++) { vnodedegree=codes[Gnum][i]; i++; vnodeedgelist=(edge *)swr_malloc(sizeof(edge)*vnodedegree); for (socket=0; socket<vnodedegree; socket++) { vnodeedge.dest=codes[Gnum][i]; i++; vnodeedge.socket=codes[Gnum][i]; i++; } } /* assign cnodes */ PR_DBG( 3 , "allocating cnodeedgelists\n") for (node=0; node<(*graph).cnodenum; node++) { cnodedegree=codes[Gnum][i]; i++; cnodeedgelist=(edge *)swr_malloc(sizeof(edge)*cnodedegree); for (socket=0; socket<cnodedegree; socket++) { cnodeedge.dest=codes[Gnum][i]; i++; cnodeedge.socket=codes[Gnum][i]; i++; } } //assign encoder preprocessed data (*gap)=codes[Gnum][i]; i++; *iphi=(int *)swr_malloc((*gap)*(*gap)*sizeof(int)); for (j=0; j<(*gap); j++) { for (k=0; k<(*gap); k++) { *(*iphi+j*(*gap)+k)=codes[Gnum][i]; i++; } } return(0);}/****************************************//** Free most of the memory of a graph **//****************************************/void freeGraph(graphs *graph,int *iphi) { int node; /* deallocate memory for edges */ PR_DBG( 3 , "freeing vnodeedgelists\n"); for (node=0; node<(*graph).vnodenum; node++) swr_free((*((*graph).vnodelist+node)).edgelist);//swr_free(vnodeedgelist); PR_DBG( 3 , "freeing cnodeedgelists\n"); for (node=0; node<(*graph).cnodenum; node++) swr_free((*((*graph).cnodelist+node)).edgelist);//swr_free(cnodeedgelist); /* deallocate memory for nodes */ PR_DBG( 3 , "freeing nodelists and degreelists\n"); swr_free((*graph).vnodelist); swr_free((*graph).cnodelist); /* deallocate memory for degreelist */ swr_free((*graph).vdegreelist); swr_free((*graph).cdegreelist); /* deallocate memory for iphi */ PR_DBG( 3 , "freeing iphi\n"); swr_free(iphi);}int getGraphtemp(int index, graphstemp *graph, int *gap, int **iphi) { int Gnum,i,j,k,l=0, node, socket, startingpoint,vdegindex,cdegindex; int *vtmp,*ctmp; //int *vdegrees, *vdegreedisp, *cdegrees, *cdegreedisp; if ( ( index <= 0 ) ) { PR_DBG( 0, "Don't know about code %i\n", index ); return -1; } Gnum=index-1; i=0; (*graph).vnodenum=codes[Gnum][i]; i++; (*graph).cnodenum=codes[Gnum][i]; i++; (*graph).vdegrees = (int *) swr_malloc(sizeof(int) *(*graph).vnodenum); (*graph).vdegreedisp = (int *) swr_malloc(sizeof(int) * (*graph).vnodenum); (*graph).cdegrees = (int *) swr_malloc(sizeof(int) * (*graph).cnodenum); (*graph).cdegreedisp = (int *) swr_malloc(sizeof(int) * (*graph).cnodenum); (*graph).rate=1.0-((double)(*graph).cnodenum)/((double)(*graph).vnodenum); (*graph).vdegreesnum=codes[Gnum][i]; i++; (*graph).cdegreesnum=codes[Gnum][i]; i++; (*graph).vmaxdegree=codes[Gnum][i]; i++; (*graph).cmaxdegree=codes[Gnum][i]; i++; vtmp = (int *) swr_malloc(sizeof(int) *(*graph).vdegreesnum); ctmp = (int *) swr_malloc(sizeof(int) *(*graph).cdegreesnum); (*graph).rec = (short int **) swr_malloc(sizeof(short int *) *(*graph).vdegreesnum); (*graph).getnode = (int **) swr_malloc(sizeof(int *) *(*graph).vdegreesnum); //contain the dynamic displacement within a degree of each node while scanning for(vdegindex=0;vdegindex<(*graph).vdegreesnum;vdegindex++) vtmp[vdegindex]=0; for(cdegindex=0;cdegindex<(*graph).cdegreesnum;cdegindex++) ctmp[cdegindex]=0; /* allocate memory for node message values*/ PR_DBG( 3 , "allocating nodelists and degreelists\n"); (*graph).vnodes = (short int ***)swr_malloc(sizeof(short int **) * (*graph).vdegreesnum); (*graph).cnodes = (short int ***)swr_malloc(sizeof(short int **) * (*graph).cdegreesnum); /*allocate memory for edge pointers from the nodes*/ (*graph).vnodeedges = (edge1 ***)swr_malloc(sizeof(edge1 **) * (*graph).vdegreesnum); (*graph).cnodeedges = (edge1 ***)swr_malloc(sizeof(edge1 **) * (*graph).cdegreesnum); /*allocate memory for lookuptable to get index of the type of degree*/ (*graph).cdegreelookup = (int *) swr_malloc(sizeof(int) * (*graph).cdegreesnum); (*graph).vdegreelookup = (int *) swr_malloc(sizeof(int) * (*graph).vdegreesnum); /* enter the degreelist */ (*graph).vdegreelist=(degreelist *)swr_malloc(sizeof(degreelist)); (*graph).cdegreelist=(degreelist *)swr_malloc(sizeof(degreelist)); /* assign vnodelist */ /*lookup gives the degree index given its degree*/ for (j=0; j<(*graph).vdegreesnum; j++) { (*(*graph).vdegreelist).degree[j]=codes[Gnum][i]; (*graph).vdegreelookup[codes[Gnum][i]] = j; i++; (*(*graph).vdegreelist).numofnodes[j]=codes[Gnum][i]; i++; } for(j=0; j<(*graph).vdegreesnum; j++) { (*graph).vnodes[j] = (short int **) swr_malloc(sizeof(short int *) * (*(*graph).vdegreelist).degree[j]); (*graph).vnodeedges[j] = (edge1 **) swr_malloc(sizeof(edge1*) * (*(*graph).vdegreelist).degree[j]); (*graph).rec[j] = (short int*) swr_malloc(sizeof(short int) * (*(*graph).vdegreelist).numofnodes[j]); (*graph).getnode[j] = (int*) swr_malloc(sizeof(int) * (*(*graph).vdegreelist).numofnodes[j]); for(l=0;l<(*(*graph).vdegreelist).degree[j];l++) { (*graph).vnodes[j][l] = (short int*) swr_malloc(sizeof(short int) * (*(*graph).vdegreelist).numofnodes[j]); (*graph).vnodeedges[j][l] = (edge1*) swr_malloc(sizeof(edge1) * (*(*graph).vdegreelist).numofnodes[j]); } } /* assign cnodelist */ for (j=0; j<(*graph).cdegreesnum; j++) { (*(*graph).cdegreelist).degree[j]=codes[Gnum][i]; (*graph).cdegreelookup[codes[Gnum][i]] = j; i++; (*(*graph).cdegreelist).numofnodes[j]=codes[Gnum][i]; i++; } for(j=0; j<(*graph).cdegreesnum; j++) { (*graph).cnodes[j] = (short int **) swr_malloc(sizeof(short int*) * (*(*graph).cdegreelist).degree[j]); (*graph).cnodeedges[j] = (edge1 **) swr_malloc(sizeof(edge1*) * (*(*graph).cdegreelist).degree[j]); for(l=0;l<(*(*graph).cdegreelist).degree[j];l++) { (*graph).cnodes[j][l] = (short int*) swr_malloc(sizeof(short int) * (*(*graph).cdegreelist).numofnodes[j]); (*graph).cnodeedges[j][l] = (edge1*) swr_malloc(sizeof(edge1) * (*(*graph).cdegreelist).numofnodes[j]); } } // assign vnodes PR_DBG( 3 , "allocating vnodeedgelists\n") startingpoint = i; for (node=0; node<(*graph).vnodenum; node++) { vnodedeg=codes[Gnum][i]; i++; //assign to this node the displacement it has within its degree (*graph).vdegreedisp[node] = vtmp[(*graph).vdegreelookup[vnodedeg]]; vtmp[(*graph).vdegreelookup[vnodedeg]]++; (*graph).getnode[(*graph).vdegreelookup[vnodedeg]][(*graph).vdegreedisp[node]]=node; i+= 2 * vnodedeg; } for (node=0; node<(*graph).cnodenum; node++) { cnodedeg=codes[Gnum][i]; i++; (*graph).cdegreedisp[node] = ctmp[(*graph).cdegreelookup[cnodedeg]]; i+= 2 * cnodedeg; ctmp[(*graph).cdegreelookup[cnodedeg]]++; //PR_DBG(0," The cdegreedisp [%i] is %i\n",i,(*graph).cdegreedisp[node]); } /* for(node=0;node<(*graph).vnodenum;node++) { PR_DBG(0," Degree = %i Disp is %i, vnodenum is %i\n",(*graph).vdegrees[node],(*graph).vdegreedisp[node],node); }*/ //exit(0); (*gap)=codes[Gnum][i]; i++; *iphi=(int *)swr_malloc((*gap)*(*gap)*sizeof(int)); for (j=0; j<(*gap); j++) { for (k=0; k<(*gap); k++) { *(*iphi+j*(*gap)+k)=codes[Gnum][i]; i++; } } i= startingpoint; for (node=0; node<(*graph).vnodenum; node++) { //vnodedeg=codes[Gnum][i]; i++; edge1 etemp; //etemp.msgforvnode = (double*) swr_malloc(sizeof(double)); //etemp.msgforcnode = (double*) swr_malloc(sizeof(double)); for (socket=0; socket<vnodedeg; socket++) { etemp.msgforvnode = &((*graph).vnodes[(*graph).vdegreelookup[vnodedeg]][socket][(*graph).vdegreedisp[node]]); etemp.msgforcnode = &((*graph).cnodes[(*graph).cdegreelookup[(*graph).cdegrees[codes[Gnum][i]]]][codes[Gnum][i+1]][(*graph).cdegreedisp[codes[Gnum][i]]]); i++; (*graph).vnodeedges[(*graph).vdegreelookup[vnodedeg]][socket][(*graph).vdegreedisp[node]]= etemp; (*graph).cnodeedges[(*graph).cdegreelookup[(*graph).cdegrees[codes[Gnum][i-1]]]][codes[Gnum][i]][(*graph).cdegreedisp[codes[Gnum][i-1]]]= etemp; //vnodeedge.dest=codes[Gnum][i]; //i++; //vnodeedge.socket=codes[Gnum][i]; i++; } } //assign encoder preprocessed data return(0);}void freeGraphtemp(graphstemp *graph,int *iphi) { PR_DBG( 3 , "freeing iphi\n"); swr_free(iphi);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -