Logo Search packages:      
Sourcecode: tablix2 version File versions  Download package

population* population_init ( population pop,
int  size 
)

Initializes population structure.

All resources, resource types and tuples (events) must be defined before calling this function.

If pop is NULL, a new structure with population size size is allocated using the number of tuples and resource types. If pop is not NULL then only proper links to resources, etc. are made.

Checks are also performed to see if population pop is compatible with the number of defined resource types, etc. size parameter is not used in this case.

Parameters:
pop Pointer to the population structure to be initialized.
size Size of the population.
Returns:
Pointer to the initialized structure on success and NULL on error.

Definition at line 1301 of file data.c.

References table_t::chr, dat_tuplenum, dat_typenum, error(), chromo_t::gennum, mod_fitnessnum, population_new(), population_t::size, table_t::subtotals, table_init(), population_t::tables, and table_t::typenum.

{
      population *dest;
      int new;
      int n,m;
      
      assert(size>0);
      assert(dat_typenum>0);
      assert(dat_tuplenum>0);

      new=(pop==NULL);

      if(new) {
            dest=population_new(size, dat_typenum, dat_tuplenum);
            if(dest==NULL) {
                  error(_("Can't allocate memory"));
                  return(NULL);
            }
      } else {
            assert(pop->size>0);
            assert(pop->tables!=NULL);
            if(pop->tables[0]->typenum!=dat_typenum||
                        pop->tables[0]->chr[0].gennum!=dat_tuplenum) {
                  error(_("Size of the saved population does not match "
                        "the configuration"));
                  return(NULL);
            }
            dest=pop;
      }

      for(n=0;n<dest->size;n++) {
            assert(dest->tables[n]->typenum==dat_typenum);

            m=sizeof(*dest->tables[n]->subtotals)*mod_fitnessnum;
            dest->tables[n]->subtotals=malloc(m);
            if(dest->tables[n]->subtotals==NULL) {
                  error(_("Can't allocate memory"));
                  for(m=0;m<n;m++) {
                        free(dest->tables[m]->subtotals);
                  }
                  if(new) free(dest);
                  return(NULL);
            }

            if(table_init(dest->tables[n], new)) {
                  error(_("Saved population and configuration "
                        "do not match"));
                  return(NULL);
            }
      }

      return(dest);
}


Generated by  Doxygen 1.6.0   Back to index