예제 #1
0
bool GAConjProblemForORGroupSolver::isConj( )
{
  if( bestFit==NOCONJ ) {
    if( conjProblem )
      *file << "Given words are not conjugate." << endl;
    else 
      *file << "The word is not trivial." << endl;
    return false;
  }

  theIter1 = 1 ;
  theIter2 = 0;

  for( ; bestFit!=0 ; ++theIter1, ++theIter2, ++lastImprovement ) {
    
    if( theIter1 % 100 == 0 && file ) 
      *file << "Generation " << theIter1 << ", best fitness " << bestFit << endl << endl;

    int newGenes = reproduction( );
    for( int g=0 ; g<newGenes ; ++g )
      if( tournament( *newGene[g] ) )
	break;

    checkImprovementTime( );
  }
  
  if( conjProblem )
    *file << "Given words are conjugate." << endl;
  else
    *file << "The given word is trivial." << endl;

  return true;
}
예제 #2
0
int main(int argc, char *argv[]) {
	int my_rank;
	double mpi_start_time, mpi_end_time;
	deme *subpop = (deme*) malloc(sizeof(deme));

	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
	init_population(subpop, argc, argv);
	mpi_start_time = MPI_Wtime();

	while (!subpop->complete) {
		migration(subpop);
		reproduction(subpop);
		crossover(subpop);
		mutation(subpop);
		fitness(subpop);
		subpop->old_pop = subpop->new_pop;
		subpop->cur_gen++;
		check_complete(subpop);
		sync_complete(subpop);
		report_all(subpop);
	}
	
	mpi_end_time = MPI_Wtime();
	report_fittest(subpop);
	MPI_Finalize();
	printf("[%i] Elapsed time: %f\n", my_rank, mpi_end_time - mpi_start_time);
	return 1;
}
예제 #3
0
bool GAConjProblemForORGroupConjecture::isConj( int maxIter , int& doneIter )
{
  if( bestFit==NOCONJ )
    return false;

  theIter1 = doneIter;
  theIter2 = 0;

  for( ; bestFit!=0 && theIter1<=maxIter+doneIter ; ++theIter1, ++theIter2, ++lastImprovement ) {
    
    if( theIter1 % 100 == 0 && file ) 
      *file << "Generation " << theIter1 << ", best fitness " << bestFit << endl << endl;

    int imp = lastImprovement;

    int newGenes = reproduction( );
    for( int g=0 ; g<newGenes ; ++g )
      if( tournament( *newGene[g] ) )
	break;

    // if there was an improvement
    if( imp!=lastImprovement && lastImprovement==0 ) 
      maxIter += theIter2;
    
  }

  doneIter = theIter1;
  
  if( bestFit==0 ) return true;
  return false;  
}
예제 #4
0
Stats Population::evaluate()
{
    ++_current_gen;

    fitness_testing(); //so individuals have set current fitness
    if (_current_gen != 1)
        adult_selection();
    parent_selection();
    reproduction();
    return _current;
}
예제 #5
0
파일: Genes.cpp 프로젝트: Ibasam/IBASAM
Genes::Genes(Genes *mother, Genes *father)
{
	gPercF_ = reproduction(&(mother->gPercF_),&(father->gPercF_));
	gG_ = reproduction(&(mother->gG_),&(father->gG_));
	gG_sea_ = reproduction(&(mother->gG_sea_),&(father->gG_sea_));
	gMocean_intercept_ = reproduction(&(mother->gMocean_intercept_),&(father->gMocean_intercept_));
	//gMocean_slope_ = reproduction(&(mother->gMocean_slope_),&(father->gMocean_slope_));
	gMocean_f_intercept_ = reproduction(&(mother->gMocean_f_intercept_),&(father->gMocean_f_intercept_));
	//gMocean_f_slope_ = reproduction(&(mother->gMocean_f_slope_),&(father->gMocean_f_slope_));
	gMriver_intercept_ = reproduction(&(mother->gMriver_intercept_),&(father->gMriver_intercept_));
	//gMriver_slope_ = reproduction(&(mother->gMriver_slope_),&(father->gMriver_slope_));
	gMriver_f_intercept_ = reproduction(&(mother->gMriver_f_intercept_),&(father->gMriver_f_intercept_));
	//gMriver_f_slope_ = reproduction(&(mother->gMriver_f_slope_),&(father->gMriver_f_slope_));
	gSLmid_ = reproduction(&(mother->gSLmid_),&(father->gSLmid_));
	gSalphaS_ = reproduction(&(mother->gSalphaS_),&(father->gSalphaS_));
	neutral_=reproduction(&(mother->neutral_),&(father->neutral_));
	ID_=0;
	motherID_=mother->ID();
	fatherID_=father->ID();
	motherStrat_=mother->strategy();//floor(mother->AgeSea()) + floor(mother->AgeRiver())*0.1;
	fatherStrat_=father->strategy();//floor(father->AgeSea()) + floor(father->AgeRiver())*0.1;
}
예제 #6
0
//----------------------------------------------------------------------------------
//std::vector<EnumConclusion> Simulation::execute()
void Simulation::execute(MeasurementsTable& table, std::vector<EnumConclusion>& conclusions)
{

	checkPopSize("void Simulation::execute() - #1");
	std::cout << "Start of simulation, running time (timesteps): " << mMaxTime << std::endl;
	std::cout << "Starting population size: " << SoilMiteBase::getPopSize() << std::endl;

	mErrorCode = EcNoError;
	for(unsigned int time=0; time<mMaxTime && mErrorCode==EcNoError; ++time)
	{
		changeEnvironment(time,table);
		intake(table);
		reproduction(table);
		mortality();
		measurePopulation(table);
		if (mOptionsFileParameters.showYearSummary==true) table.showYearHorizontal(time);
	}

	
	checkPopSize("void Simulation::execute() - #2");
	mpFunctions->coutAll();
	std::cout << "Body size adult: " << SoilMiteBase::getBodySizeAdult() << std::endl; 

	//Some conclusions
	if (mOffspringProduced==false) conclusions.push_back(CcNoOffspringProduced);
	switch(mErrorCode)
	{
		case EcNoError: conclusions.push_back(CcNoError); break;
		case EcPopExtinct: conclusions.push_back(CcPopExtinct); break;
		case EcPopSizeTooBig: conclusions.push_back(CcPopSizeTooBig); break;
		case EcNoffspringTooBigSingleParent: conclusions.push_back(CcNoffspringTooBigSingleParent); break;
		case EcNoffspringTooBigAllParents: conclusions.push_back(CcNoffspringTooBigAllParents); break;
	}

	
}
예제 #7
0
int main(int argc, char *argv[])
{
    int ch;
    char *progname = argv[0];

    // read in optional command line arguments
    while ((ch = getopt(argc, argv, "A:C:D:I:L:m:M:N:p:P:q:r:R:s:S:t:T:u:U:w:W:z:Z?")) != -1) {
        switch (ch) {
            case 'A':
                DURATION_ALLOPATRY = atoi(optarg);
                break;
            case 'C':
                CUTOFF = strtod(optarg, (char**)NULL);
                break;
            case 'D':
                DETERMINISTIC = atoi(optarg);
                break;
            case 'I':
                INITIAL_CONDITION = atoi(optarg);
                break;
            case 'L':
                nSITES_PER_WINDOW = atoi(optarg);
                break;
            case 'm':
                MIGRATION_RATE = strtod(optarg, (char **)NULL);
                break;
            case 'M':
                MODEL_TYPE = atoi(optarg);
                break;
            case 'N':
                TOTAL_N = atoi(optarg);
                break;
            case 'p':
                PROB_MUT_BENEFICIAL = strtod(optarg, (char **)NULL);
                break;
            case 'P':
                PROB_MUT_BG = strtod(optarg, (char **)NULL);
                break;
            case 'q':
                PROB_MUT_DIVERGENT = strtod(optarg, (char **)NULL);
                break;
            case 'Q':
                HIGH_RECOMB_PROB_PER_KB = strtod(optarg, (char **)NULL);
                break;
            case 'r':
                LOW_RECOMB_PROB_PER_KB = strtod(optarg, (char **)NULL);
                break;
            case 'R':
                nGENOMIC_REGIONS = atoi(optarg);
                break;
            case 's':
                MEAN_S_BENEFICIAL = strtod(optarg, (char **)NULL);
                break;
            case 'S':
                MEAN_S_BG = strtod(optarg, (char **)NULL);
                break;
            case 't':
                MEAN_S_DIVERGENT = strtod(optarg, (char **)NULL);
                break;
            case 'T':
                TOTAL_GENERATIONS = atoi(optarg);
                break;
            case 'u':
                MU_LOW = strtod(optarg, (char **)NULL);
                break;
            case 'U':
                MU_HIGH = strtod(optarg, (char **)NULL);
                break;
            case 'w':
                WINDOW_SIZE_BASES = atoi(optarg);
                break;
            case 'W':
                nWINDOWS_PER_REGION = atoi(optarg);
                break;
            case 'z':
                MONITOR_PROGRESS = atoi(optarg);
                break;
            case 'Z':
                useShortTestValuesOfParameters();
                break;
            case '?':
            default:
                usage(progname);
                exit(-1);
        }
    }
    
    int *demeIndexes;
    demeIndexes = (int *) malloc( (sizeof(int) * TOTAL_N * nDEMES));
    
    // set up
    RNGsetup();
    initializePopulation();
    openDataRecordingFiles();
    
    
    
    // main operations
    for ( t = 1; t <= TOTAL_GENERATIONS; t++ ) {
        
        if ( t > DURATION_ALLOPATRY )
            migration( demeIndexes );
        
        reproduction( demeIndexes );
        
        calculateMetricsAndStats();
        
        if ( MONITOR_PROGRESS ) {
            if ( t % MONITOR_PROGRESS == 0 )
                fprintf(stdout, "%li\n", t);
        }
    }
    
    
    finalPrints();
    
    // free blocks from malloc
    free(genomeMap);
    free(genotypes);
    free(isVariableSite);
    free(fixedAllele);
    free(alleleFrequenciesByDeme);
    free(alleleSelectionCoeffs);
    free(demeLocations);
    free(demeIndexes);
    free(regionFlags);
    free(windowFlags);
    free(regionMembership);
    free(windowMembership);
    free(mutationRateClass);
    free(alleleFrequencies);
    
    // close files
    fclose(mutationLog);
    fclose(alleleFrequenciesOverTime);
    fclose(fixationLog);
    fclose(piOverTime);
    fclose(DaOverTime);
    fclose(DxyOverTime);
    fclose(variableLociOverTime);
    
    return 0;
}
예제 #8
0
int main (int argc, char* argv[]) {

  srand(atoi(argv[1])); //Take argument to write special extension to file
  double Btotalple, Bnurseple, Bspawnple, Btotalsol, Bnursesol, Bspawnsol ;    /* biomass on nursery, total biomass */

  //Read in the data
  readgrid(&GridFood , X_MAX, Y_MAX, 52, theFood);
  cout << "Read Food completed" << endl;

  readgrid(&GridTemp , X_MAX, Y_MAX, 52, theTemp);
  cout << "Read Temp completed" << endl;

  readgrid(&GridLMort , X_MAX, Y_MAX, 52, theLMort);
  cout << "Read Larval Mortality completed" << endl;

  readgrowthgam(&WeekPropFood,52,theGrowthGam);
  cout << "Read growth gam completed" << endl;

  /* INITIALISE INDIVIDUALS AT START, FIRST PLAICE, THEN SOLE */
  for(int i=0; i < POPMAX; i++) {
    ple[i].sex    = (i%2)+1;
    ple[i].weight = BORNWGHT;
    ple[i].id     = id ;
    ple[i].stage  = 1 ; /* everybody should be mature */
    ple[i].age    = 52 ;
    ple[i].u_m    = U_M ;
    ple[i].u_f    = U_F;
    if(SPAREA == 1){ 
      ple[i].X      = 75 ;
      ple[i].Y      = 53 ;
    } else if(SPAREA == 2){
        ple[i].X      = 91 ;
        ple[i].Y      = 67 ;
    }             
    int X         = ple[i].X;
    int Y         = ple[i].Y;
    int resX, resY;
    for(int dd=0; dd < L_CHR1;  dd++){ //check juvenile strategy
        do{ple[i].juvXdir[dd] = (char)( (rand()% 11) -5); // Movement of maximum 5 left or right //
           ple[i].juvYdir[dd] = (char)( (rand()% 11) -5); // Movement of maximum 5 up or down    //
           resX = (int) (ple[i].juvXdir[dd] * ple[i].swim()) ;
           resY = (int) (ple[i].juvYdir[dd] * ple[i].swim()) ;
        } while ((theTemp[1][X + resX][Y + resY ] < -15) ||(( X + resX) <0) || (( X + resX) > X_MAX) ||(( Y + resY) < 0) || ((Y + resY) > Y_MAX));
        X += resX;
        Y += resY;
        ple[i].weight  = ple[i].weight  + ple[i].growth(theFood[(dd+6)%52][X][Y], theTemp[(dd+6)%52][X][Y],theGrowthGam[(dd+6)%52]);      
    }    
    for(int dd=0; dd <L_CHR2;  dd++){ //check juvenile strategy
      ple[i].adultXdir[dd] = (char)( (rand()% 11) -5); // Movement of maximum 5 left or right //
      ple[i].adultYdir[dd] = (char)( (rand()% 11) -5); // Movement of maximum 5 up or down    //
    }
    ple[i].weight = BORNWGHT;
    id++;
  }

//  for(int i=0; i < POPMAX; i++){
//    sol[i].sex    = (i%2)+1;
//    sol[i].weight = BORNWGHT ;
//    sol[i].id     = id ;
//    sol[i].stage  = 1 ;
//    sol[i].age    = 52 ;
//    sol[i].u_m    = U_M ;
//    sol[i].u_f    = U_F;
//    if(SPAREA == 1){ 
//      sol[i].X      = 75 ;
//      sol[i].Y      = 53 ;
//    } else if(SPAREA == 2){
//        sol[i].X      = 91 ;
//        sol[i].Y      = 67 ;
//    } 
//    int X         = sol[i].X;
//    int Y         = sol[i].Y;
//    int resX, resY;
//    for(int dd=0; dd < L_CHR1;  dd++){                         //check juvenile strategy
//        do{sol[i].juvXdir[dd] = (char)( (rand()% 11) -5);      // Movement of maximum 5 left or right //
//           sol[i].juvYdir[dd] = (char)( (rand()% 11) -5);      // Movement of maximum 5 up or down    //
//           resX = (int) (sol[i].juvXdir[dd] * sol[i].swim()) ;
//           resY = (int) (sol[i].juvYdir[dd] * sol[i].swim()) ;
//        } while ((theTemp[1][X + resX][Y + resY ] < -15) ||(( X + resX) <0) ||((X + resX) > X_MAX) ||((Y + resY )< 0) ||((Y + resY) > Y_MAX));
//        X += resX;
//        Y += resY;
//        sol[i].weight  = sol[i].weight  + sol[i].growth(theFood[(dd+6)%52][X][Y], theTemp[(dd+6)%52][X][Y],theGrowthGam[(dd+6)%52]);      
//    }
//    for(int dd=0; dd < L_CHR2 ;  dd++){                        //check juvenile strategy
//      sol[i].adultXdir[dd] = (char)((rand()% 11) -5);          // Movement of maximum 5 left or right //
//      sol[i].adultYdir[dd] = (char)((rand()% 11) -5);          // Movement of maximum 5 up or down    //
//    }
//    sol[i].weight = BORNWGHT;
//    id++;
//  }                                                            // end for loop over individuals /
  cout << "Initialisation of Plaice and Sole done" << endl;

  int aliveple = POPMAX, alivesol = POPMAX;

  string ext(".csv");                                          //Open file to write output to disk
  string SPname("_SPAREA");
  char buffer [4];
  string SP(itoa(SPAREA,buffer,10));
  filename += ( argv[1] + SPname + SP + ext);
  cout << filename << endl;
  popname += (argv[1] + SPname + SP + ext);
  myfile.open (filename.c_str() );
  mypopulation.open(popname.c_str());

  /* START SIM */
  for(int t = 6; t < T_MAX; t++){
   /* CALCULATE TOTAL BIOMASS AND BIOMASS ON NURSERY FOR TWO SPECIES */
    Bnurseple = Btotalple = Bspawnple = Bnursesol = Btotalsol = Bspawnsol = 0;

    for(int n = 0 ; n < aliveple ; n++) {
        if (ple[n].stage < 3 ) {
            Btotalple  += ple[n].weight ;
            if (ple[n].stage < 2 ) Bnurseple += ple[n].weight;
        }
    }

//    for(int n = 0 ; n < alivesol ; n++) {
//        if (sol[n].stage < 3 ) {
//            Btotalsol  += sol[n].weight ; 
//            if (sol[n].stage < 2 ) Bnursesol += sol[n].weight;
//        }
//    }

    Bspawnple =  Btotalple - Bnurseple;
//    Bspawnsol =  Btotalsol - Bnursesol;

    move(ple, aliveple, t%52, theTemp);                                                       // Move individuals every tenth timestep //
//    move(sol, alivesol, t%52, theTemp);                                                       // Move individuals every tenth timestep //  

    age        (ple, aliveple)    ;                                                           // Function of ageing //
//    age        (sol, alivesol)    ;                                                           // Function of ageing //    

    mortality(ple, LAMBDAple, aliveple ,Bnurseple ) ;                                         // Function mortality //
//    mortality(sol, LAMBDAsol, alivesol ,Bnursesol ) ;                                         // Function mortality */

    growth     (ple, aliveple, Bnurseple, t % 52, theFood, theTemp, theGrowthGam) ;                        // Function of growth //   
//    growth     (sol, alivesol, Bnursesol, t % 52, theFood, theTemp, theGrowthGam) ;                        // Function of growth //

    if(t%52 == 10 ) maturation (ple, aliveple)   ; //Checked with Cindy, gonads start to develop in March // Function of maturation //
//    if(t%52 == 10 ) maturation (sol, alivesol)   ;                                           // Function of maturation //

    if(t%52 == 5) cout<<"i " << argv[1]  <<" t " << t << " ssb ple " << Bspawnple<<" num ple "<<aliveple<< endl; //output(ple,t, 3);            // Write biomass and number to screen, followed by data for 10$
//    if(t%52 == 5) cout<<"i " << argv[1]  <<  " t " << t << " ssb sol " << Bspawnsol<<" num sol "<<alivesol<< endl; //output(sol,t, 3);            // Write biomass and number to screen, followed by data fo$

    aliveple = alive2front (ple)  ;                                                           // shuffle so that alives are in front*/
//    alivesol = alive2front (sol)  ;                                                           // shuffle so that alives are in front*/

    if(t%52 == 5) aliveple = reproduction(ple, R1ple, R2ple, aliveple, Bspawnple, theTemp); // Function of reproduction  in week 5*/
//    if(t%52 == 5) alivesol = reproduction(sol, R1sol, R2sol, alivesol, Bspawnsol, theTemp); // Function of reproduction  in week 5*/

    if(t%52 == 5){ larvalmortality (ple, aliveple, theLMort); aliveple = alive2front (ple);} // larvalmortality depends on field, now uniform field where everybody survives //
//    if(t%52 == 5){ larvalmortality (sol, alivesol, theLMort); alivesol = alive2front (sol);} // larvalmortality depends on field, now uniform field where everybody survives // 

    //Write output
    if ((t==6) ||( (t+A_MAX) % (int)(T_MAX/(T_STEP-1)) < 52 && t % 52 == 6)){
        int nn  = aliveple;
        int age = ple[nn].age;
        do{ age = ple[nn].age;
          nn--;
        } while ((nn > (aliveple - P_WRITE)) && (age <= 53));
        minid = ple[nn + 1].id;
        maxid = ple[aliveple - 1].id;
    } else if ((t < 6 + A_MAX) ||( (t + A_MAX)% (int)(T_MAX/(T_STEP-1)) < A_MAX +52)){
      for(int nn = 0; nn < aliveple; nn++){
        if(ple[nn].stage < 3 && (ple[nn].id > minid & ple[nn].id < maxid)){
          myfile <<t << "," <<       ple[nn].id          << "," << (int) ple[nn].sex          << "," <<       ple[nn].age                           << "," << (int) ple[nn].stage 
                     << "," <<       ple[nn].X           << "," <<       ple[nn].Y            << "," <<       ple[nn].weight       
                     << "," << (int) ple[nn].juvXdir[(int) (ple[nn].age)]                     << "," << (int) ple[nn].juvYdir[(int) (ple[nn].age)]  
                     << "," << (int) ple[nn].adultXdir[(t+1)%52]                              << "," << (int) ple[nn].adultYdir[(t+1)%52]           << endl;
        }
      }
    }

    //Write output every 15 years (cycle of complete new population)        
    if(t % (A_MAX) == 5){ writePopStruct(mypopulation, ple,aliveple,t);}

  } //end of timeloop

  myfile.close() ; mypopulation.close();
  return 0 ;
}
예제 #9
0
/* Main program */
int main(int argc, char *argv[]){
	unsigned int g, i; 				/* Counters. Reps counter, geno counter */
	unsigned int reps;				/* Length of simulation (no. of introductions of neutral site) */
	double Bcheck = 0;				/* Frequency of B after each reproduction */
	double Acheck = 0;				/* Frequency of polymorphism */
	double Hsum = 0;				/* Summed heterozygosity over transit time of neutral allele */
	
	/* GSL random number definitions */
	const gsl_rng_type * T; 
	gsl_rng * r;
	
	/* This reads in data from command line. */
	if(argc != 8){
		fprintf(stderr,"Invalid number of input values.\n");
		exit(1);
	}
	N = strtod(argv[1],NULL);
	s = strtod(argv[2],NULL);
	rec = strtod(argv[3],NULL);
	sex = strtod(argv[4],NULL);
	self = strtod(argv[5],NULL);
	gc = strtod(argv[6],NULL);
	reps = strtod(argv[7],NULL);
	
	/* Arrays definition and memory assignment */
	double *genotype = calloc(10,sizeof(double));				/* Genotype frequencies */
	unsigned int *gensamp = calloc(10,sizeof(unsigned int));	/* New population samples */
	  
	/* create a generator chosen by the 
    environment variable GSL_RNG_TYPE */
     
	gsl_rng_env_setup();
	if (!getenv("GSL_RNG_SEED")) gsl_rng_default_seed = time(0);
	T = gsl_rng_default;
	r = gsl_rng_alloc(T);
	
	/* Initialising genotypes */
	geninit(genotype);
    
    /* Run simulation for 2000 generations to create a burn in */
    for(g = 0; g < 2000; g++){

    	/* Selection routine */
    	selection(genotype);
    	
    	/* Reproduction routine */
    	reproduction(genotype);
    	
       	/* Gene conversion routine */
       	gconv(genotype);
       	
       	/* Sampling based on new frequencies */
       	gsl_ran_multinomial(r,10,N,genotype,gensamp);
       	for(i = 0; i < 10; i++){
			*(genotype + i) = (*(gensamp + i))/(1.0*N);
       	}
       	
       	/* Printing out results (for testing) */
		/*
	   	for(i = 0; i < 10; i++){
			printf("%.10lf ", *(genotype + i));
		}
		printf("\n");
		*/
    }
    
	/* Reintroducing neutral genotype, resetting hap sum */	
	neutinit(genotype,r);
    Bcheck = ncheck(genotype);
    Hsum = Bcheck*(1-Bcheck);
    /* printf("%.10lf %.10lf\n",Bcheck,Hsum); */
    
    /* Introduce and track neutral mutations 'reps' times */
    g = 0;
    while(g < reps){

    	/* Selection routine */
    	selection(genotype);
    	
    	/* Reproduction routine */
    	reproduction(genotype);
    	
    	/* Gene conversion routine */
       	gconv(genotype);
       	
    	/* Sampling based on new frequencies */
       	gsl_ran_multinomial(r,10,N,genotype,gensamp);
       	for(i = 0; i < 10; i++){
       		*(genotype + i) = (*(gensamp + i))/(1.0*N);
       	}
       	
       	/* Checking state of haplotypes: if B fixed reset so can start fresh next time */
		Bcheck = ncheck(genotype);
		Hsum += Bcheck*(1-Bcheck);
		/* printf("%.10lf %.10lf\n",Bcheck,Hsum); */
		
		/* If polymorphism fixed then abandon simulation */
       	Acheck = pcheck(genotype);
       	if(Acheck == 0){
       		g = reps;
       	}
       	
       	if(Bcheck == 0 || Bcheck == 1){
       		printf("%.10lf\n",Hsum);
       		g++;
       		/* printf("Rep Number %d\n",g); */
       		
       		if(Bcheck == 1){
       			/* Reset genotypes so B becomes ancestral allele */
       			*(genotype + 0) = *(genotype + 7);
       			*(genotype + 1) = *(genotype + 8);
       			*(genotype + 4) = *(genotype + 9);
       			*(genotype + 7) = 0;
       			*(genotype + 8) = 0;
       			*(genotype + 9) = 0;      			
       		}
     		 
     		/* Reintroducing neutral genotype, resetting hap sum */     		
	    	neutinit(genotype,r);
			Bcheck = ncheck(genotype);
       		Hsum = Bcheck*(1-Bcheck);
       	}
    
	}	/* End of simulation */
	
	
	/* Freeing memory and wrapping up */
 	gsl_rng_free(r);
 	free(gensamp);
	free(genotype);
	/* printf("The End!\n"); */
	return 0;
}
예제 #10
0
파일: simulation.c 프로젝트: Vinc41/cublife
void actualiserIndividus(Simulation* sim)
{

    Espece *espece = sim->premiereEspece;
    Individu *ind;
    Individu *indSuiv;
    Individu *proche=NULL;
    bool regulationVitesseActive=false;
    bool mangee=false;

    int dep=0;

    while(espece!=NULL)
    {
        ind=espece->premierIndividu;
        while(ind!=NULL)
        {


                indSuiv=ind->suivant; // sauvegarde l'individu suivant au cas où l'individu courant est désalloué par sa mort
                proche=NULL;
                regulationVitesseActive=false;
                dep=0;
                mangee=false;

                ///DEPLACEMENT
                dep=deplacement(ind,sim);
                if(dep)
                {
                    deplacementAleatoire(ind);
                }

                //on deplace l'individu suivant l'angle donné précédement.
                ind->position.x += ind->vitesse * cos((ind->direction)*M_PI/180.0) * sim->coeffTemps;
                ind->position.y -= ind->vitesse * sin((ind->direction)*M_PI/180.0) * sim->coeffTemps;


                ///ETAT EAU ET NOURRITURE ET FATIGUE
                if((ind->espece->type!=VEGETAL)&&((ind->stockEau>0)||(ind->stockNourriture>0)))
                {
                    if(ind->stockEau>0.1)
                    {
                        ind->stockEau-=0.1*sim->coeffTemps;
                        if(ind->stockEau<0)
                        {
                            ind->stockEau=0;
                        }
                    }
                    if(ind->stockNourriture>0.05)
                    {
                        ind->stockNourriture-=0.05*sim->coeffTemps;
                        if(ind->stockNourriture<0)
                        {
                            ind->stockNourriture=0;
                        }
                    }



                }
                if(ind->repos==0)
                {
                    ind->fatigue+=0.1*sim->coeffTemps;
                    if(ind->fatigue>100)
                        {
                            ind->fatigue=100;
                        }
                }

                if((ind->fatigue<10)&&(ind->repos==1))
                {
                    ind->repos=0;
                }
                if((ind->fatigue>90)&&(ind->repos==0))
                {
                    if((interactionIndividuMap(sim,ind)==TERRE)&&(Random(0,100)>95))
                    {
                        ind->vitesse=0;

                        ind->repos=1;
                    }
                }
                if(ind->repos)
                {
                    regulationVitesseActive=1;
                    ind->vitesse=0;
                    ind->fatigue-=0.5*sim->coeffTemps;
                    if(ind->fatigue<0)
                        {
                            ind->fatigue=0;
                        }
                }

                if((ind->stockEau<10)||(ind->stockNourriture<10))
                {
                    ind->vitesse=ind->espece->vitesseMoyenne*0.6;
                    regulationVitesseActive=true;
                }
                //stock eau
                if(interactionIndividuMap(sim,ind)==EAU)
                {
                    ind->stockEau=100;
                    ind->vitesse=ind->espece->vitesseMoyenne*0.7;
                    regulationVitesseActive=true;
                }

                if((ind->stockEau<1)||(ind->stockNourriture<1))
                {
                    ind->sante-=0.5*sim->coeffTemps;
                    if(ind->sante<0)
                        {
                            ind->sante=0;
                        }
                }
                else if(ind->sante<100)
                {
                    ind->sante+=0.5*sim->coeffTemps;
                    if(ind->sante>100)
                        {
                            ind->sante=100;
                        }
                }
                if(regulationVitesseActive==0)
                {
                    regulerVitesse(ind);
                }

                //boucle de verif

                if(ind->espece->type==VEGETAL)//reproduction plante
                {
                    if((ind->derniereReproduction+ind->espece->delaiProchaineReproduction)<(sim->tempsPasse))
                    {
                        if(Random(0,100)>75)
                        {

                           reproduction(ind,NULL,sim);

                        }
                    }
                }
                proche=quiEstProche(ind,sim);
                if(proche!=NULL)
                {
                    if(proche->espece->type==ind->espece->type)
                    {
                        if(proche->espece==ind->espece)
                        {
                            if(proche->sexe!=ind->sexe)
                            {
                                if((ind->derniereReproduction+ind->espece->delaiProchaineReproduction)<(sim->tempsPasse))
                                {
                                    reproduction(ind,proche,sim);
                                }
                            }

                        }

                    }
                    else
                    {
                       mangee=manger(ind,proche);
                    }



                }
                if(mangee==false)
                {
                    if(((ind->espece->dureeVieMoyenne+ind->naissance)<sim->tempsPasse)||(ind->sante==0))//durée de vie de l'individu
                    {
                        if(Random(0,100)>90)
                        {

                            mortIndividu(ind);

                        }
                    }

                }

        ind=indSuiv;
        }

        espece=espece->suivante;
    }


}