Skip to content

General structure of the code

frederic-michaud edited this page Dec 14, 2017 · 5 revisions

General structure of the code

basic idea

The general structure of the code is organised arround the class TMetapopulation. The Tmetapopulation contain individuals, who contain their genetic code. The population then goes through a loop over the generation, and an inner loop over the different life cycle events (breeding, dispersal, extinction, etc).

We can therefore classify most of the according to the following logic:

  • Class which are life cycle event (starting with lce_): take care of a particular life event in the life of each individual.
  • Class which take care of interaction with the user, building simulation from the input file and writting the statistic.
  • Class which are related to individual and their genetics
  • Accessory class use to perform technical operation like matrix operation, array gestion or (pseudo-)random generation.

The class TMetapop

Top class of the metapopulation structure, contains patches, implements the replicate and generation loops. This class implements the two main loops of a simulation, the replicate and the generation loops. The replicate loop iterates the generation loop which itself iterates the life cycle loop composed of the LCEs selected by the user.

The basic design for the metapopulation structure is a top-down chain of responsibility where the Metapop class takes care of the patches it contains which are themselves concerned by the management of their individual containers. The Individual class is only concerned by the management of its traits. Thereby, a metapopulation can be viewed as an interleaving of containers where one container class takes care of its directly contained class only, without knowledge of the upward container state.

The Metapop class thus implements methods used to manage and get information from the patches, to manage the parameters necessary to build a population and to get the population state information.

Population states:given by the number and the position of the individuals (both spatially in demes and temporally in age class containers). The Metapop::_currentAge flag is set according to the age state of the metapopulation. The life cycle events modify that state by moving individuals between individuals containers within the metatpopulation. The Metapop::_currentAge flag can contain the following age class bits as defined in types.h. The OFFSPRNG (=1) age class bit is set whenever the offspring containers are not empty. The ADULTS (=2) age class bit is set whenever the adult containers are not empty. The ALL (=3) age class is the addition of the previous tags and NONE (=0) is the negation of them. The individual containers are stored in the patches and handled through the Patch class interface. Each age class is represented by two containers, one for the males (index 0) and the other for the females (index 1). These containers are store in a table and are accessed through their age class index as defined by the age_idx enum (see types.h). These indexes are as follows:

  • The OFFSPRNG age class has index OFFSx = 0,
  • and the ADULTS age class has index ADLTx = 2.

Prototype in metapopulation

Each individual is mainly defined by it's genetics, formally defined in QuantiNemo with the classes TGenome and the class TTrait. However, some characteristic of the genome are shared among all the population (like the number of loci, number of chromosome, mutation frequency, etc) while other value are specific to each individual (in particular the exact genetic information, i.e. the DNA).

To handle this fact, QuantiNemo define classes which are prototypes. There is in general only one instance (or two, one for male and one for female) of object of the type prototype, which is shared among the population. Each individual then posses it's own genome, with a pointer to the prototype genome. In particular:

  • each individual posses a TGenome, with a pointer toward TGenomeProto
  • each individual posses a TTrait, with a pointer toward TTraitProto
  • If selection act, each individual posses a TTquanti, with a pointer toward TTquantiProto Notice also that in general, input parameter are used to define the caracteristic of the genome, shared among population. Therefore, the *Proto class inherit from the class SimComponent.

How does selection act (breeding level)

The selection is in general active during breeding. During breeding, the method makeOffsprg of IndFactory call, indirectly the method 'TTraitQuanti::set_value()' to set the genotype and phenotype value of the individual. However, the fitness itself is not computed before they are grown up, i.e. just before reproduction. It is done through the method 'TSelection::set_fitness' which set the fitness of each individual, and then set an array with all the fitness of the individual. Finally the parent of every new individual are selected using function such as 'TPatchFitness::get_RAND_mostFit()'.