int main( int argc, const char * argv[] )
{
  int n_itrs = MAX;
  
  #ifdef SHOW_QS
    mpz_class quoc;
  #endif  

  if( argc > 1 )
    n_itrs = atoi( argv[1] );

  #ifdef TIME
    CPUTimer timer;
    unsigned int runs = 0;
  #endif

  for(int x = -n_itrs; x < n_itrs; ++x)
    for(int y = -n_itrs; y < n_itrs; ++y)
    {
      if( y == x )
        continue;

      Quociente q( x , y ) ;

      for(int k = 1 ; k < n_itrs; ++k)
      {
        std::cout << "x[" << x << "] y[" << y << "] k[" << k << "]\n";

        #ifdef TIME
          timer.start();
        #endif

        #ifdef SHOW_QS
          quoc = q.FindFor( k );
        #else
          q.FindFor( k );
        #endif

        #ifdef TIME
          timer.stop();
          
          runs++;

          std::cout << "\tTrial time: " << timer.getCPUCurrSecs() << "s" << std::endl;
        #endif
        #ifdef SHOW_QS
          std::cout << "\tQuocient: " << quoc << std::endl;
        #endif        

       
      }      
    }

  #ifdef TIME
    std::cout << "\n\nTotal time: " << timer.getCPUTotalSecs() << "s" << std::endl;
    std::cout << "Avg. time : " << timer.getCPUTotalSecs()/runs << "s" << std::endl;
  #endif

  return 0;
}
int main(int argc, const char * argv[])
{
	int numberOfIterations = MAX_K;

	if (argc > 1)
		numberOfIterations = atoi(argv[1]);

	CPUTimer timer;
	int totalRuns = 0;

	cout << "Initializing computation for different values of k:" << endl;
	cout << "Trying to generate rounds for k from 0 to " << numberOfIterations << endl;
	cout << "Printing rounds output for k <= " << MAX_K_TO_PRINT_RESULTS << endl;
	cout << "----------------------------------------------------" << endl;

	timer.start();
	for (int k = 0; k <= numberOfIterations; k++)
	{
		CPUTimer timerPerK;
		int runsPerK=0;
		string output;
		do
		{
			timerPerK.start();
			output = testAlgorithm(k, false);
			timerPerK.stop();
			totalRuns++;
			runsPerK++;
		} while ( timerPerK.getCPUTotalSecs() < 5.0 );

		if (k <= MAX_K_TO_PRINT_RESULTS)
		{
			timerPerK.start();
			output = testAlgorithm(k, true);
			timerPerK.stop();
			totalRuns++;
			runsPerK++;
		}

		cout << endl << "Results for k=" << k << ":" << endl << endl;

		int numTeams, numRounds, numMatches;
		calculateDataSize(k,&numTeams,&numRounds,&numMatches);

		cout << "\t" << numTeams << " teams." << endl;
		cout << "\t" << numRounds << " rounds with " << numTeams / 2 << " matches per round." << endl;
		cout << "\t" << numMatches << " total number of matches." << endl << endl;

		cout << "\t" << runsPerK << " runs in " << timerPerK.getCPUTotalSecs() << "s" << endl;
		cout << "\t" << "Average time per run: " << timerPerK.getCPUTotalSecs() / runsPerK << "s" << endl;
		cout << output;
	}

	timer.stop();

	cout << "Total time: " << timer.getCPUTotalSecs() << "s" << endl;
	cout << "Average time per run : " << timer.getCPUTotalSecs() / (double)totalRuns << "s" << endl;

}
Example #3
0
int main(){
  unsigned int n_lines, max_val, i, ret, a = 0, b = 0, c = 0; 
  bst_ret b_ret;
  char op;
  bst * h = NULL;
   
  scanf(" %u %u", &n_lines, &max_val); 
  
  /* Create the binary tree */
  b_ret = bst_create(&h, n_lines);
  if(b_ret == bst_NoMem){
    printf("ERROR: No memory to create bst tree!\n");
    printf("\t\tSize: %u\n", n_lines);
    exit(1);
  }

  /* Intiatializing time variables */
  insTime.reset();
  searchTime.reset();
  remTime.reset();
  
  /* Read the input file */
  for(i = 0; i < n_lines; i++){
    scanf(" %c %*d %[^\n]", &op, set);
	
    switch( op ){
      /* Insertion */
      case 'i':
        ret = insert(h, set);
        
        #ifdef _LOG
          if( ret  == OP_OK )
            printf("i   OK  %s\n", set);
          else if( ret == PREV_INSERTED )
            printf("i PREV  %s\n", set);
          else if( ret == BST_FULL) {
            printf("ERROR: bst if full!\n\tcould not insert %s\n", set);
            exit( 1 );
          }
        #endif

        a++;

      break;
      /* Search */
      case 'b':
        ret = search(h, set);
        
        #ifdef _LOG
          if( ret == OP_OK )
            printf("b  FND  %s\n", set);
          else
            printf("b ~FND  %s\n", set);
        #endif
        
        b++;

      break;
      /* Removal */
      case 'r':
        ret = _delete(h, set); 
        #ifdef _LOG
          if( ret == OP_OK )
            printf("r   OK  %s\n", set);
          else
            printf("r ~FND  %s\n", set);
        #endif

        c++;

      break;
      /* Wrong code */
      default:
        printf("ERROR: Wrong input at line %u!\n", i+1);
        exit(1);
    } 
  }

  if(a == 0)
    a++;
  if(b == 0)
    b++;
  if(c == 0)
    c++;

  printf("\n\nSTATISTICS\n==========\n\n");
  /* Insertion */
  printf(" Insertion Total Time: %lfs\n\tInsertion Average Time: %.12lfms\n",
         insTime.getCPUTotalSecs(), (insTime.getCPUTotalSecs() / a) * 1000 );
  /* Search */
  printf(" Search Total Time:    %lfs\n\tSearch Average Time:    %.12lfms\n",
         searchTime.getCPUTotalSecs(), (searchTime.getCPUTotalSecs() / b) * 1000 );
  /* Removal */
  printf(" Remove Total Time:    %lfs\n\tRemove Average Time:    %.12lfms\n", 
         remTime.getCPUTotalSecs(), (remTime.getCPUTotalSecs() / c) * 1000 );
  /* Total running time */
  printf("Total Running time:    %lfs\n", ( remTime.getCPUTotalSecs() +  
         searchTime.getCPUTotalSecs() + insTime.getCPUTotalSecs() ) );
 
  bst_destroy(h);
 
  return 0;
}
Example #4
0
/**
 * Reads in the input file, performs the KP-frac linear time strategy on the 
 *   input and displays the optimal solution.
 */
