Exemplo n.º 1
0
DWORD WINAPI ExtractAndSendThreadEntry(LPVOID lpParam) 
{
	TThreadData* pTDat = (TThreadData*)lpParam;
	//uint8_T* TSinglePart = pTDat->TSinglePart;
	uint8_T* Tvec = pTDat->Tvec;
	uint32_T* BoundBox = pTDat->BoundBox;
	const uint32_T d = pTDat->d;
	//uint8_T* RSinglePart = pTDat->RSinglePart;
	uint8_T* Rvec = pTDat->Rvec;
	uint32_T* b_DSPResponsibilityBox = pTDat->b_DSPResponsibilityBox;
	uint32_T b_i = pTDat->b_i;
	CHPRPCRequestStoreImg* pRequest = pTDat->pRequest;

	//Extract partial image (places the extracted lines into the HPRPC command buffer. In case of a PCIe transfer directly to the buffers of the non-paged kernel memory used for DMA.)
	CBufferedWriter& BufferedWriter=pRequest->GetHPRPCConnection().GetBufferedWriter();
	extract(Tvec, BoundBox, d, BufferedWriter);
	//Note: We could initiate the sending and start the pyramid generation here allready.
	extract(Rvec, b_DSPResponsibilityBox, d, BufferedWriter);

	//record duration
	pTDat->ExtractFinishedWCTime = get_wall_time();
	pTDat->ExtractFinishedCPUTime = get_cpu_time();
	g_lastImageExtractor = pTDat;	//last thread wins

    //Start sending the data buffer to the target DSP (async, header and image data)
	matlab_c_sendToTarget(b_i, pRequest);

	//Remember completion time (for performance analysis)
	pTDat->SndStartdWCTime = get_wall_time();
	pTDat->SndStartdCPUTime = get_cpu_time();
	g_lastPCIeSender = pTDat;	//last thread wins
	
	return 0;
}
Exemplo n.º 2
0
/*
 * Test: n = size of the counter, t = timeout value
 */
static void test_timeout(uint32_t *c, uint32_t n, uint32_t timeout) {
  double start, end;

  printf("---> test: size = %"PRIu32", timeout = %"PRIu32" s\n", n, timeout);
  fflush(stdout);
  wrapper.interrupted  = false;
  start_timeout(timeout, handler, &wrapper);
  start = get_cpu_time();
  loop(c, n);
  clear_timeout();
  end = get_cpu_time();
  printf("     cpu time = %.2f s\n", end - start);
  fflush(stdout);
  if (wrapper.interrupted) {
    printf("     interrupted at: ");
    show_counter(c, n);
    printf("\n");
    fflush(stdout);
  } else {
    printf("     completed: ");
    show_counter(c, n);
    printf("\n");
    fflush(stdout);
  }
}
Exemplo n.º 3
0
Arquivo: lock.c Projeto: avagin/ploop
static int do_lock(const char *fname, unsigned int timeout)
{
	int fd, r, _errno;
	timer_t tid;
	clock_t end = 0;
	struct sigaction osa;
	struct sigaction sa = {
			.sa_handler = timer_handler,
		};

	if ((fd = open(fname, O_RDWR)) == -1) {
		ploop_err(errno, "Can't open lock file %s", fname);
		return -1;
	}

	/* Set FD_CLOEXEC explicitly */
	fcntl(fd, F_SETFD, FD_CLOEXEC);

	if (timeout) {
		end = get_cpu_time();
		if (end == (clock_t)-1)
			goto err;
		end += SEC_TO_NSEC(timeout);
		sigaction(SIGRTMIN, &sa, &osa);
		if (set_timer(&tid, timeout))
			goto err;
	}
	while ((r = flock(fd, LOCK_EX)) == -1) {
		_errno = errno;
		if (_errno != EINTR)
			break;
		if (timeout == 0 || get_cpu_time() < end)
			continue;
		_errno = EAGAIN;
		break;
	}
	if (timeout) {
		timer_delete(tid);
		sigaction(SIGRTMIN, &osa, NULL);
	}
	if (r != 0) {
		if (_errno == EAGAIN) {
			ploop_err(_errno, "The %s is locked", fname);
			goto err;
		} else {
			ploop_err(_errno, "Error in flock(%s)", fname);
			goto err;
		}
	}
	return fd;

err:
	close(fd);
	return -1;
}
Exemplo n.º 4
0
void Run(std::string iArgument1, std::string iArgument2)
{
  if (iArgument2=="GeneralStats")
    GeneralStats(iArgument1);
  else if (iArgument2=="")
  {
    std::string Instance = iArgument1;
    int PopSize = 16;
    int MaxHamming = 3;
    int RCLLength = 3;
    double MutationRate = 0.1;
    double TransmitionRate = 0.2;
    int MaxNbGenerations = 200;
    double InfMeanDiff = 0.002;
    Traces ExecTraces;
    ExecTraces.Initialize(PopSize, MaxNbGenerations);
  
    GRASP myGRASP(Instance, PopSize, MaxHamming, RCLLength, MutationRate, TransmitionRate, MaxNbGenerations, InfMeanDiff, &ExecTraces);
    ExecTraces._BeginPopBuilt_UserTime = get_wall_time();
    ExecTraces._BeginPopBuilt_CPUTime = get_cpu_time();
    myGRASP.Construction();
    ExecTraces._EndPopBuilt_CPUTime = get_cpu_time();
    ExecTraces._EndPopBuilt_UserTime = get_wall_time();

    Localisation * TmpBestLoc = myGRASP.GetBestLocalisation();
    if (TmpBestLoc)
      ExecTraces._GRASPBestCost = TmpBestLoc->GetLocalisationCost();

    ExecTraces._BeginGenetic_UserTime = get_wall_time();
    ExecTraces._BeginGenetic_CPUTime = get_cpu_time();
    myGRASP.GeneticAlgorithm();
    ExecTraces._EndGenetic_CPUTime = get_cpu_time();
    ExecTraces._EndGenetic_UserTime = get_wall_time();

    TmpBestLoc = myGRASP.GetBestLocalisation();
    if (TmpBestLoc)
      ExecTraces._GeneticBestCost = TmpBestLoc->GetLocalisationCost();

    std::cout << "===== Parameters\n";
    std::cout << "Size of the population: " << PopSize << "\n";
    std::cout << "Maximal Hamming Distance: " << MaxHamming << "\n";
    std::cout << "Length of RCl (restricted candidates list): " << RCLLength << "\n";
    std::cout << "Mutation rate: " << MutationRate << "\n";
    std::cout << "Transmition rate: " << TransmitionRate << "\n";
    std::cout << "Maximal number of generation in genetic algorithm: " << MaxNbGenerations << "\n";
    std::cout << "Mean difference of the costs of the population from which stop: " << InfMeanDiff << "\n";
    std::cout << "\n";
    std::cout << "===== Result of the metaheuristic\n";
    myGRASP.PrintBestLocalisation();
    ExecTraces.PostTreatment();

    TmpBestLoc = 0;
  }
}
Exemplo n.º 5
0
/* _lib7_Time_gettime : Void -> (int32.Int * int * int32.Int * int * int32.Int * int)
 *
 * Return this process's CPU time consumption
 * so far, broken down as:
 *     User-mode          seconds and microseconds.
 *     Kernel-mode        seconds and microseconds.
 *     Garbage collection seconds and microseconds.
 * used by this process so far.
 */
