Esempio n. 1
0
      int		randomBetween(int start, int end)
      {
	std::uniform_int_distribution<int> dist_n(start, end);
	return (dist_n(_generator));
      }
Esempio n. 2
0
int main(int argc, char** argv)
{  
  if(argc^7){
    printf("Usage: ./osil bits seed N G Mu Chi\n");
    exit(1);
  }
  if ((sizeof(int) < 4)|| (sizeof(long int) < 8)){
    printf("Assumptions concerning bits are invalid: int has %d bits, unsigned long int has %d bits\n",
	   (int)(8*sizeof(int)), (int)(8*sizeof(unsigned long)));
    return 1;
  }
  L = atol(argv[1]);                     // bit length
  if (L > 32){
    printf("Can't have more thqan 32 bits\n");
    return 1;
  }
  int seed = atoi(argv[2]);
  N = (unsigned long)atoi(argv[3]);      // no. of individuals in finite population
  G = (unsigned long)atol(argv[4]);      // no. of generations
  Mu_n = atof(argv[5]);          
  Chi_n = atof(argv[6]);

  int i,j, n, m;
  double *d1, *d2, dst1, dst2;
  unsigned long *tmp_ptr;
  char fname[200];                       // file name
  FILE *fp;                              // data file pointer
  
  d1 = calloc(G, sizeof(double));
  d2 = calloc(G, sizeof(double));
  
  initrand(seed);
  setup();   
         
  init();                             // initializes memory for pop, M and Cr and also installs values for these  
  merge_sort(Pop[0], N);    
  // infinite population simulation   
  calc_px_from_finite_population(P0); // calculates haploids proportion using finite set
  P1 = g_w(G, P0, P1);
  display_p(P1);
  // find oscillating points for infinite population
  if( osc_points(P0, P1, P2, P3) ){     // if oscillation occurs
    {                                   // compute distance between finite population to oscillating points
      int a, b;  
      //finite population simulation
      for(i = 0; i < G; i++){           // evolve through G generations
	for(j = 0; j < N; j++){         // reproduce N offsprings      
	  a = rnd(N); b = rnd(N);
	  reproduce(a, b, j);           // randomly two parents chosen; will be proportional to proportion
	}
	merge_sort(Pop[0], N); 
	// calculate distance to oscillating points and write to file
	dst1 = dist_n(P2);               // distance to 1st oscillating point
	dst2 = dist_n(P3);               // distance to 2nd oscillating point
	d1[i] = dst1;
	d2[i] = dst2;
	// set new generation as parent generation for next generation
	tmp_ptr = Pop[0];
	Pop[0] = Pop[1];
	Pop[1] = tmp_ptr;		    
      }
    }
  }     
  deinit();        
  cleanup();
  
  sprintf(fname, "b%lug%lun%lu_osc.dat", L, G, N);
  if(!(fp = fopen(fname, "w"))){
    printf("%s could not be opened!! Error!!\n", fname);
    exit(2);
  }
   // write distances to file
   for(n = 0; n < G; n++){
    fprintf(fp, "%d  ", n);
    fprintf(fp, "%" PREC "lf  %" PREC "lf\n", d1[n], d2[n]);
   }
  fclose(fp);
  free(d1); free(d2);
  
  FILE *gp = popen ("gnuplot -persistent", "w"); // open gnuplot in persistent mode
  plot(gp, 0, fname, 3, "oscillation", "G", "d", 0, "" );
  fflush(gp);
  pclose(gp);
  
  return 0;
}