i am trying to implement GP , and have random initialization in arraylist , the code works fine in debug mode , but when i run it without debugging, all trees come out to be same ,
if i use message box to show these trees , code works fine again ...
i have become MAD in resolving this issue !!
create_rndtree( ref al[i],depth)
create_fixtree( ref al[i],depth);
trees are stored in al array of arralist , which is cleared first
below is the code for one of the functions
private void create_rndtree( ref ArrayList tree,int depth)
{
tree.Clear();
int dangling_limbs = 1;
int i;
Random random = new Random();
double rnd;
int rndint;
//ArrayList tree=new ArrayList( );
char[] function=new char[4];
function[0]='-';
function[1]='+';
function[2]='/';
function[3]='*';
int num_attrib=cols-1;//one column is for class
//now how to generate the tree
//int possiblenodes=( cols-1)+function.Len gth+rnd;
int maxdepth=depth;
int leaf_nodes=Conv ert.ToInt32(Mat h.Pow(2,maxdept h));
int nodecount=0;
for (int k=0;k<maxdepth; k++)
{
nodecount=nodec ount+Convert.To Int32(Math.Pow( 2,k));
}
int max_size=nodeco unt;
object[] leafs=new object[leaf_nodes];
leafs=title.Spl it(';');
for ( i = 0; (dangling_limbs > 0) && (i <= max_size) ; i++ )
{ /*chose function or terminal at random*/
rnd=random.Next (0,100);
rnd=rnd/100;
if( rnd > (double)(dangli ng_limbs*dangli ng_limbs+1)/(double)(max_si ze-i) )// what is this for ????
{
rndint=random.N ext(0,4);
tree.Add(Conver t.ToString(func tion[rndint]));
dangling_limbs+ +; /*all operators have two limbs*/
}
else
{
rndint=random.N ext(0,leafs.Len gth+1);
if(rndint==leaf s.Length)
{
tree.Add((rando m.Next(0,10)));
}
else
{
tree.Add(leafs[rndint]);
}
dangling_limbs--;
}
}/*end for*/
dangling_limbs =0;;
//string temp=null;
}
i hope someone can help me out of it !!!!
if i use message box to show these trees , code works fine again ...
i have become MAD in resolving this issue !!
create_rndtree( ref al[i],depth)
create_fixtree( ref al[i],depth);
trees are stored in al array of arralist , which is cleared first
below is the code for one of the functions
private void create_rndtree( ref ArrayList tree,int depth)
{
tree.Clear();
int dangling_limbs = 1;
int i;
Random random = new Random();
double rnd;
int rndint;
//ArrayList tree=new ArrayList( );
char[] function=new char[4];
function[0]='-';
function[1]='+';
function[2]='/';
function[3]='*';
int num_attrib=cols-1;//one column is for class
//now how to generate the tree
//int possiblenodes=( cols-1)+function.Len gth+rnd;
int maxdepth=depth;
int leaf_nodes=Conv ert.ToInt32(Mat h.Pow(2,maxdept h));
int nodecount=0;
for (int k=0;k<maxdepth; k++)
{
nodecount=nodec ount+Convert.To Int32(Math.Pow( 2,k));
}
int max_size=nodeco unt;
object[] leafs=new object[leaf_nodes];
leafs=title.Spl it(';');
for ( i = 0; (dangling_limbs > 0) && (i <= max_size) ; i++ )
{ /*chose function or terminal at random*/
rnd=random.Next (0,100);
rnd=rnd/100;
if( rnd > (double)(dangli ng_limbs*dangli ng_limbs+1)/(double)(max_si ze-i) )// what is this for ????
{
rndint=random.N ext(0,4);
tree.Add(Conver t.ToString(func tion[rndint]));
dangling_limbs+ +; /*all operators have two limbs*/
}
else
{
rndint=random.N ext(0,leafs.Len gth+1);
if(rndint==leaf s.Length)
{
tree.Add((rando m.Next(0,10)));
}
else
{
tree.Add(leafs[rndint]);
}
dangling_limbs--;
}
}/*end for*/
dangling_limbs =0;;
//string temp=null;
}
i hope someone can help me out of it !!!!