lib7_val_t _lib7_Time_gettime (lib7_state_t *lib7_state, lib7_val_t arg)
{
    Time_t		usr;					/* User-mode   time consumption as reported by os.				*/
    Time_t		sys;					/* Kernel-mode time consumption as reported by os.				*/

    lib7_val_t		usr_seconds;
    lib7_val_t		sys_seconds;
    lib7_val_t		gc_seconds;

    lib7_val_t		result;					/* For result 6-vector.								*/

    vproc_state_t	*vsp = lib7_state->lib7_vproc;

								/* On posix: get_cpu_time()	def in   src/runtime/main/unix-timers.c		*/
								/* On win32: get_cpu_time()      def in   src/runtime/main/win32-timers.c	*/
    get_cpu_time (&usr, &sys);

    INT32_ALLOC (lib7_state, usr_seconds, usr.seconds            );
    INT32_ALLOC (lib7_state, sys_seconds, sys.seconds            );
    INT32_ALLOC (lib7_state, gc_seconds,  vsp->vp_gcTime->seconds);

    REC_ALLOC6 (lib7_state, result,
	usr_seconds, INT_CtoLib7(usr.uSeconds),
	sys_seconds, INT_CtoLib7(sys.uSeconds),
	gc_seconds,  INT_CtoLib7(vsp->vp_gcTime->uSeconds)
    );

    return result;
}
Exemplo n.º 6
0
static int
time_msghandler (int m, int c)
{
	if (m == 0)
		printf ("time %llu\n", get_cpu_time ());
	return 0;
}
Exemplo n.º 7
0
int
cm_get_host_stat (T_CM_HOST_STAT * stat, T_CM_ERROR * err_buf)
{
  __int64 kernel, user, idle;
  PERFORMANCE_INFORMATION pi;

  if (get_cpu_time (&kernel, &user, &idle) != 0)
    {
      return 1;
    }

  stat->cpu_kernel = kernel;
  stat->cpu_user = user;
  stat->cpu_idle = idle;
  stat->cpu_iowait = 0;

  memset (&pi, 0, sizeof (pi));
  pi.cb = sizeof (pi);
  if (!GetPerformanceInfo (&pi, sizeof (pi)))
    {
      return 1;
    }

  stat->mem_physical_total = ((__int64) pi.PhysicalTotal) * pi.PageSize;
  stat->mem_physical_free = ((__int64) pi.PhysicalAvailable) * pi.PageSize;
  stat->mem_swap_total = ((__int64) pi.CommitLimit) * pi.PageSize;
  stat->mem_swap_free =
    ((__int64) (pi.CommitLimit - pi.CommitTotal)) * pi.PageSize;

  return 0;
}
Exemplo n.º 8
0
/*
 * Speed test: sequential search
 */
static void speed_test_sequential_search(int32_t *a, uint32_t n) {
  double start, done;
  uint32_t i;
  int32_t x, top;

  top = 5 * n + 12;
  printf("Sequential search: size = %"PRIu32"   (10000*%"PRId32" searches)\n", n, top+12);
  start = get_cpu_time();
  for (i=0; i<10000; i++) {
    for (x = -12; x<top; x++) {
      (void) sequential_search(a, n, x);
    }
  }
  done = get_cpu_time();
  printf("Total time: %.4f\n", done - start);
}
Exemplo n.º 9
0
enum piglit_result
piglit_display(void)
{
	GLint64 t1, t2;
	GLint64 query_overhead, get_overhead, tolerance;
	GLuint q;

	glGenQueries(1, &q);

	/* this creates the query in the driver */
	get_gpu_time_via_query(q);

	/* compute a reasonable tolerance based on driver overhead */
	t1 = get_cpu_time();
	get_gpu_time_via_query(q);
	query_overhead = get_cpu_time() - t1;

	t1 = get_cpu_time();
	get_gpu_time_via_get(q);
	get_overhead = get_cpu_time() - t1;

	printf("glGet overhead: %llu us\n", (unsigned long long) get_overhead / 1000);
	printf("glQuery overhead: %llu us\n", (unsigned long long) query_overhead / 1000);

	/* minimum tolerance is 3 ms */
	tolerance = query_overhead + get_overhead + 3000000;

	/* do testing */
	puts("Test: first glQuery, then glGet");
	t1 = get_gpu_time_via_query(q);
	t2 = get_gpu_time_via_get(q);
	validate_times(t1, t2, tolerance);

	usleep(10000);

	puts("Test: first glGet, then glQuery");
	t1 = get_gpu_time_via_get(q);
	t2 = get_gpu_time_via_query(q);
	validate_times(t1, t2, tolerance);

	glDeleteQueries(1, &q);

	return PIGLIT_PASS;
}
Exemplo n.º 10
0
/*
 * Call solver on file given as an argument
 */
int main(int argc, char *argv[]) {
  int resu;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s <input file>\n", argv[0]);
    exit(1);
  }

  resu = build_instance(argv[1], &solver);
  if (resu < 0) {
    exit(2);
  }

  construction_time = get_cpu_time();
  print_problem_size(stdout, &solver, argv[1], construction_time);
  init_handler();
  sat_solve(&solver, NULL, true);
  search_time = get_cpu_time() - construction_time;
  print_results(&solver, construction_time, search_time);

  delete_smt_core(&solver);

  return 0;
}
Exemplo n.º 11
0
/* Show CPU usage - experimental */
static int cmd_show_cpu_usage(hypervisor_conn_t *conn,int argc,char *argv[])
{
   vm_instance_t *vm;
   double usage;

   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
      return(-1);

   usage = get_cpu_time();
   if (usage == -1)
      return(-1);
   hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u", (unsigned long)usage);

   vm_release(vm);
   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
   return(0);
}
Exemplo n.º 12
0
/* _lib7_Time_gettime : Void -> (int32.Int * int * int32.Int * int * int32.Int * int)
 *
 * Return the total CPU time, system time and garbage collection time used by this
 * process so far.
 */
