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.Length+rnd;
int maxdepth=depth;
int leaf_nodes=Convert.ToInt32(Math.Pow(2,maxdepth));
int nodecount=0;
for (int k=0;k<maxdepth;k++)
{
nodecount=nodecount+Convert.ToInt32(Math.Pow(2,k)) ;
}
int max_size=nodecount;
object[] leafs=new object[leaf_nodes];
leafs=title.Split(';');
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)(dangling_limbs*dangling_limbs+1)/(double)(max_size-i) )// what is this for ????
{
rndint=random.Next(0,4);
tree.Add(Convert.ToString(function[rndint]));
dangling_limbs++; /*all operators have two limbs*/
}
else
{
rndint=random.Next(0,leafs.Length+1);
if(rndint==leafs.Length)
{
tree.Add((random.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 !!!!