Nemo  2.3.46
LCE_Cross Class Reference

A class to perform crosses within patches, implements the NC1 mating design. More...

#include <LCEmisc.h>

+ Inheritance diagram for LCE_Cross:
+ Collaboration diagram for LCE_Cross:

Public Member Functions

 LCE_Cross ()
 
virtual ~LCE_Cross ()
 
void sampleAmongPop (Patch *patch, deque< Individual * > &males, unsigned int nsire)
 
void sampleWithinPop (Patch *patch, deque< Individual * > &males, deque< Individual * > &females, unsigned int nsire)
 
void generatePedigree ()
 
bool create_individual_ancestors (Individual *ind)
 
virtual bool setParameters ()
 
virtual void execute ()
 
virtual LifeCycleEventclone ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual age_t removeAgeClass ()
 
virtual age_t addAgeClass ()
 
virtual age_t requiredAgeClass ()
 
- Public Member Functions inherited from LifeCycleEvent
 LifeCycleEvent (const char *name, const char *trait_link)
 Cstor. More...
 
virtual ~LifeCycleEvent ()
 
virtual void init (Metapop *popPtr)
 Sets the pointer to the current Metapop and the trait link if applicable. More...
 
virtual bool attach_trait (string trait)
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 
virtual void set_event_name (std::string &name)
 Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set. More...
 
virtual void set_event_name (const char *name)
 
virtual string & get_event_name ()
 Accessor to the LCE's name. More...
 
virtual int get_rank ()
 Accessor to the LCE rank in the life cycle. More...
 
virtual void set_pop_ptr (Metapop *popPtr)
 Accessors for the population pointer. More...
 
virtual Metapopget_pop_ptr ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 

Private Attributes

unsigned int _nSire
 
unsigned int _nDam
 
unsigned int _nOffspring
 
unsigned int _atGeneration
 
bool _doAmongPop
 
bool _doWithinPop
 
bool _doReplace
 
FHPedigreeReader_reader
 
string _pedigree_file
 
map< unsigned long, Individual * > _pedigree_pop
 

Additional Inherited Members

- Protected Attributes inherited from LifeCycleEvent
std::string _event_name
 The param name to be read in the init file. More...
 
Metapop_popPtr
 The ptr to the current Metapop. More...
 
std::string _LCELinkedTraitType
 The name of the linked trait. More...
 
int _LCELinkedTraitIndex
 The index in the individual's trait table of the linked trait. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Detailed Description

A class to perform crosses within patches, implements the NC1 mating design.

Constructor & Destructor Documentation

LCE_Cross::LCE_Cross ( )

References SimComponent::add_parameter(), BOOL, INT, setParameters(), and STR.

Referenced by clone().

379  : LifeCycleEvent("cross",""), _nSire(0), _nDam(0), _nOffspring(0),
380 _atGeneration(0), _reader(0)
381 {
383  add_parameter("cross_num_sire", INT, 0, 0, 0, 0, updater);
384  add_parameter("cross_num_dam", INT, 0, 0, 0, 0, updater);
385  add_parameter("cross_num_offspring", INT, 0, 0, 0, 0, updater);
386  add_parameter("cross_at_generation", INT, 1, 0, 0, 0, updater);
387  add_parameter("cross_do_among_pop", BOOL, 0, 0, 0, 0, updater);
388  add_parameter("cross_do_within_pop", BOOL, 0, 0, 0, 0, updater);
389  add_parameter("cross_with_replacement", BOOL, 0, 0, 0, 0, updater);
390 
391  add_parameter("cross_with_pedigree_file", STR, 0, 0, 0, 0, updater);
392 
393 }
virtual bool setParameters()
Definition: LCEmisc.cc:397
Implementation of the ParamUpdaterBase interface.
Definition: param.h:348
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
unsigned int _nOffspring
Definition: LCEmisc.h:164
unsigned int _nDam
Definition: LCEmisc.h:163
unsigned int _nSire
Definition: LCEmisc.h:163
Definition: types.h:78
Definition: types.h:78
FHPedigreeReader * _reader
Definition: LCEmisc.h:168
unsigned int _atGeneration
Definition: LCEmisc.h:165
Definition: types.h:78
virtual LCE_Cross::~LCE_Cross ( )
inlinevirtual
175 { }