lib7_val_t _lib7_Time_gettime (lib7_state_t *lib7_state, lib7_val_t arg)
{
    Time_t		t, s;
    lib7_val_t		tSec, sSec, gcSec, res;
    vproc_state_t	*vsp = lib7_state->lib7_vproc;

    get_cpu_time (&t, &s);

    INT32_ALLOC (lib7_state, tSec, t.seconds);
    INT32_ALLOC (lib7_state, sSec, s.seconds);
    INT32_ALLOC (lib7_state, gcSec, vsp->vp_gcTime->seconds);
    REC_ALLOC6 (lib7_state, res,
	tSec, INT_CtoLib7(t.uSeconds),
	sSec, INT_CtoLib7(s.uSeconds),
	gcSec, INT_CtoLib7(vsp->vp_gcTime->uSeconds));

    return res;

} /* end of _lib7_Time_gettime */
Exemplo n.º 13
0
//{{{ int main(int argc, char** argv)
int main(int argc, char** argv)
{
	//read the first argument to set the function.
	if(argc < 3) show_help_short(argv);
	long t_begin=get_cpu_time();
	int randseed=int(time(NULL));
	ZRANDOMv3 rg(randseed);
	int nsample=10;
	if(argc>=4) nsample=atoi(argv[3]);
//	cout<<"nsample="<<nsample<<endl;
	
	ifstream fa(argv[1]);
	ifstream fb(argv[2]);
	assert(fa.good()&&fb.good()&&"I can not open the file that contains the partition.");

	vector <string> pas;//partition a in string
	vector <string> pbs;//partition b in string
	string tmpstr;
	while(fa >> tmpstr) pas.push_back(tmpstr);
	while(fb >> tmpstr) pbs.push_back(tmpstr);
	assert(pas.size() == pbs.size() && "Two partitions have different number of nodes !");

	vector <int> pa;//partition a in number
	vector <int> pb;//partition b in number
	int qa=ps2p(pas,pa);
	int qb=ps2p(pbs,pb);

	double the_nmi=0;
	bool agtb=true; //qa is greater than qb
	if(qa<qb) agtb=false;
	if(agtb) the_nmi=compute_nmi(pa,pb);
	else the_nmi=compute_rnmi(pb,pa);
	cout<<the_nmi<<endl;
//	cout<<"RNMI="<<the_nmi-tot_nmi<<endl;
//	cout<<"time used: "<<(get_cpu_time()-t_begin)/1000.0<<" seconds."<<endl;
}
/*
 * Parse options, read polygons, convert to turning reps, initialize
 * everything, compute the answers, and print the answers.  Do all
 * this in a loop until all the polygons are gone.
 */
