Esempio n. 1
0
void wait_all_plugin_to_finish(GPtrArray *plugin_array)
{
  if (!plugin_array)
    return;

  struct timeval start_time;
  gettimeofday(&start_time, NULL);

  for (int i=0; i < plugin_array->len; i++)
    {
      PluginInfo *plugin = g_ptr_array_index(plugin_array,i);
      if (!plugin)
        continue;

      while (plugin->get_thread_count() > 0)
        {
          g_usleep(500*1000);
          print_statistic(&start_time);
        }
    }

  /* print final statistic: */
  print_statistic(&start_time);
  unsigned long count = sent_messages_num;
  struct timeval now;
  gettimeofday(&now, NULL);
  double total_runtime_sec = time_val_diff_in_sec(&now, &start_time);
  if (total_runtime_sec > 0 && count > 0)
    fprintf(stderr,
            "average rate = %.2lf msg/sec, count=%ld, time=%g, (average) msg size=%"G_GINT64_FORMAT", bandwidth=%.2f kB/sec\n",
            (double)count/total_runtime_sec,
            count,
            total_runtime_sec,
            (gint64)raw_message_length/count,
            (double)raw_message_length/(total_runtime_sec*1024) );
  else
    fprintf(stderr, "Total runtime = %g, count = %ld\n",total_runtime_sec, count);
}
Esempio n. 2
0
int main(int argc, char **argv) {
	int opt;

	if (argc < 2) {
		printf("Please enter correct file name\n");
		return 0;
	}
	getopt_init();

	while (-1 != (opt = getopt(argc - 1, argv, "nh"))) {
		switch (opt) {
		case '?':
			printf("Invalid option `-%c'\n", optopt);
			/* FALLTHROUGH */
			argc = 0;
			break;
		case 'h':
			print_usage();
			return 0;
		default:
			return -EINVAL;
		}
	}

	if (argc < 2) {
		print_usage();
		return 0;
	}

	if (-1 == stat(argv[argc - 1], &filestat)) {
		return -errno;
	}

	print_statistic(&filestat);

	return 0;
}
Esempio n. 3
0
stResult<TCity> * main_genetic(mySlimTree* SlimTree, TCity * queryObject, stDistance range)
{
	time_t begin, end;

	begin = time(NULL);
	
	srand(time(NULL));
	
	Population * pop = new_population();
	Population * aux_pop = new_empty_population();
	
	infeasible(SlimTree, pop);
	
	set_genotype(pop);
	
	evaluate_fitness(pop, SlimTree, queryObject, range);

	#if DEBUG
	print_population(pop ,"Pop", number_of_gerations);
	#endif

	while( (number_of_gerations < MAX_NUMBER_OF_GERATIONS) && (delta_fitness > 0.0001) )
	{
		number_of_gerations++;
		#if DEBUG
		cout << "Number of Gerations: "<< number_of_gerations << endl;
		#endif
		selection_by_tournament(pop, aux_pop);
		#if DEBUG
		cout << "Torneio" << endl;
		#endif
		crossover_uniform(aux_pop);
		#if DEBUG
		cout << "Crossover Uniforme" << endl;
		#endif
		mutation(aux_pop);
		#if DEBUG
		cout << "Mutação" << endl;
		#endif
		set_phenotype(aux_pop);
		#if DEBUG
		cout << "Fenotipo" << endl;
		#endif
		infeasible(SlimTree, aux_pop);
		#if DEBUG
		cout << "Infactibilidade" << endl;
		#endif
		set_genotype(aux_pop);
		#if DEBUG
		cout << "Fenotipo" << endl;
		#endif
		copy_population(aux_pop, pop);
		#if DEBUG
		cout << "Copiar aux pop" << endl;
		#endif
		evaluate_fitness(pop, SlimTree, queryObject, range);
		#if DEBUG
		cout << "Fitness" << endl;
		#endif
		
		old_media_of_fitness = media_of_fitness;
		media_of_fitness = get_media_of_population(pop);
		delta_fitness = fabs(media_of_fitness - old_media_of_fitness);
	}

	end = time(NULL);
	
	#if DEBUG
	print_population(pop, "PopulatioN", number_of_gerations);
	
	print_statistic(pop, begin, end);
	#endif
}