int main (int argc, char * argv[]) {
    if (argc <= 1) {
        std::cout << "Please indicate the name of the input file." << std::endl;
        return -1;
    }

    CPUTimer timer;

    std::cout << "Instance, Avg Running Time (s), Number of Iterations, Value" << std::endl; 

    for (int fileIdx = 1; fileIdx < argc; fileIdx++) {
        parser(argv[fileIdx]);

        Object * temp = new Object[num_elem];

        for (int i = 0; i < num_elem; i++)
            temp[i] = objects[i];

        timer.reset();        

        int it = 0;
        while (timer.getCPUTotalSecs() < 5.0)
        {
            inserted.clear();
            timer.start();
            kpfrac_linear(objects, num_elem, W); 
            timer.stop();      
            it++;
            for(int j = 0; j < num_elem; j++)
                objects[j] = temp[j];
        }

        double media = timer.getCPUTotalSecs() / it;

        std::cout << argv[fileIdx] << "," << media << "," << it; 

        // Loop over the array of objects and display which were inserted and with
        //   what frequency.
        
        double totalValue = 0;

        #ifdef DEBUG
            std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
        #endif

        for (int i = 0, len = inserted.size(); i < len; i++) {
            Object obj = inserted[i];

            #ifdef DEBUG
                std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
                std::cout << obj.elem   << " " << obj.value   << " " 
                          << obj.weight << " " << obj.density << " "
                          << obj.frequency << std::endl;
            #endif

            totalValue  += obj.frequency * obj.value;
        }
        
        std::cout << std::setprecision(15) << "," << totalValue << std::endl;

        delete [] objects;
        inserted.clear();
    }

    return 0;
}