int main(int argc, char** argv)
{
    int update_p, precise_p, n_repeats, i;
    TURN_REP trf, trg;
    TURN_REP* f;
    TURN_REP* g;
    std::vector<OPENCV_POINT> pf, pg;
    EVENT_REC e;
    double ht0, slope, alpha, theta_star, metric2, metric, ht0_err, slope_err;

#ifdef CPU_TIME
    struct tms cpu_time;
    clock_t cpu_start_time;
    int elapsed_ms;
    int total_elapsed_ms = 0;
#define start_cpu_time() \
      (times(&cpu_time), cpu_start_time = cpu_time.tms_utime)
#define get_cpu_time() \
      (times(&cpu_time), (cpu_time.tms_utime - cpu_start_time)*1000/HZ)
#endif

    precise_p = 0;
    update_p = 1;
    n_repeats = 1;
    while(--argc)
    {
        ++argv;
        if (argv[0][0] == '-' && argv[0][1] != '\0')
            switch(argv[0][1]) {
                case 'p':
                    precise_p = 1;
                    break;
                case 'n':
                    update_p = 0;
                    break;
		case 'r':
		    if (sscanf(&argv[0][2], "%d", &i) == 1)
		      n_repeats = i;
		    break;
                default:
                    fprintf(stderr, "sim: unknown option\n");
                    return 1;
            }
    }
    if (read_poly(pg)) //reference polygon is pg
    {
        poly_to_turn_rep(pg, &trg);
        g = &trg;
        while (read_poly(pf))
        {
            poly_to_turn_rep(pf, &trf);
	    f = &trf;
#ifdef CPU_TIME
	    start_cpu_time();
#endif
	    /* Performance measure repeat loop. */
	    for (i = 0; i < n_repeats; ++i)
            {

              init_vals(f, g, &ht0, &slope, &alpha);
              init_events(f, g);
              metric2 = h_t0min(f, g,
			        ht0, slope, alpha,
                                update_p ? reinit_interval(f, g) : 0,
                	        &theta_star, &e, &ht0_err, &slope_err);
	    }
#ifdef CPU_TIME
	    elapsed_ms = get_cpu_time();
	    total_elapsed_ms += elapsed_ms;
#endif
            /*
             * Fixups: The value of metric2 can be a tiny
             * negative number for an exact match.  Call it 0.
             * Theta_star can be over 360 or under -360 because we
             * handle t=0 events at t=1. Normalize to [-PI,PI).
             */
            metric = metric2 > 0 ? sqrt(metric2) : 0;
            printf(precise_p ? "%.18lg %.18lg %d %d %lg %lg" : "%lg %lg %d %d %lg %lg",
                   metric, turn(theta_star, 0)*180/M_PI,
                   tr_i(f, e.fi), tr_i(g, e.gi), ht0_err, slope_err);

#ifdef CPU_TIME
	    printf(" %d\n", (elapsed_ms + (n_repeats/2))/n_repeats);
#else
	    printf("\n");
#endif

        }
    }

#ifdef CPU_TIME
    printf("total user time: %d ms\n", (total_elapsed_ms + (n_repeats/2))/n_repeats);
#endif

    return 0;
}
Exemplo n.º 15
0
void Timer::reset(double init_time)
{
   time_start   = get_cpu_time();
   time_end     = time_start;
   time_elapsed = init_time;
}
Exemplo n.º 16
0
double Timer::stop()
{
   time_end = get_cpu_time();
   time_elapsed += time_end - time_start;
   return (double) time_end;
}
Exemplo n.º 17
0
double Timer::start()
{
   return (double) (time_start = get_cpu_time());
}
Exemplo n.º 18
0
static void compare(int32_t *a, int32_t n) {
  int32_t *b;
  int32_t i;
  double runtime;

  b = (int32_t *) safe_malloc((n + 1) * sizeof(int32_t));

  runtime = get_cpu_time();
  for (i=0; i<5000; i++) {
    copy_array(b, a, n);
    insertion_sort(b, n);
  }
  runtime = get_cpu_time() - runtime;
  //    printf("isort: %.3f s\n", runtime);
  itime += runtime;

  runtime = get_cpu_time();
  for (i=0; i<5000; i++) {
    copy_array(b, a, n);
    sort(b, n);
  }
  runtime = get_cpu_time() - runtime;
  //  printf("sort1: %.3f s\n", runtime);
  time1 += runtime;

  runtime = get_cpu_time();
  for (i=0; i<5000; i++) {
    copy_array(b, a, n);
    sort2(b, n);
  }
  runtime = get_cpu_time() - runtime;
  //  printf("sort2: %.3f s\n", runtime);
  time2 += runtime;

  runtime = get_cpu_time();
  for (i=0; i<5000; i++) {
    copy_array(b, a, n);
    sort3(b, n);
  }
  runtime = get_cpu_time() - runtime;
  //  printf("sort3: %.3f s\n", runtime);
  time3 += runtime;

  runtime = get_cpu_time();
  for (i=0; i<5000; i++) {
    copy_array(b, a, n);
    sort4(b, n);
  }
  runtime = get_cpu_time() - runtime;
  //  printf("sort4: %.3f s\n\n", runtime);
  time4 += runtime;

  runtime = get_cpu_time();
  for (i=0; i<5000; i++) {
    copy_array(b, a, n);
    sort4var(b, n);
  }
  runtime = get_cpu_time() - runtime;
  //  printf("sort4var: %.3f s\n\n", runtime);
  time4var += runtime;

  runtime = get_cpu_time();
  for (i=0; i<5000; i++) {
    copy_array(b, a, n);
    sort4var2(b, n);
  }
  runtime = get_cpu_time() - runtime;
  //  printf("sort4var2: %.3f s\n\n", runtime);
  time4var2 += runtime;

  safe_free(b);
}
Exemplo n.º 19
0
void cputime_(float * ttt)
{
	double tt = get_cpu_time();
	*ttt = (float)tt;
	return;
}
Exemplo n.º 20
0
void TypicalTimeOfLocalisationBuilt(std::string iInstance)
{
  // Creation of the instance
  Testio Instance(iInstance);

  // Time needed to build the localisation
  double ConstructionUserTime =  0;
  double ConstructionCPUTime = 0;
  // Time to explore a neighbourhood for Hamming distance equal to 1
  double Exploration1UserTime = 0;
  double Exploration1CPUTime = 0;
  // Time to explore a neighbourhood for Hamming distance equal to 2
  double Exploration2UserTime = 0;
  double Exploration2CPUTime = 0;
  // Time to explore a neighbourhood for Hamming distance equal to 3
  double Exploration3UserTime = 0;
  double Exploration3CPUTime = 0;
  // Time to execute a complete local search
  double LocalSearchUserTime = 0;
  double LocalSearchCPUTime = 0;


  int NbIter = 10;
  int i;
  for (i = 0; i < NbIter; i++)
  {
    Localisation myLoc(Instance, 0, 0);

    // Construction of the localisation
    double BeginUserTime =  get_wall_time();
    double BeginCPUTime = get_cpu_time();
    myLoc.Construction(3);
    double EndCPUTime = get_cpu_time();
    double EndUserTime =  get_wall_time();
    ConstructionUserTime = ConstructionUserTime + EndUserTime - BeginUserTime;
    ConstructionCPUTime = ConstructionCPUTime + EndCPUTime - BeginCPUTime;

    // Exploration of a neighbourhood for Hamming distance equal to 1
    BeginUserTime =  get_wall_time();
    BeginCPUTime = get_cpu_time();
    myLoc.NeighbourhoodSearch(1);
    EndCPUTime = get_cpu_time();
    EndUserTime =  get_wall_time();
    Exploration1UserTime = Exploration1UserTime + EndUserTime - BeginUserTime;
    Exploration1CPUTime = Exploration1CPUTime + EndCPUTime - BeginCPUTime;

    // Exploration of a neighbourhood for Hamming distance equal to 1
    BeginUserTime =  get_wall_time();
    BeginCPUTime = get_cpu_time();
    myLoc.NeighbourhoodSearch(2);
    EndCPUTime = get_cpu_time();
    EndUserTime =  get_wall_time();
    Exploration2UserTime = Exploration2UserTime + EndUserTime - BeginUserTime;
    Exploration2CPUTime = Exploration2CPUTime + EndCPUTime - BeginCPUTime;

    // Exploration of a neighbourhood for Hamming distance equal to 1
    BeginUserTime =  get_wall_time();
    BeginCPUTime = get_cpu_time();
    myLoc.NeighbourhoodSearch(3);
    EndCPUTime = get_cpu_time();
    EndUserTime =  get_wall_time();
    Exploration3UserTime = Exploration3UserTime + EndUserTime - BeginUserTime;
    Exploration3CPUTime = Exploration3CPUTime + EndCPUTime - BeginCPUTime;
  }
  int NbLocalSearch = 5;
  for (i = 0; i < NbLocalSearch; i++)
  {
    Localisation myLoc(Instance, 0, 0);

    // Construction of the localisation
    myLoc.Construction(3);

    // Computation of a complete local search
    double BeginUserTime =  get_wall_time();
    double BeginCPUTime = get_cpu_time();
    myLoc.LocalSearchAlgorithm(3);
    double EndCPUTime = get_cpu_time();
    double EndUserTime =  get_wall_time();
    LocalSearchUserTime = LocalSearchUserTime + EndUserTime - BeginUserTime;
    LocalSearchCPUTime = LocalSearchCPUTime + EndCPUTime - BeginCPUTime;
  }

  std::cout.precision(4);
  std::cout << "Time needed to build the localisation\n";
  std::cout << "  CPU time : " << ConstructionCPUTime/NbIter << "s\n";
  std::cout << "  User time: " << ConstructionUserTime/NbIter << "s\n";
  std::cout << "Time to explore a neighbourhood for Hamming distance equal to 1\n";
  std::cout << "  CPU time : " << Exploration1CPUTime/NbIter << "s\n";
  std::cout << "  User time: " << Exploration1UserTime/NbIter << "s\n";
  std::cout << "Time to explore a neighbourhood for Hamming distance equal to 2\n";
  std::cout << "  CPU time : " << Exploration2CPUTime/NbIter << "s\n";
  std::cout << "  User time: " << Exploration2UserTime/NbIter << "s\n";
  std::cout << "Time to explore a neighbourhood for Hamming distance equal to 3\n";
  std::cout << "  CPU time : " << Exploration3CPUTime/NbIter << "s\n";
  std::cout << "  User time: " << Exploration3UserTime/NbIter << "s\n";
  std::cout << "Time to execute a complete local search\n";
  std::cout << "  CPU time : " << LocalSearchCPUTime/NbLocalSearch << "s\n";
  std::cout << "  User time: " << LocalSearchUserTime/NbLocalSearch << "s\n";
  std::cout << "\n";
}
Exemplo n.º 21
0
void NonOptimalSolutions(std::string iInstance)
{
  // Optimal values of the instances
  static struct {
    const std::string _TestName;
    double _OptimalValue;
  } aInstance[] = {
    // Test name                    Optimal value
    {"TestCases/Input/cap71.txt",    932615.75   },
    {"TestCases/Input/cap72.txt",    977799.4    },
    {"TestCases/Input/cap73.txt",   1010641.45   },
    {"TestCases/Input/cap74.txt",   1034976.975  },
    {"TestCases/Input/cap101.txt",   796648.4375 },
    {"TestCases/Input/cap102.txt",   854704.2    },
    {"TestCases/Input/cap103.txt",   893782.1125 },
    {"TestCases/Input/cap104.txt",   928941.75   },
    {"TestCases/Input/cap131.txt",   793439.5625 },
    {"TestCases/Input/cap132.txt",   851495.325  },
    {"TestCases/Input/cap133.txt",   893076.7125 },
    {"TestCases/Input/cap134.txt",   928941.75   },
    {"TestCases/Input/capa.txt",   17156454.4783 },
    {"TestCases/Input/capb.txt",   12979071.58143},
    {"TestCases/Input/capc.txt",   11505594.32878}
  };
  int IdxTest;
  for (IdxTest = 0; IdxTest < 15; IdxTest++) {
    if (aInstance[IdxTest]._TestName == iInstance)
      break;
  }
  if (IdxTest==15) {
    std::cout << "The optimal value of the problem is unknown. Fill code with it!\n";
    return;
  }

  int NbTest = 100;
  // Array of the found optimal costs
  double * aOptimalCosts = new double[NbTest];
  memset(aOptimalCosts, 0, NbTest*sizeof(double));

  // Time to perform algorithm
  double UserTime = 0;
  double CPUTime = 0;


  // Parameters of the algorithm
  std::string Instance = iInstance;
  int PopSize = 16;
  int MaxHamming = 3;
  int RCLLength = 3;
  double MutationRate = 0.1;
  double TransmitionRate = 0.2;
  int MaxNbGenerations = 200;
  double InfMeanDiff = 0.002;

  int i;
  for (i = 0; i < NbTest; i++)
  {
    GRASP myGRASP(Instance, PopSize, MaxHamming, RCLLength, MutationRate, TransmitionRate, MaxNbGenerations, InfMeanDiff, 0);
    double BeginUserTime =  get_wall_time();
    double BeginCPUTime = get_cpu_time();
    myGRASP.Construction();
    myGRASP.GeneticAlgorithm();
    double EndCPUTime = get_cpu_time();
    double EndUserTime =  get_wall_time();
    Localisation * BestLoc = myGRASP.GetBestLocalisation();
    if (BestLoc)
      aOptimalCosts[i] = BestLoc->GetLocalisationCost();

    UserTime = UserTime + EndUserTime - BeginUserTime;
    CPUTime = CPUTime + EndCPUTime - BeginCPUTime;
  }

  int NbNonOptimal = 0;
  double MeanDiff = 0;
  for (i = 0; i < NbTest; i++) {
    double diff = fabs(aOptimalCosts[i]-aInstance[IdxTest]._OptimalValue);
    if ( diff > EPSILON )
    {
      NbNonOptimal++;
      MeanDiff+=diff;
    }
  }

  std::cout.precision(3);
  std::cout << "Percentage of returned non-optimal solutions: " << NbNonOptimal*100./NbTest << "%\n";
  std::cout.precision(4);
  if (NbNonOptimal > 0)
    MeanDiff = 100 * MeanDiff / (NbNonOptimal*aInstance[IdxTest]._OptimalValue);
  std::cout << "Averge mean difference of non-optimal solutions with optimum: " << MeanDiff << "%\n";
  std::cout << "\n";

  std::cout.precision(4);
  std::cout << "Average time to perform GRASP algorithm:\n";
  std::cout << "  CPU time : " << CPUTime/NbTest << "s\n";
  std::cout << "  User time: " << UserTime/NbTest << "s\n";
  std::cout << "\n";

  if (aOptimalCosts)
    delete [] aOptimalCosts; aOptimalCosts = 0;
}
Exemplo n.º 22
0
int main(int argc, char *argv[]) {
  char *filename;
  int32_t code;
  double time, mem_used;

  if (argc > 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(YICES_EXIT_USAGE);
  }

  if (argc == 2) {
    // read from file
    interactive = false;
    filename = argv[1];
    if (init_smt2_file_lexer(&lexer, filename) < 0) {
      perror(filename);
      exit(YICES_EXIT_FILE_NOT_FOUND);
    }
  } else {
    // read from stdin
    interactive = true;
    init_smt2_stdin_lexer(&lexer);
  }

  yices_init();
  init_smt2(true, 0, interactive);
  init_smt2_tstack(&stack);
  init_parser(&parser, &lexer, &stack);

  // disable SMT2_CHECK_SAT/PUSH/POP/GET_VALUE
  tstack_add_op(&stack, SMT2_CHECK_SAT, false, eval_smt2_skip, check_smt2_skip);
  tstack_add_op(&stack, SMT2_PUSH, false, eval_smt2_skip, check_smt2_skip);
  tstack_add_op(&stack, SMT2_POP, false, eval_smt2_skip, check_smt2_skip);
  tstack_add_op(&stack, SMT2_GET_VALUE, false, eval_smt2_skip, check_smt2_skip);

  //  smt2_set_verbosity(100);

  while (smt2_active()) {
    if (interactive) {
      fputs("smt2> ", stdout);
      fflush(stdout);
    }
    code = parse_smt2_command(&parser);
    if (code < 0) {
      // syntax error
      if (interactive) {
	flush_lexer(&lexer);
      } else {
	break; // exit
      }
    }
    fflush(stdout);
  }

  // statistics
  time = get_cpu_time();
  mem_used = mem_size() / (1024 * 1024);
  printf("\nRun time: %.4f s\n", time);
  printf("Memory used: %.2f MB\n\n", mem_used);
  fflush(stdout);

  delete_parser(&parser);
  close_lexer(&lexer);
  delete_tstack(&stack);
  delete_smt2();
  yices_exit();

  return YICES_EXIT_SUCCESS;
}
Exemplo n.º 23
0
/*------------------------------------------------------------------------*/
static void
search_coeffs(msieve_obj *obj, poly_search_t *poly, 
		bounds_t *bounds, uint32 deadline)
{
	mpz_t curr_high_coeff;
	double dn = mpz_get_d(poly->N);
	uint32 digits = mpz_sizeinbase(poly->N, 10);
	double start_time = get_cpu_time();
	uint32 deadline_per_coeff = 800;
	uint32 batch_size = (poly->degree == 5) ? POLY_BATCH_SIZE : 1;

	if (digits <= 100)
		deadline_per_coeff = 5;
	else if (digits <= 105)
		deadline_per_coeff = 20;
	else if (digits <= 110)
		deadline_per_coeff = 30;
	else if (digits <= 120)
		deadline_per_coeff = 50;
	else if (digits <= 130)
		deadline_per_coeff = 100;
	else if (digits <= 140)
		deadline_per_coeff = 200;
	else if (digits <= 150)
		deadline_per_coeff = 400;
	printf("deadline: %u seconds per coefficient\n", deadline_per_coeff);

	mpz_init(curr_high_coeff);
	mpz_fdiv_q_ui(curr_high_coeff, 
			bounds->gmp_high_coeff_begin, 
			(mp_limb_t)MULTIPLIER);
	mpz_mul_ui(curr_high_coeff, curr_high_coeff, 
			(mp_limb_t)MULTIPLIER);
	if (mpz_cmp(curr_high_coeff, 
			bounds->gmp_high_coeff_begin) < 0) {
		mpz_add_ui(curr_high_coeff, curr_high_coeff, 
				(mp_limb_t)MULTIPLIER);
	}

	poly->num_poly = 0;

	while (1) {
		curr_poly_t *c = poly->batch + poly->num_poly;

		if (mpz_cmp(curr_high_coeff, 
					bounds->gmp_high_coeff_end) > 0) {

			if (poly->num_poly > 0) {
				search_coeffs_core(obj, poly, 
					   deadline_per_coeff);
			}
			break;
		}

		stage1_bounds_update(bounds, dn, 
					mpz_get_d(curr_high_coeff),
					poly->degree);

		mpz_set(c->high_coeff, curr_high_coeff);
		c->p_size_max = bounds->p_size_max;
		c->coeff_max = bounds->coeff_max;

		if (++poly->num_poly == batch_size) {
			search_coeffs_core(obj, poly, 
					deadline_per_coeff);

			if (obj->flags & MSIEVE_FLAG_STOP_SIEVING)
				break;

			if (deadline) {
				double curr_time = get_cpu_time();
				double elapsed = curr_time - start_time;

				if (elapsed > deadline)
					break;
			}
			poly->num_poly = 0;
		}

		mpz_add_ui(curr_high_coeff, curr_high_coeff, 
				(mp_limb_t)MULTIPLIER);
	}

	mpz_clear(curr_high_coeff);
}
Exemplo n.º 24
0
void
cpu_stop_internal(void)
{
  get_cpu_time(lib_end_count);
}
Exemplo n.º 25
0
void
cpu_start_internal(void)
{
  get_cpu_time(lib_start_count);
}
Exemplo n.º 26
0
void *ref1(void*){
	int target_fps = 0;
	int target_Ug = 0;
	int target_Uc = 0;
	
	start_sampling = 1;
	int fps;
	
	int Ug;
	static unsigned long long Ug_bp,Ug_tp;
	get_gpu_time(&Ug_bp,&Ug_tp);
	
	int Uc;
	static unsigned long long Uc_bp,Uc_tp;
	get_cpu_time(4,&Uc_bp,&Uc_tp);
	
	int Fc,Fg;
	
	while(true){
		if(game == -1){sleep(1);start_sampling=1;continue;}
		Fc=get_cpu_freq(0);
		Fg=get_gpu_freq();
		//printf("Sample%d Fc=%d,Fg=%d,Uc=%d,Ug=%d\n",start_sampling,get_cpu_freq(0),get_gpu_freq(),Uc,Ug);
		if(start_sampling == 1){			
			fps = get_fps(binder);			
			Uc = get_cpu_util(4,&Uc_bp,&Uc_tp);
			Ug = get_gpu_util(&Ug_bp,&Ug_tp);			
			printf("Sample%d Fc=%d,Fg=%d,Uc=%d,Ug=%d\n",start_sampling,Fc,Fg,Uc,Ug);			
			if(target_fps < fps)target_fps = fps;
			if(target_Uc < Uc)target_Uc = Uc;
			if(target_Ug < Ug)target_Ug = Ug;		
			
			set_cpu_freq(0,FL[3]);
			set_gpu_freq(GFL[4]);
			start_sampling=2;
			sleep(1);continue;
		}else if(start_sampling == 2){
			fps = get_fps(binder);			
			Uc = get_cpu_util(4,&Uc_bp,&Uc_tp);
			Ug = get_gpu_util(&Ug_bp,&Ug_tp);			
			printf("Sample%d Fc=%d,Fg=%d,Uc=%d,Ug=%d\n",start_sampling,Fc,Fg,Uc,Ug);			
			if(target_fps < fps)target_fps = fps;
			if(target_Uc < Uc)target_Uc = Uc;
			if(target_Ug < Ug)target_Ug = Ug;
			
			set_cpu_freq(0,FL[10]);
			set_gpu_freq(GFL[0]);
			start_sampling=3;
			sleep(1);continue;
		}else if(start_sampling == 3){
			fps = get_fps(binder);			
			Uc = get_cpu_util(4,&Uc_bp,&Uc_tp);
			Ug = get_gpu_util(&Ug_bp,&Ug_tp);			
			printf("Sample%d Fc=%d,Fg=%d,Uc=%d,Ug=%d\n",start_sampling,Fc,Fg,Uc,Ug);			
			if(target_fps < fps)target_fps = fps;
			if(target_Uc < Uc)target_Uc = Uc;
			if(target_Ug < Ug)target_Ug = Ug;
			
			set_cpu_freq(0,FL[10]);
			set_gpu_freq(GFL[4]);
			start_sampling=4;
			sleep(1);continue;
		}else if(start_sampling == 4){
			printf("Sample%d Fc=%d,Fg=%d\n",start_sampling,get_cpu_freq(0),get_gpu_freq());
			printf("Q : %d , Ug : %d , Uc : %d\n",target_fps,target_Ug,target_Uc);			
			start_sampling=5;
		}
		
		fps = get_fps(binder);
		int fps_dev = (target_fps - fps)*100/target_fps;
		
		static int FL_point = freq_level-2;
		static int pre_FL = FL_point;
		static int GFL_point = gpu_freq_level-1;
		static int pre_GFL = GFL_point;
		
		int CPU_Sensitive = 1;
		
		int Fc_adj = 0;
		int Fg_adj = 0;
		int Ug_adj = 0;
		if(fps_dev > 10){
			//printf("UP! %d %d %d\n",fps,target_fps,fps_dev);
			Uc = get_cpu_util(4,&Uc_bp,&Uc_tp);
			Ug = get_gpu_util(&Ug_bp,&Ug_tp);
			
			int fps_dif = (target_fps - fps);
			int Uc_dev = (target_Uc - Uc)*100/target_Uc;
			int Ug_dev = (target_Ug - Ug)*100/target_Ug;
			
			
			if(CPU_Sensitive){
				//CPU Sensitive			
				Fc_adj = (double)fps_dif * reciprocal(Coef_Fc2Q[game]) + FL[FL_point];
				Ug_adj = Ug + (double)fps_dif * reciprocal(Coef_Ug2Q[game]);
				if(Ug_adj > target_Ug){
					Fg_adj = (double)(Ug_adj - target_Ug) * -reciprocal(Coef_Fg2Ug[game]) + GFL[GFL_point];
				}
			}else{
				//GPU Sensitive
				Fg_adj = (double)fps_dif * reciprocal(Coef_Fg2Q[game]) + GFL[GFL_point];
				Ug_adj = Ug + (double)fps_dif * reciprocal(Coef_Uc2Q[game]);
				if(Ug_adj > target_Ug){
					Fc_adj = (double)(Ug_adj - target_Ug) * -reciprocal(Coef_Fc2Uc[game]) + FL[FL_point];
				}
			}

			while(FL_point < freq_level && FL[FL_point] < Fc_adj)FL_point++;
			while(GFL_point < gpu_freq_level && GFL[GFL_point] < Fg_adj)GFL_point++;	
				
			
			
			if(FL_point != pre_FL){		
				if(FL_point > freq_level-2){
					FL_point = freq_level-2;
				}else if(FL_point < 2){
					FL_point = 2;
				}		
				pre_FL = FL_point;
				set_cpu_freq(0,FL[FL_point]);			
			}
			if(GFL_point != pre_GFL){			
				if(GFL_point > gpu_freq_level-1){
					GFL_point = gpu_freq_level-1;
				}else if(GFL_point < 0){
					GFL_point = 0;
				}		
				pre_GFL = GFL_point;
				set_gpu_freq(GFL[GFL_point]);			
			}
			
			
		}else if(fps_dev <= 10){			
			//printf("DOWN! POWER SAVE %d %d %d\n",fps,target_fps,fps_dev);
			Uc = get_cpu_util(4,&Uc_bp,&Uc_tp);
			Ug = get_gpu_util(&Ug_bp,&Ug_tp);
			
			int Uc_dev = target_Uc - Uc;
			int Ug_dev = target_Ug - Ug;
			if(Uc_dev*100/Uc > 10)
				Fc_adj = (double)(Uc_dev) * reciprocal(Coef_Fc2Uc[game]) + FL[FL_point];
			if(Ug_dev*100/Ug > 10)
				Fg_adj = (double)(Ug_dev) * reciprocal(Coef_Fg2Ug[game]) + GFL[GFL_point];
			
			while(FL_point > 0 && FL[FL_point] > Fc_adj)FL_point--;
			while(GFL_point > 0 && GFL[GFL_point] > Fg_adj)GFL_point--;
			
			if(FL_point != pre_FL){		
				if(FL_point > freq_level-2){
					FL_point = freq_level-2;
				}else if(FL_point < 2){
					FL_point = 2;
				}		
				pre_FL = FL_point;
				set_cpu_freq(0,FL[FL_point]);			
			}
			
			
			if(GFL_point != pre_GFL){			
				if(GFL_point > gpu_freq_level-1){
					GFL_point = gpu_freq_level-1;
				}else if(GFL_point < 0){
					GFL_point = 0;
				}		
				pre_GFL = GFL_point;
				set_gpu_freq(GFL[GFL_point]);			
			}	
			
		}		
		sleep(1);
	}	
	return 0;
}
Exemplo n.º 27
0
int main(int argc, char *argv[]) {
  char *filename;
  int32_t code;
  FILE *dump;
  double time, mem_used;

  if (argc > 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(YICES_EXIT_USAGE);
  }

  if (argc == 2) {
    // read from file
    filename = argv[1];
    if (init_smt_file_lexer(&lexer, filename) < 0) {
      perror(filename);
      exit(YICES_EXIT_FILE_NOT_FOUND);
    }
  } else {
    // read from stdin
    init_smt_stdin_lexer(&lexer);
  }

  yices_init();

  init_smt_tstack(&stack);

  init_parser(&parser, &lexer, &stack);
  init_benchmark(&bench);
  code = parse_smt_benchmark(&parser, &bench);
  if (code == 0) {
    printf("No syntax error found\n");
  }

  if (benchmark_reduced_to_false(&bench)) {
    printf("Reduced to false\n\nunsat\n");
    fflush(stdout);
  }
  printf("\n");

  time = get_cpu_time();
  mem_used = mem_size() / (1024 * 1024);
  printf("Construction time: %.4f s\n", time);
  printf("Memory used: %.2f MB\n\n", mem_used);
  fflush(stdout);

  dump = fopen("yices2new.dmp", "w");
  if (dump == NULL) {
    perror("yices2new.dmp");
  } else {
    dump_benchmark(dump, &bench);
    fclose(dump);
  }

  delete_benchmark(&bench);
  delete_parser(&parser);
  close_lexer(&lexer);
  delete_tstack(&stack);
  yices_exit();

  return YICES_EXIT_SUCCESS;
}
Exemplo n.º 28
0
/* Actual mex function */
void mexFunction(int nargout, mxArray *argout[], int nargin, const mxArray *argin[]) 
{
  const mxArray *matlab_A;
  taucs_ccs_matrix A, *R;
  taucs_multiqr_factor *F;
  int *column_order, *icol_order;
  double *pr, *B, max_kappa_R;
  int i, nrhs;

  if (nargin > 2)
    taucs_logfile("/tmp/taucs_qr.log");

  /* Make sure A is sparse */
  matlab_A = argin[0];
  if (!mxIsSparse(matlab_A))
  {
    mexPrintf("input matrix A must be sparse\n");
    return;
  }

  max_kappa_R = mxGetScalar(argin[1]);

  /* Get B */
  if (nargin > 2 && !mxIsEmpty(argin[2]) && mxIsDouble(argin[2])) 
  {
    argout[2] = mxDuplicateArray(argin[2]);
    B = mxGetPr(argout[2]);
    nrhs = mxGetN(argout[2]);
  } else
  {
    if (nargout > 2)
      argout[2] = mxCreateDoubleMatrix(0, 0, mxREAL);
    B = NULL;
    nrhs = 0;
  }

  /* now we can convert to matrix */
  fill_taucs_ccs_matrix(matlab_A, &A);

  /* Run factorizatrization */
  double tstart = get_cpu_time();
  taucs_ccs_order(&A, &column_order, &icol_order, "colamd");
  F = taucs_ccs_factor_pseudo_qr(&A, column_order, max_kappa_R, 0, B, nrhs);
  free(column_order);
  free(icol_order);
  if (F == NULL)
  {
    mexPrintf("Factorization failed\n");fflush(stdout);
    return;
  }
  if (nargin > 3)
    mexPrintf("Actual factor time is %.2es\n", get_cpu_time() - tstart);

  /* Copy to matlab allocated structure (just to make sure no problems with free */
  tstart = get_cpu_time();

  R = taucs_multiqr_get_R(F, &column_order);
  argout[0] = convert_taucs_ccs_2_matlab(R);

  argout[1] =  mxCreateDoubleMatrix(1, A.n, mxREAL);
  pr = mxGetPr(argout[1]);
  for(i = 0; i < A.n; i++)
    pr[i] = column_order[i] + 1;

  free(column_order);

  if (nargin > 3)
    mexPrintf("Getting result time is %.2es\n", get_cpu_time() - tstart);

  /* Free TAUCS format */
  free_ccs_matrix(R);

  if (nargout > 3) 
  {
    int perb_number =  taucs_multiqr_get_perb_number(F);
    argout[3] =  mxCreateDoubleMatrix(1, perb_number, mxREAL);
    pr = mxGetPr(argout[3]);
    int *indices = malloc(perb_number * sizeof(int));
    taucs_multiqr_get_perb_indices(F, indices);
    for(i = 0; i < perb_number; i++)
      pr[i] = (int)indices[i] + (indices[i] > 0 ? 1 : -1);
  }

  if (nargout > 4)
    argout[4] = mxCreateDoubleScalar(taucs_multiqr_get_perb_value(F));

  taucs_multiqr_factor_free(F);

  if (nargin > 3) 
  {
    taucs_profile_report();
    mexPrintf("Look at more profiling at /tmp/taucs_qr.log\n");
  }

}
Exemplo n.º 29
0
int main(int argc, char *argv[]) {
  uint32_t i, j, n;
  double runtime, memused;
  int32_t x, *val;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s filename\n", argv[0]);
    fprintf(stderr, "  filename must contain a set of strings, one per line, less than 100 char long\n");
    fflush(stderr);
    exit(1);
  }
  words_from_file(argv[1]);

  init_stbl(&sym_table, 0);

  val = (int32_t *) malloc(n_words * sizeof(int32_t));
  if (val == NULL) {
    fprintf(stderr, "Failed to allocate array val\n");
    exit(1);
  }

  for (i=0; i<n_words; i++) {
    x = stbl_find(&sym_table, words[i]);
    if (x < 0) {
      stbl_add(&sym_table, words[i], i);
      val[i] = i;
    } else {
      val[i] = x;
    }
  }

  printf("\n--- checking ---\n");
  for (i=0; i<n_words; i++) {
    x = stbl_find(&sym_table, words[i]);
    if (x != val[i]) {
      printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[i], x, val[i]);
      fflush(stdout);
      exit(1);
    }
  }

  printf("\n*** Added %"PRIu32" words from %s ***\n", n_words, argv[1]);

  // repeated additions of the same symbols with multiple lookups
  // warning: this code does not work (may give a false alarm)
  // if the input file contains duplicates.
  n = (n_words < 200) ?  n_words : 200;
  printf("\n*** Repeated symbol addition ***\n");
  runtime = get_cpu_time();
  for (i=0; i<10000; i++) {
    for (j=0; j<n; j++) {
      stbl_add(&sym_table, words[j], new_val(i, j));
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n_words; j++) {
      x = stbl_find(&sym_table, words[j]);
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n_words; j++) {
      x = stbl_find(&sym_table, words[j]);
    }
  }


  runtime = get_cpu_time() - runtime;
  memused = mem_size() / (1024 * 1024);
  printf("Adding 10000 times the same %"PRIu32" words + repeated lookups\n", n);
  printf("Runtime: %.4f s\n", runtime);
  printf("Table size: %"PRIu32" (nelems = %"PRIu32", ndeleted = %"PRIu32")\n",
	sym_table.size, sym_table.nelems, sym_table.ndeleted);
  if (memused > 0) {
    printf("Memory used: %.2f MB\n", memused);
  }

  clear_words();
  free(val);
  delete_stbl(&sym_table);

  return 0;
}
TwoObjectivesInstance::TwoObjectivesInstance(string name, string filename1, string filename2)
:m_Name(name), m_File1Path(filename1), m_File2Path(filename2)
{
    // On initialise srand
    std::srand(std::time(0));

    // On établit la précision
    //cout.precision(dbl::max_digits10);
    cout.precision(8);

    // On parse les fichiers
    this->m_File1Matrix = this->parsingTSPFile(filename1, &this->m_File1Dimension);
    this->m_File2Matrix = this->parsingTSPFile(filename2, &this->m_File2Dimension);

    // On teste si les dimensions des deux fichiers sont les mêmes
    // Si ce n'est pas le cas, il y'a un problème
    if(this->m_File1Dimension != this->m_File2Dimension)
    {
        cout << "Erreur: les deux fichiers n'ont pas le même nombre de villes" << endl;
        cout << filename1 << " possède " << this->m_File1Dimension << " villes"<< endl;
        cout << filename2 << " possède " << this->m_File2Dimension << " villes"<< endl;
        exit(EXIT_FAILURE);
    }

    // On génère 500 solutions
    for(int i = 0; i < SOLUTIONS; i++)
    {
        #if SHOW_DEBUGS
        cout << endl << "Solution N°" << i+1 << endl;
        #endif // SHOW_DEBUGS
        this->generateSolution(i);
    }

    // Filtrage Online
    this->onlineFiltering();

    // Filtrage Offline
    this->offlineFiltering();

    // On affiche les 500 solutions
    #if SHOW_DEBUGS
    for(int i = 0; i < SOLUTIONS; i++)
    {
        cout << endl << "Solution N°" << i+1 << endl;
        cout << "Distance: " << this->m_solutions[i].Getdistance() << " - Coût: " << this->m_solutions[i].Getcost() << endl;
        cout << "Dominée online: " << this->m_solutions[i].GetOnlineDominated() << endl;
        cout << "Dominée offline: " << this->m_solutions[i].GetOfflineDominated() << endl;
    }
    #endif // SHOW_DEBUGS

    // On crée un graphique sur gnuplot avec toutes les solutions
    this->makePlot(this->m_Name, OFFLINE, false);
    this->makePlot(this->m_Name, ONLINE, false);

    // On crée un graphique sur gnuplot avec le Front de Pareto
    this->makePlot(this->m_Name, OFFLINE, true);
    this->makePlot(this->m_Name, ONLINE, true);

    // 5) Fichier 10 approx front pareto
    this->createApproxFile();

    // On exécute au moins 10 fois
    cout << "Approximations du front de Pareto pour l'instance " << m_Name << endl;
    for(int i = 0; i < 10; i++)
    {
        double cpu0  = get_cpu_time();
        // On remplit un front de Pareto dans le fichier
        vector<Solution> best_sols = PLS();
        double cpu1  = get_cpu_time();
        cout << "Temps d'exécution itération " << i+1 << " : " << (int)( (cpu1  - cpu0) * 1000) << " milliseconds (CPU time)" << endl;
        this->fillApproxFile(best_sols, i);
    }
    makePlotForPLS();
}