当前位置: 首页>>代码示例>>C++>>正文


C++ GAErr函数代码示例

本文整理汇总了C++中GAErr函数的典型用法代码示例。如果您正苦于以下问题:C++ GAErr函数的具体用法?C++ GAErr怎么用?C++ GAErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GAErr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

// This works only for enumerated sets.  If someone tries to use this on a
// non-enumerated set then we post an error message.  No bounds checking on 
// the value that was passed to us, but we do modulo it so that we'll never
// break.  Also, this means you can wrap an allele set around an array that
// is significantly larger than the allele set that defines its contents.
template <class T> T
GAAlleleSet<T>::allele(unsigned int i) const {
  if(core->type == GAAllele::ENUMERATED)
    return core->a[i % core->sz];
  else if(core->type == GAAllele::DISCRETIZED){
    GAErr(GA_LOC, "GAAlleleSet", "allele(unsigned int)", gaErrOpUndef);
    return core->a[0];
  }
  else{
    GAErr(GA_LOC, "GAAlleleSet", "allele(unsigned int)", gaErrNoAlleleIndex);
    return core->a[0];
  }
}
开发者ID:NemanjaFilipovic,项目名称:garbage_truck_automation,代码行数:18,代码来源:GAAllele.C

示例2: resizeBehaviour

template <class T> int
GA3DArrayGenome<T>::
resizeBehaviour(GAGenome::Dimension which, 
		unsigned int lower, unsigned int upper)
{
  if(upper < lower){
    GAErr(GA_LOC, className(), "resizeBehaviour", gaErrBadResizeBehaviour);
    return resizeBehaviour(which);
  }

  switch(which){
  case WIDTH:
    minX = lower; maxX = upper;
    if(nx > upper) GA3DArrayGenome<T>::resize(upper,ny,nz);
    if(nx < lower) GA3DArrayGenome<T>::resize(lower,ny,nz);
    break;

  case HEIGHT:
    minY = lower; maxY = upper;
    if(ny > upper) GA3DArrayGenome<T>::resize(nx,upper,nz);
    if(ny < lower) GA3DArrayGenome<T>::resize(nx,lower,nz);
    break;

  case DEPTH:
    minZ = lower; maxZ = upper;
    if(nz > upper) GA3DArrayGenome<T>::resize(nx,ny,upper);
    if(nz < lower) GA3DArrayGenome<T>::resize(nx,ny,lower);
    break;

  default:
    break;
  }

  return resizeBehaviour(which);
}
开发者ID:backo880607,项目名称:YuKonSolution,代码行数:35,代码来源:GA3DArra.cpp

示例3: resizeBehaviour

int
GA2DBinaryStringGenome::
resizeBehaviour(Dimension which, unsigned int lower, unsigned int upper)
{
  if(upper < lower){
    GAErr(GA_LOC, className(), "resizeBehaviour", gaErrBadResizeBehaviour);
    return resizeBehaviour(which);
  }

  switch(which){
  case WIDTH:
    minX = lower; maxX = upper;
    if(nx > upper) resize(upper,ny);
    if(nx < lower) resize(lower,ny);
    break;

  case HEIGHT:
    minY = lower; maxY = upper;
    if(ny > upper) resize(nx,upper);
    if(ny < lower) resize(nx,lower);
    break;

  default:
    break;
  }

  return resizeBehaviour(which);
}
开发者ID:boogerlad,项目名称:pngwolf,代码行数:28,代码来源:GA2DBinStrGenome.C

示例4: GAErr

const GAPopulation&
GASteadyStateGA::population(const GAPopulation& p) {
  if(p.size() < 1) {
    GAErr(GA_LOC, className(), "population", gaErrNoIndividuals);
    return *pop;
  }

  GAGeneticAlgorithm::population(p);
  delete tmpPop;

  if(which == USE_PREPL){
    double n = pRepl * pop->size();
    if(n < 1) n = 1.0;
    nRepl = (unsigned int)n;
    params.set(gaNnReplacement, nRepl);
  }
  else{
    if(nRepl > (unsigned int)(pop->size())) nRepl = pop->size();
    if(nRepl < 1) nRepl = 1;
  }
  tmpPop = new GAPopulation(pop->individual(0), nRepl);
  tmpPop->geneticAlgorithm(*this);

  return *pop;
}
开发者ID:DukhangLee,项目名称:SKIRT,代码行数:25,代码来源:GASStateGA.cpp

示例5: GAErr

