Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to produce an irregular graph. i find a code that produce irregular graph but because i use windows 7 it doesn't support functions drand48() and srand48(), so i use srand() and ((float) rand()) / (float) RAND_MAX) instead of them.
when i run my program for small nodes and edges it works but when i run it for large nodes and edges( for example 90000 nodes and 900000 edges it doesn't work.
"my error is CRT detected that the application wrote after end of heap buffer"

i don't know if it is because my memory card size or my code is wrong or i shouldn't use srand()and srand48() instead of those functions.
could any one help me?
my RAM is 4GB and i use windows 7 32 bit


C++
    gpgraph *  create_RMAT_graph(int N, int M,int rseed, double a, double b, double c, bool permute)
{
	double d;
	d=1-(a+b+c);
	double drand48(void);
	
	gpgraph* g1=new gpgraph();
	g1->allocate_node(N,M);
	
	int *src=new int[M];
	int *dest=new int[M];
	int *degree=new int[N];
	
	for(int i=0;i<n;i++)>
		degree[i]=0;
	
	int SCALE=(int) log2((double)N);
	
	srand(rseed);
	
	for(int i=0;i<m;i++)>
	{
		int u=1;
		int v=1;
		int step=N/2;
		double av=a;
		double bv=b;
		double cv=c;
		double dv=d;
		
		double p=(((float) rand()) / (float) RAND_MAX);
		if(p<av){}>
		else if(p<(av+bv))
			v+=step;
		else if(p<(av+bv+cv))
			u+=step;
		else
		{
			v+=step;
			u+=step;
		}
		for(int j=1;j<scale;j++)>
		{
			step=step/2;
			double var=0.1;
			av*=0.95+var*(((float) rand()) / (float) RAND_MAX);
			bv*=0.95+var*(((float) rand()) / (float) RAND_MAX);
			cv*=0.95+var*(((float) rand()) / (float) RAND_MAX);
			dv*=0.95+var*(((float) rand()) / (float) RAND_MAX);
			double S=av+bv+cv+dv;
			av=av/S;
			bv=bv/S;
			cv=cv/S;
			dv=dv/S;
			
			p=(((float) rand()) / (float) RAND_MAX);
			if(p<av){}>
			else if(p<(av+bv))
				v+=step;
			else if(p<(av+bv+cv))
				u+=step;
			else{
				v+=step;
				u+=step;
			}
		}
		src[i]=u-1;
		dest[i]=v-1;
		if(src[i]==dest[i])
		{
			i=i-1;
			continue;
		}
	}
	if(permute)
	{
		int* p=new int[N];
		for(int i=0;i<n;i++)>
			p[i]=i;
		for(int i=0;i<n;i++)>
		{
			int j=(int)(N * (((float) rand()) / (float) RAND_MAX));
			int temp=p[j];
			p[j]=p[i];
			p[i]=temp;
		}
		for(int i=0;i<m;i++)>
		{
			src[i]=p[src[i]];
			dest[i]=p[dest[i]];
		}
		delete []p;
	}
		
	for(int i=0;i<m;i++)>
		degree[src[i]]++;
	
	g1->h_nodes[0]=0;
	for(int i=1;i<n;i++)>
		g1->h_nodes[i]=g1->h_nodes[i-1]+degree[i-1];
		
	for(int i=0;i<m;i++)>
	{
		int u=src[i];
		int v=dest[i];
		int pos=degree[u]--;
		g1->h_edges[g1->h_nodes[u]+pos-1]=v;
	}

	delete [] src;
	delete []dest;
	delete []degree;
		
	return g1;
    }
    int main( int argc, char** argv) 
    {

	g=create_RMAT_graph(90000,9000000,1993,0.45,0.25,0.15,true);

    }
Posted
Updated 26-Jul-13 7:21am
v2
Comments
Sergey Alexandrovich Kryukov 26-Jul-13 13:59pm    
In what line? And how do you define "irregular graph"?
—SA
pari_6 26-Jul-13 15:46pm    
infact function create_RMAT_graph produce irregular graph
Sergey Alexandrovich Kryukov 26-Jul-13 23:46pm    
And is there any strict definition of "irregular"?
—SA
pari_6 27-Jul-13 2:51am    
In regular graphs all neighbors of a vertex have the same degree. but in irregular some of vertices have more degree than others.
Sergey Alexandrovich Kryukov 27-Jul-13 23:36pm    
If so, the "irregular graph" is simply the synonymous of the term "graph", nothing else. It's just that "regularity" is not the case...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900