Member Function Documentation

virtual age_t LCE_Cross::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

References OFFSPRG.

191 {return OFFSPRG;}
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
virtual LifeCycleEvent* LCE_Cross::clone ( )
inlinevirtual

Implements LifeCycleEvent.

References LCE_Cross().

185 {return new LCE_Cross();}
LCE_Cross()
Definition: LCEmisc.cc:379
bool LCE_Cross::create_individual_ancestors ( Individual ind)

References _pedigree_pop, LifeCycleEvent::_popPtr, ADLTx, Individual::create(), Individual::create_first_gen(), FEM, Metapop::get(), Individual::getFather(), Individual::getFatherID(), Individual::getID(), Individual::getMother(), Individual::getMotherID(), IndFactory::makeNewIndividual(), MAL, Individual::setFather(), Individual::setFatherID(), Individual::setMother(), Individual::setMotherID(), Metapop::size(), and RAND::Uniform().

Referenced by generatePedigree().

580 {
581  Individual *mother = ind->getMother();
582  Individual *father = ind->getFather();
583  unsigned long sire = ind->getFatherID();
584  unsigned long dam = ind->getMotherID();
585 
586  //the individual is set when the mum and dad ptrs are set, exit
587  if(mother && father) return true;
588 
589  //check parents' ID for sampling in the whole pop; choose individuals in first patch
590  if(dam == 0) {
591 
592  if(_popPtr->size(FEM, ADLTx, 0) != 0) {
593 
594  mother = _popPtr->get(FEM, ADLTx, RAND::Uniform( _popPtr->size(FEM, ADLTx, 0) ), 0);
595 
596  } else {
597  mother = _popPtr->makeNewIndividual(0, 0, FEM, 0);
598  mother->create_first_gen();
599  }
600 
601  ind->setMother(mother);
602  ind->setMotherID(mother->getID());
603 
604  } else if( !mother ) {
605 
607  ind->setMother(_pedigree_pop[ dam ]);
608  }
609  }
610 
611  //father
612  if(sire == 0) {
613 
614  if(_popPtr->size(MAL, ADLTx, 0) != 0 ) {
615 
616  father = _popPtr->get(MAL, ADLTx, RAND::Uniform( _popPtr->size(MAL, ADLTx, 0) ), 0);
617 
618  } else {
619  father = _popPtr->makeNewIndividual(0, 0, MAL, 0);
620  father->create_first_gen();
621  }
622 
623  ind->setFather(father);
624  ind->setFatherID(father->getID());
625 
626  } else if(!father) {
627 
629  ind->setFather( _pedigree_pop[ sire ] );
630 
631  }
632 
633  mother = ind->getMother();
634  father = ind->getFather();
635 
636  if(mother && father) {
637 
638 // cout << "create "<<ind->getID()<<" ("<<mother->getID()<<" + "<<father->getID()<<") "
639 // <<"("<<dam<<" + "<<sire<<")\n";
640 
641  ind->create(true, true); //create with inheritance and mutation
642  }
643 
644  return( mother && father ); //return false when parents are not created
645 }
unsigned long getID()
Definition: individual.h:122
void setFather(Individual *f)
Definition: individual.h:109
void setFatherID(unsigned long value)
Definition: individual.h:107
Individual * makeNewIndividual(Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Creates an individual with pointers to parents, sex and home ID set but no genetic data...
Definition: indfactory.cc:152
bool create_individual_ancestors(Individual *ind)
Definition: LCEmisc.cc:579
Individual * getFather()
Definition: individual.h:126
unsigned long getMotherID()
Definition: individual.h:125
void setMotherID(unsigned long value)
Definition: individual.h:108
Individual * getMother()
Definition: individual.h:127
Individual * create_first_gen()
Creates an individual's genotypes and phenotypes for first generation.
Definition: individual.h:348
unsigned long getFatherID()
Definition: individual.h:124
void setMother(Individual *m)
Definition: individual.h:110
Individual * create()
Creates an individual's genotypes and phenotypes with recombination and mutations.
Definition: individual.h:362
map< unsigned long, Individual * > _pedigree_pop
Definition: LCEmisc.h:170
Definition: types.h:42
Individual * get(sex_t SEX, age_idx AGE, unsigned int at, unsigned int deme)
Returns a pointer to the appropriate individual.
Definition: metapop.h:783
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
Definition: types.h:37
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
Definition: types.h:37
void LCE_Cross::execute ( )
virtual

Implements LifeCycleEvent.

References _atGeneration, _doAmongPop, _doWithinPop, _nSire, LifeCycleEvent::_popPtr, ADLTx, FEM, Metapop::flush(), generatePedigree(), SimComponent::get_parameter(), Patch::getCopy(), Metapop::getCurrentGeneration(), Metapop::getPatch(), Metapop::getPatchNbr(), Param::isSet(), MAL, message(), OFFSPRG, sampleAmongPop(), sampleWithinPop(), Metapop::size(), Patch::size(), and warning().

453 {
454  Patch* patch;
455  unsigned int nsire;
456  deque<Individual*> males, females;
457 
458 #ifdef _DEBUG_
459  message("LCE_Cross::execute\n");
460 #endif
461 
462  if(_popPtr->getCurrentGeneration() != _atGeneration) return;
463 
464  if(get_parameter("cross_with_pedigree_file")->isSet())
465 
467 
468  else {
469 
470  if(_popPtr->size(OFFSPRG) != 0) {
471  warning("Offspring are still present at time of crossing, flushing\n");
473  }
474 
475  for(unsigned int i = 0; i < _popPtr->getPatchNbr(); i ++) {
476 
477  patch = _popPtr->getPatch(i);
478 
479  if(patch->size(MAL, ADLTx) == 0) continue;
480 
481  if(_nSire > patch->size(MAL, ADLTx)) {
482  warning("LCE_Cross:: num_sire greater than actual number of males in patch %i, reseting.\n", patch->size(MAL, ADLTx));
483  nsire = patch->size(MAL, ADLTx);
484  } else
485  nsire = _nSire;
486 
487  males.clear();
488  patch->getCopy(MAL, ADLTx, males);
489 
490  if(_doAmongPop) sampleAmongPop(patch, males, nsire);
491 
492  males.clear();
493  females.clear();
494 
495  if(patch->size(FEM, ADLTx) == 0) continue;
496 
497 
498  if(_doWithinPop) {
499  patch->getCopy(MAL, ADLTx, males);
500  patch->getCopy(FEM, ADLTx, females);
501  sampleWithinPop(patch, males, females, nsire);
502  }
503  }
504  }
505 }
void message(const char *message,...)
Definition: output.cc:40
void generatePedigree()
Definition: LCEmisc.cc:509
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
void getCopy(sex_t SEX, age_idx AGE, deque< Individual * > &to)
Definition: metapop.h:673
bool _doAmongPop
Definition: LCEmisc.h:166
unsigned int getCurrentGeneration()
Definition: metapop.h:286
void sampleWithinPop(Patch *patch, deque< Individual * > &males, deque< Individual * > &females, unsigned int nsire)
Definition: LCEmisc.cc:688
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
bool _doWithinPop
Definition: LCEmisc.h:166
unsigned int getPatchNbr()
Definition: metapop.h:270
void sampleAmongPop(Patch *patch, deque< Individual * > &males, unsigned int nsire)
Definition: LCEmisc.cc:649
void warning(const char *str,...)
Definition: output.cc:56
Definition: types.h:42
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:796
Definition: types.h:37
unsigned int _nSire
Definition: LCEmisc.h:163
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
unsigned int _atGeneration
Definition: LCEmisc.h:165
bool isSet()
Definition: param.h:138
void LCE_Cross::generatePedigree ( )

References _pedigree_file, _pedigree_pop, LifeCycleEvent::_popPtr, _reader, Patch::add(), create_individual_ancestors(), error(), FEM, FHPedigreeReader::FHread(), Metapop::flush(), Metapop::getCurrentReplicate(), Metapop::getPatch(), FHPedigreeReader::getPedigree(), IndFactory::getPrototypeClone(), Individual::init(), OFFSPRG, OFFSx, Metapop::setCurrentAge(), Individual::setFatherID(), Individual::setID(), Individual::setMotherID(), and warning().

Referenced by execute().

510 {
511  Individual* ind;;
512 
513  //read the pedigree file only once per simulation:
514  if(_popPtr->getCurrentReplicate() == 1) {
515 
517 
518  }
519 
520  vector< unsigned long * > pedigree = _reader->getPedigree();
521 
522  _pedigree_pop.clear();
523 
524  //read in the individual ID of each record and create individuals
525  for(unsigned int i = 0; i < pedigree.size(); ++i) {
526 
527 // cout<<"\nrecord #"<<i+1<<endl;
528 
529  if(_pedigree_pop.find(pedigree[i][0]) != _pedigree_pop.end())
530  warning("found duplicated ID %i in pedigree, replacing it with latest record"
531  , pedigree[i][0]);
532  else
533  _pedigree_pop[ pedigree[i][0] ] = _popPtr->getPrototypeClone();
534 
535 // cout<<"\nsetting new ind in pedigree: "<<pedigree[i][0]<<" "<<pedigree[i][1]
536 // <<" "<<pedigree[i][2]<<"\n";
537  ind = _pedigree_pop[ pedigree[i][0] ];
538 
539  ind->init(); //need to allocate traits' memory; warning: sets parents' ID to 0!!!
540  ind->setID( pedigree[i][0] );
541  ind->setFatherID( pedigree[i][1] );
542  ind->setMotherID( pedigree[i][2] );
543 
544 // ind->show_up();
545  }
546 
547  //create the genetics
548  map< unsigned long, Individual*>::const_iterator REC = _pedigree_pop.begin();
549 
550  while(REC != _pedigree_pop.end()) {
551 
552  //recursively create ancestors of an individual, and the individual by inheritance
553  // adding mutations as well
554  if(!create_individual_ancestors( REC->second ))
555  error("while creating individuals on a pedigree (ID=%i)\n",REC->first);
556 
557  REC++;
558  }
559 
560  //deal with pedigreed population
561  //for now, empty all patches and dump the ped pop in the first patch (offspring fems)
562  _popPtr->flush();
564 
565  Patch* patch = _popPtr->getPatch(0);
566 
567  REC = _pedigree_pop.begin();
568  while(REC != _pedigree_pop.end()) {
569 
570  patch->add(FEM, OFFSx, REC->second);
571 
572  REC++;
573  }
574 
575 }
void setFatherID(unsigned long value)
Definition: individual.h:107
bool create_individual_ancestors(Individual *ind)
Definition: LCEmisc.cc:579
void setMotherID(unsigned long value)
Definition: individual.h:108
vector< unsigned long * > & getPedigree()
Definition: LCEmisc.h:207
void setID(unsigned long value)
Definition: individual.h:104
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:293
int error(const char *str,...)
Definition: output.cc:73
unsigned int getCurrentReplicate()
Definition: metapop.h:285
map< unsigned long, Individual * > _pedigree_pop
Definition: LCEmisc.h:170
void warning(const char *str,...)
Definition: output.cc:56
string _pedigree_file
Definition: LCEmisc.h:169
void flush()
Removes all individual pointers and flush them into the recycling pool.
Definition: metapop.h:796
virtual void FHread(string &filename)
Definition: LCEmisc.cc:736
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
Individual * init()
Inits parameters and traits.
Definition: individual.cc:53
Individual * getPrototypeClone()
Return an uninitialized copy of the individual prototype.
Definition: indfactory.h:79
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it...
Definition: metapop.h:540
Definition: types.h:37
FHPedigreeReader * _reader
Definition: LCEmisc.h:168
void LCE_Cross::loadFileServices ( FileServices loader)
virtual

Implements SimComponent.

References _atGeneration, _pedigree_file, _reader, FileServices::attach_reader(), SimComponent::get_parameter(), Param::getArg(), EventFileHandler< LCE >::set(), and FileHandler::set_isInputHandler().

434 {
435  if( ! get_parameter("cross_with_pedigree_file")->isSet() ) return;
436 
437  if(_reader) delete _reader;
438  _reader = new FHPedigreeReader(this);
439  //set to read mode:
441  //attach to file manager:
442  loader->attach_reader(_reader);
443 
444  _pedigree_file = get_parameter("cross_with_pedigree_file")->getArg();
445 
446  _reader->set(true, false, 1, _atGeneration, 0, "", this);
447 
448 }
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path, LCE *event)
Definition: filehandler.h:265
virtual void attach_reader(FileHandler *FH)
Attaches the FileHandler to the current list (_readers) of the FileServices.
Definition: fileservices.cc:70
string _pedigree_file
Definition: LCEmisc.h:169
string getArg()
Definition: param.h:136
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
A class to read a pedigree from a file.
Definition: LCEmisc.h:199
FHPedigreeReader * _reader
Definition: LCEmisc.h:168
void set_isInputHandler(bool val)
Definition: filehandler.h:151
unsigned int _atGeneration
Definition: LCEmisc.h:165
virtual void LCE_Cross::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

