Container create(unsigned int n)
{
  Container s;
  rand_seq  rnd(n);
  while(n--)insert_random(s, rnd);
  return s;
}
Example #2
0
void Tree::insert_rnd(unsigned int max_depth, bool halframping)
{
   if(root)
   {
      if(root->mChilds.size() == 0)
      {
         int childs = 2;

         if( root->getOperator() == Operators::ifthen4)
         {
            childs = 4;
         }

         if(root->getOperator() >= Operators::add && root->getOperator() <= Operators::mul)
         {
            childs = 2;
         }

         if(root->getOperator() >= Operators::MoveLeft && root->getOperator() <= Operators::DoNothing)
         {
            childs = 1;
         }

         for(int i = 0; i < childs; i++)
         {
            root->insertChild(insert_random(root, max_depth-1, halframping));
         }
      }
   }
}
Example #3
0
void Tree::grow()
{
   Node* rand_A = select_random_node(root);

   if(rand_A->mChilds.size() >= 1)
   {
      int child = mRandom.rnd(0, rand_A->mChilds.size()-1);

      delete rand_A->mChilds.at(child);

      rand_A->mChilds.at(child) = insert_random(rand_A, mRandom.rnd(0, 2));
   }
}
Example #4
0
 ///driver function to generate, insert and search rb hash tree
 void random_runner() {
     clock_t start, end;
     double insert_array[10], search_array[10];
     for ( int i = 0; i < 10; i++ ) {
         generate_random();
         start = ((double)clock()*1000)/CLOCKS_PER_SEC;
         insert_random();
         end = ((double)clock()*1000)/CLOCKS_PER_SEC;
         insert_array[i] = end - start;
         start = ((double)clock()*1000)/CLOCKS_PER_SEC;
         search_random();
         end = ((double)clock()*1000)/CLOCKS_PER_SEC;
         search_array[i] = end - start;
         make_root_null();
     }
     cout << avg ( insert_array ) << " " <<  avg ( search_array ) << endl;    
 }
Example #5
0
 void random_runner() {
     clock_t start, end;
     long insert_array[10], search_array[10];
     cout << "Experiment Running....." << endl;
     for ( int i = 0; i < 10; i++ ) {
         generate_random();
         start = clock();
         insert_random();
         end = clock();
         insert_array[i] = end - start;
         start = clock();
         search_random();
         end = clock();
         search_array[i] = end - start;
         make_root_null();
     }
     cout << "Insert Avg. Time : " << avg ( insert_array ) << "   " << "Search Avg. Time : " << avg ( search_array ) << endl;
 }
Example #6
0
Node* Tree::insert_random(Node* node, unsigned int max_depth, bool halframping)
{
   if( max_depth == 0 )
   {
      return new Node(node, mRandom.rnd(Operators::Piece, Operators::constant), mRandom.rnd(0, 10));
   }
   else
   {
      Node* new_node;
      new_node = get_random_node(halframping, mRandom.rnd(0,100));
      new_node->mNodeParent = node;

      int childs = 0;

      if(new_node->getOperator() == Operators::ifthen4)
      {
         childs = 4;
      }

      if(new_node->getOperator() >= Operators::add && new_node->getOperator() <= Operators::mul)
      {
         childs = 2;
      }

      if(new_node->getOperator() >= Operators::MoveLeft && new_node->getOperator() <= Operators::DoNothing)
      {
         childs = 1;
      }

      for(int i = 0; i < childs; i++)
      {
         new_node->insertChild(insert_random(new_node, max_depth-1, halframping));
      }

      return new_node;
   }
}