// Resize the population.  If we shrink, we delete the extra genomes.  If
// we grow, we clone new ones (and we DO NOT initialize them!!!).  When we
// trash the genomes, we delete the worst of the population!  We do not
// free up the space used by the array of pointers, but we do free up the
// space used by the genomes.
//   We do a clone of the genome contents so that we don't have to initialize
// the new ones (what if the population has a custom initilizer?).  We randomly
// pick which ones to clone from the existing individuals.  If the population
// contains no genomes, then we post an error message (since there are no
// individuals from which to clone the new ones).
//   If the population was evaluated, then we evaluate the new genomes.  We
// do not sort nor restat the population, and we tag the statted and sorted
// flags to reflect the fact that they are no longer valid.
//   Resizing to a bigger size is the same as a batch 'add'
int
GAPopulation::size(unsigned int popsize){
  if(popsize == n) return n;
  if(n == 0 && popsize > 0) {
    GAErr(GA_LOC, "GAPopuluation", "size", gaErrNoIndividuals);
    return n;
  }

  if(popsize > n){
    grow(popsize);
    for(unsigned int i=n; i<popsize; i++)
      rind[i] = rind[GARandomInt(0,n-1)]->clone(GAGenome::CONTENTS);
    rsorted = gaFalse;
  }
  else{
    for(unsigned int i=popsize; i<n; i++) // trash the worst ones (if sorted)
      delete rind[i];			  // may not be sorted!!!!
  }

  memcpy(sind, rind, N * sizeof(GAGenome*));
  ssorted = scaled = statted = divved = selectready = gaFalse;
  n = popsize;  

  if(evaluated == gaTrue) evaluate(gaTrue);

  return n;
}
开发者ID:dbremner,项目名称:galib,代码行数:41,代码来源:GAPopulation.C

示例6: while

int
GA2DBinaryStringGenome::read(STD_ISTREAM & is)
{
  static char c;
  unsigned int i=0, j=0;
  while(!is.fail() && !is.eof() && j < ny) {
    is >> c;
    if(isdigit(c)){
      gene(i, j, ((c == '0') ? 0 : 1));
      if(++i >= nx){		// ready for next row
	i=0;
	j++;
      }
    }
  }

  _evaluated = gaFalse;

  if(is.eof() && 
     ((j < ny) ||	     // didn't get some lines
      (i < nx && i != 0))){   // stopped early on a row
    GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
    is.clear(STD_IOS_BADBIT | is.rdstate());
    return 1;
  }

  return 0;
}
开发者ID:boogerlad,项目名称:pngwolf,代码行数:28,代码来源:GA2DBinStrGenome.C

示例7: strcmp

/// Must do a special case for double/float.  Any floats that get passed to this
/// routine will be cast to doubles, but then we need to force them back to a
/// float if FLOAT is the type that is expected.  Kind of sucks, eh?
///   We could check the parameter type against the type here, but we don't.
/// (could do it for all of the 'set' members).  Maybe in a later release.
int
GAParameterList::set(const char* name, double v)
{
    int found = 0;
    for(unsigned int i = 0; i < n; i++)
    {
        if(strcmp(name, p[i]->fullname()) == 0 ||
                strcmp(name, p[i]->shrtname()) == 0)
        {
            if(p[i]->type() == GAParameter::FLOAT)
            {
                float fval = (float)v;
                p[i]->value((void*)&fval);
            }
            else if(p[i]->type() == GAParameter::DOUBLE)
            {
                p[i]->value((void*)&v);
            }
            else
            {
                GAErr(GA_LOC, "GAParameterList", "set", gaErrBadTypeIndicator);
            }
            found = 1;
        }
    }
    return found ? 0 : -1;
}
开发者ID:pemryan,项目名称:GAlib,代码行数:32,代码来源:GAParameter.C

示例8: GAErr

// Remove the specified node from the tree.  We don't cruise through the tree
// to make certain that the node is in the tree.  But we do check to make sure
// that the connections were ok before we prune the node.  If there is any
// problem with the links, we return a NULL.  If we get a NULL node, then we
// don't do anything.
//   We don't do anything to the next, prev, etc links of the node that is
// being removed (they are left pointing to where they used to point) so be
// careful!!
//   If the removal is on the root node, set the root node to NULL.
GANodeBASE *
GATreeBASE::remove(GANodeBASE * n)
{
  if(!n) return (GANodeBASE *)0;

  if(!n->next || !n->prev || n->prev->next != n || n->next->prev != n){
    GAErr(GA_LOC, "GATreeBASE", "remove", gaErrBadTreeLinks);
    return (GANodeBASE*)0;
  }

  if(n->next == n || !n->next){
    if(n->parent && n->parent->child == n)
      n->parent->child = (GANodeBASE *)0;
  }
  else{
    if(n->parent && n->parent->child == n)
      n->parent->child = n->next;
    n->prev->next = n->next;
    n->next->prev = n->prev;
  }

  if(n == rt) rt = (GANodeBASE *)0;

// uncomment these to modify the node that is getting removed
  n->prev = n;
  n->next = n;
  n->parent = 0;

  csz = 1;
  cdpth = 1;
  return n;
}
开发者ID:backo880607,项目名称:YuKonSolution,代码行数:41,代码来源:GATreeBA.cpp

示例9: GAErr

// Set the bits of the binary string based on the decimal value that is passed
// to us.  Notice that the number you pass may or may not be set properly.  It
// depends on the resolution defined in the phenotype.  If you didn't define 
// enough resolution, then there may be no way to represent the number.
//   We round off to the closest representable value, then return the number 
// that we actually entered (the rounded value).
// *** this is dangerous!  we're accessing the superclass' data representation
// directly, so if the representation changes to a bit stream, this will break.
//   If someone tries to set the phenotype beyond the bounds, we post an error
// then set the bits to the closer bound.
float
GABin2DecGenome::phenotype(unsigned int n, float val)
{
  if(n >= ptype->nPhenotypes()){
    GAErr(GA_LOC, className(), "phenotype", gaErrBadPhenotypeID);
    return val;
  }
  if(val < ptype->min(n) || val > ptype->max(n)){
    GAErr(GA_LOC, className(), "phenotype", gaErrBadPhenotypeValue);
    val = ((val < ptype->min(n)) ? ptype->min(n) : ptype->max(n));
  }
  encode(val,
	 &(data[ptype->offset(n)]), ptype->length(n),
	 ptype->min(n), ptype->max(n));
  return val;
}
开发者ID:B0RJA,项目名称:GAlib-mpi,代码行数:26,代码来源:GABin2DecGenome.C

示例10: gene

int
GA3DBinaryStringGenome::read(std::istream & is)
{
  static char c;
  unsigned int i=0, j=0, k=0;
  do{
    is >> c;
    if(isdigit(c)){
      gene(i++, j, k, ((c == '0') ? 0 : 1));
      if(i >= nx){
	i=0;
	j++;
      }
      if(j >= ny){
	j=0;
	k++;
      }
    }
  } while(!is.fail() && !is.eof() && k < nz);

  _evaluated = gaFalse;

  if(is.eof() && 
     ((k < nz) ||		// didn't get some lines
      (j < ny && j != 0) ||	// didn't get some lines
      (i < nx && i != 0))){	// didn't get some lines
    GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
    is.clear(std::ios::badbit | is.rdstate());
    return 1;
  }

  return 0;
}
开发者ID:backo880607,项目名称:YuKonSolution,代码行数:33,代码来源:GA3DBinS.cpp

示例11: GAErr

const GAGenome & 
GAStatistics::bestIndividual(unsigned int n) const {
  if(boa == 0 || (int)n >= boa->size()){
    GAErr(GA_LOC, "GAStatistics", "bestIndividual", gaErrBadPopIndex);
    n = 0;
  }
  return boa->best(n);		// this will crash if no boa
}
开发者ID:boogerlad,项目名称:pngwolf,代码行数:8,代码来源:GAStatistics.C

示例12: GAErr

// Set the multiplier for this selection type.  It should be greater than or
// equal to zero.
float
GASigmaTruncationScaling::multiplier(float fm) {
  if(fm < 0.0){
    GAErr(GA_LOC, className(), "multiplier", gaErrBadSigmaTruncationMult);
    return c;
  }
  return c = fm;
}
开发者ID:B0RJA,项目名称:GAlib-mpi,代码行数:10,代码来源:GAScaling.C

示例13: GAErr

GAAlleleSetCore<T>::~GAAlleleSetCore()
{
    if(cnt > 0)
    {
        GAErr(GA_LOC, "GAAlleleSetCore", "destructor", gaErrRefsRemain);
    }
    delete [] a;
}
开发者ID:distanceModling,项目名称:GAlib,代码行数:8,代码来源:GAAllele.C

示例14: GAErr

// This is the class-specific copy method.  It will get called by the super
// class since the superclass operator= is set up to call ccopy (and that is
// what we define here - a virtual function).  We should check to be sure that
// both genomes are the same class.
void
BitStringGenome::copy(const GAGenome & orig) {
  if(&orig == this) return;
  if(!sameClass(orig)){
    GAErr(GA_LOC, className(), "copy", gaErrObjectTypeMismatch);
    return;
  }
  GAGenome::copy(orig);
  BitStringGenome &bsg = (BitStringGenome &)orig;
  BitString::operator=(bsg._substr(0,bsg.length()));
}
开发者ID:Aerobota,项目名称:2015VisionCode,代码行数:15,代码来源:bitstr.C

示例15: GAErr

int
GAIncrementalGA::nOffspring(unsigned int value){
  if(value != 1 && value != 2){
    GAErr(GA_LOC, className(), "numCrossStrategy", gaErrBadCS);
    noffspr = 1;
  }
  else{
    noffspr = value;
  }
  params.set(gaNnOffspring, value);
  return noffspr;
}
开发者ID:DukhangLee,项目名称:SKIRT,代码行数:12,代码来源:GAIncGA.cpp


注:本文中的GAErr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。