189 {}
virtual age_t LCE_Cross::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

190 {return 0;}
virtual age_t LCE_Cross::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

References ADULTS.

192 {return ADULTS;}
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
void LCE_Cross::sampleAmongPop ( Patch patch,
deque< Individual * > &  males,
unsigned int  nsire 
)

References _doReplace, _nDam, _nOffspring, LifeCycleEvent::_popPtr, Patch::add(), ADLTx, ADULTS, FEM, Patch::get(), Patch::getID(), Metapop::getPatchNbr(), Metapop::getPatchPtr(), IndFactory::makeOffsprg(), OFFSx, Patch::size(), and RAND::Uniform().

Referenced by execute().

650 {
651  unsigned int at, deme, npatch = _popPtr->getPatchNbr();
652  Individual *sire, *dam;
653  Patch* aimedPatch;
654 
655  for(unsigned int s = 0; s < nsire; ++s) {
656 
657  //sampling parents
658  at = (unsigned int)RAND::Uniform( males.size() );
659 
660  sire = males[at];
661 
662  if( !_doReplace ) males.erase(males.begin() + at);
663 
664  for(unsigned int d = 0; d < _nDam; ++d) {
665  //sample a deme
666  do {
667  deme = (unsigned int)RAND::Uniform(npatch);
668  } while(deme == patch->getID() || patch->size(FEM, ADLTx) == 0);
669 
670  aimedPatch = _popPtr->getPatchPtr(deme);
671  //sample a female
672  dam = aimedPatch->get( FEM, ADLTx, (unsigned int)RAND::Uniform( aimedPatch->size(FEM, ADULTS) ) );
673 
674  if(dam == NULL) {d--; continue;}
675 
676  //mate and breed; ignore sex, put all offs in females' container
677  for(unsigned int k = 0; k < _nOffspring; ++k) {
678 
679  patch->add(FEM, OFFSx, _popPtr->makeOffsprg(dam, sire, FEM, patch->getID()) );
680 
681  }
682  }
683  }
684 }
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
Individual * makeOffsprg(Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Completely creates an individual with inheritance and mutations on all traits.
Definition: indfactory.cc:184
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
unsigned int getID()
Definition: metapop.h:469
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
unsigned int _nOffspring
Definition: LCEmisc.h:164
unsigned int getPatchNbr()
Definition: metapop.h:270
Definition: types.h:42
unsigned int _nDam
Definition: LCEmisc.h:163
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:254
Definition: types.h:42
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:523
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it...
Definition: metapop.h:540
Definition: types.h:37
bool _doReplace
Definition: LCEmisc.h:166
void LCE_Cross::sampleWithinPop ( Patch patch,
deque< Individual * > &  males,
deque< Individual * > &  females,
unsigned int  nsire 
)

References _doReplace, _nDam, _nOffspring, LifeCycleEvent::_popPtr, Patch::add(), ADLTx, FEM, Patch::getID(), IndFactory::makeOffsprg(), OFFSx, Patch::size(), RAND::Uniform(), and warning().

Referenced by execute().

689 {
690  unsigned int ndam, at;
691  Individual *sire, *dam;
692 
693  if(!_doReplace && nsire * _nDam > patch->size(FEM,ADLTx)) {
694  ndam = patch->size(FEM,ADLTx)/nsire;
695  warning("LCE_Cross:: total num of dam greater than available females in patch %i, reseting num_dam to %i.\n",patch->getID(), ndam);
696  } else
697  ndam = _nDam;
698 
699  if(nsire < 2 || ndam == 0) return;
700 
701  for(unsigned int s = 0; s < nsire; ++s) {
702 
703  //sampling parents
704  at = (unsigned int)RAND::Uniform( males.size() );
705 
706  sire = males[at];
707 
708  if( !_doReplace ) males.erase(males.begin() + at);
709 
710  for(unsigned int d = 0; d < ndam; ++d) {
711 
712  at = (unsigned int)RAND::Uniform( females.size() );
713 
714  dam = females[at];
715 
716  if( !_doReplace ) females.erase(females.begin() + at);
717 
718  //now mate and breed; ignore sex, put all offs in females' container
719  for(unsigned int k = 0; k < _nOffspring; ++k) {
720 
721  patch->add(FEM, OFFSx, _popPtr->makeOffsprg(dam, sire, FEM, patch->getID()) );
722 
723  }
724  }
725  }
726 }
Individual * makeOffsprg(Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Completely creates an individual with inheritance and mutations on all traits.
Definition: indfactory.cc:184
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
unsigned int getID()
Definition: metapop.h:469
unsigned int _nOffspring
Definition: LCEmisc.h:164
void warning(const char *str,...)
Definition: output.cc:56
Definition: types.h:42
unsigned int _nDam
Definition: LCEmisc.h:163
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
Definition: types.h:42
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it...
Definition: metapop.h:540
Definition: types.h:37
bool _doReplace
Definition: LCEmisc.h:166
bool LCE_Cross::setParameters ( )
virtual

Implements SimComponent.

References _atGeneration, _doAmongPop, _doReplace, _doWithinPop, _nDam, _nOffspring, _nSire, SimComponent::get_parameter(), SimComponent::get_parameter_value(), Param::getArg(), Param::isSet(), and tstring::str2int().

Referenced by LCE_Cross().

398 {
399  _nSire = (unsigned int)get_parameter_value("cross_num_sire");
400  _nDam = (unsigned int)get_parameter_value("cross_num_dam");
401  _nOffspring = (unsigned int)get_parameter_value("cross_num_offspring");
402  _atGeneration = (unsigned int)get_parameter_value("cross_at_generation");
403 
404  if(get_parameter("cross_do_among_pop")->isSet())
405  _doAmongPop = (unsigned int)get_parameter_value("cross_do_among_pop");
406  else
407  _doAmongPop = 0;
408 
409  string arg = get_parameter("cross_do_within_pop")->getArg();
410  if (tstring::str2int(arg) == 1) {
411  _doWithinPop = 1;
412  } else if (tstring::str2int(arg) == 0) {
413  _doWithinPop = 0;
414  } else {
415  _doWithinPop = 1;
416  }
417 
418  // if(get_parameter("cross_do_within_pop")->isSet())
419  // _doWithinPop = (unsigned int)get_parameter_value("cross_do_within_pop");
420  // else
421  // _doWithinPop = 1;
422 
423  if(get_parameter("cross_with_replacement")->isSet())
424  _doReplace = (unsigned int)get_parameter_value("cross_with_replacement");
425  else
426  _doReplace = 0;
427 
428  return true;
429 }
static int str2int(const string &str)
Converts a string into an integer.
Definition: tstring.h:73
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
bool _doAmongPop
Definition: LCEmisc.h:166
bool _doWithinPop
Definition: LCEmisc.h:166
unsigned int _nOffspring
Definition: LCEmisc.h:164
unsigned int _nDam
Definition: LCEmisc.h:163
string getArg()
Definition: param.h:136
unsigned int _nSire
Definition: LCEmisc.h:163
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
bool _doReplace
Definition: LCEmisc.h:166
unsigned int _atGeneration
Definition: LCEmisc.h:165
bool isSet()
Definition: param.h:138

Member Data Documentation

unsigned int LCE_Cross::_atGeneration
private
bool LCE_Cross::_doAmongPop
private

Referenced by execute(), and setParameters().

bool LCE_Cross::_doReplace
private
bool LCE_Cross::_doWithinPop
private

Referenced by execute(), and setParameters().

unsigned int LCE_Cross::_nDam
private
unsigned int LCE_Cross::_nOffspring
private
unsigned int LCE_Cross::_nSire
private

Referenced by execute(), and setParameters().

string LCE_Cross::_pedigree_file
private
map<unsigned long, Individual* > LCE_Cross::_pedigree_pop
private
FHPedigreeReader* LCE_Cross::_reader
private

The documentation for this class was generated from the following files:

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR