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


C++ Chromosome类代码示例

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


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

示例1: insertMutEvents

void Graph::insertMutEvents(nat genC, AddrArrayBackwardIter<Node,true> &mutBackIter, Node** nodeBufferNowGen, Chromosome &chrom, Randomness &rng)
{
    bool canGoBack = NOT mutBackIter.empty();

    nat chromId = chrom.getId();

    while(canGoBack && mutBackIter()->originGen == genC)
    {
        Node *node = mutBackIter();
        nat indiNr = node->indiNr;

        node->ancId1 = nodeBufferNowGen[indiNr] ? nodeBufferNowGen[indiNr]->id : NO_NODE ;

        // determine the base
        // :TODO: this currently does not allow for a double mutation occuring in one line
        node->base = chrom.mutateSite(rng, node->loc);

#ifdef DEBUG_HOOKUP
        cout << "MUT: [" << *node  << "]" << "\t===>"  << (nodeBufferNowGen[indiNr] ? nodeBufferNowGen[indiNr]->id : 0) << endl;
#endif

        nodeBufferNowGen[indiNr] = node;
        canGoBack = mutBackIter.back();
    }
}
开发者ID:aberer,项目名称:AnA-FiTS,代码行数:25,代码来源:Graph.cpp

示例2: progOpt

Simulation::Simulation(InfoFile &info, ProgramOptions &theProgOpt, ThreadPool &_tp)
  : progOpt(theProgOpt) 
  , numGen(progOpt.getNumberOfGenerations())
  , tp(_tp)
{

  // create chromosomes 
  Randomness &rng = tp[0].getRNG();
  vector<seqLen_t> lengths = progOpt.get<vector<seqLen_t> >("length");  
  nat idC = 0; 

  nat numPop = 1; 		// TODO pops 
  
  for(auto& length : lengths)
    {
      FitnessFunction fFun(progOpt.get<vector<string>>("selCoef"));
      Chromosome* chromo = new Chromosome(length, theProgOpt.hasOption("neutral"), fFun, idC++, numPop);
      chromo->init(rng);
      chromosomes.push_back(chromo); 
    }

  // create parameters of populations 
  vector<nat> popSizes = progOpt.get<vector<nat> >("popSize"); 
  assert(popSizes.size() == 1 );
  popParams.push_back( PopulationParams(0, numGen, popSizes[0], progOpt));  

  fractionalSimulation = new FractionalSimulation(tp,info,  progOpt, numGen, chromosomes, popParams); 
}
开发者ID:aberer,项目名称:AnA-FiTS,代码行数:28,代码来源:Simulation.cpp

示例3: Chromosome

Chromosome* Chromosome::MultiplePointCrossoverWithChromosome(Chromosome* Mutator)
{
	//srand( (unsigned)time(0) ); srand should have been called already
	Chromosome* ret = new Chromosome(10); // NEED NUM HERE
	for (int i = 0; i < NUM_EVALNODES; i++)
	{
		//In single point crossover, we select a random point
		//Before the random point, take from A, take rest from B
		int random_integer1 = (rand() %10); //32 bit integer
		int random_integer2 = (rand() %10);
		while (random_integer1 == random_integer2)
			random_integer2 = (rand() % 10);

		int mask = 1;
		//if (random_integer1 > random_integer2)
		{
			for (int j = 0 ; j < abs(random_integer1-random_integer2); j++)
			{
				mask = mask<<1;
				mask |= 1;
			}
			int nextShift = ((random_integer2 > random_integer1) ? random_integer1 : random_integer2);
			mask = mask << nextShift;
		}
		
		int newWeighting = (Weightings[i]&mask) | (Mutator->GetWeighting(i)& ~mask);
		ret->SetWeighting(i, newWeighting);
	}
	return ret;
}
开发者ID:mpweinge,项目名称:Chess-AI,代码行数:30,代码来源:ChessChromosome.cpp

示例4: report_mapped_region

int GenomeMaps::report_mapped_region(Chromosome const &chr, int chr_start, int chr_end, int num_matches)
{
	reported_mapped_regions++ ;
	//fprintf(stdout, "mapped_region:\tchr=%s\tstart=%i\tend=%i\tmatches=%i\n", CHR_DESC[chr], chr_start, chr_end, num_matches) ;
	//assert(chr_start>=0 && chr_start<CHR_LENGTH[chr]) ;
	//assert(chr_end>=0 && chr_end<CHR_LENGTH[chr]) ;

	if (!(chr_start>=0 && (size_t)chr_start<=chr.length()))
	{
		if (_config.VERBOSE>0)
			fprintf(stdout, "report_mapped_region: start out of bounds\n") ;
		if (chr_start<0)
			chr_start = 0 ;
		else
			chr_start = chr.length() ;
	}
	if (!(chr_end>=0 && (size_t)chr_end<=chr.length()))
	{
		if (_config.VERBOSE>0)
			fprintf(stdout, "report_mapped_region: end out of bounds\n") ;
		if (chr_end<0)
			chr_end = 0 ;
		else
			chr_end = chr.length() ;
	}

	for (int i=chr_start; i<chr_end; i++)
		if ((CHR_MAP(chr,i) & MASK_MAPPED_REGION) ==0 )
		{
			covered_mapped_region_positions++ ;
			CHR_MAP_set(chr, i, CHR_MAP(chr,i) + MASK_MAPPED_REGION) ;
		}
	
	return 0 ;
}
开发者ID:boya888,项目名称:oqtans_tools,代码行数:35,代码来源:GenomeMaps.cpp

示例5: mutate

	 /// todo: create a function that return the pop/chromosome size for brievty
	void Popu::mutate(int pos){
	 /// given an offspring we mutate it at a certain rate and create the new population
	 int pos1=0,pos2=3;//size=offspring.elements.size();
	  QTime t;int rd=3;
	  Chromosome mutant;
	 ///NOTE: As we kept the 2 best parents as are (ellitisme) we start from 2
	 for (int i=0;i<2;i++){
		 if (i==0)
				mutant=parentOne;
			else 
				mutant=parentTwo;

		 for (int j=0;j<chromoSize;j++){
			 rd=qrand()%chromoSize;
			 //qDebug()<<rd;
			 ///DFFIXME : make it dependant on a variable value Mut_prob the probability should be small
			 if (rd >chromoSize-(chromoSize/5)) {
				 //qDebug()<<"creating a mutant";
				 pos1=qrand()%chromoSize;
				 //qsrand(QTime::msec ());
				 pos2=qrand()%chromoSize;
				 //qDebug()<<pos2<<pos1;
				 //mutant.elements.swap(pos1,pos2);
				 swapVals(mutant.elements,pos1,pos2);
				}		
			 ///qDebug()<<mutant.elements<<"route"<< mutant.routeLength;
			 
		    }
		 mutant.setRoutelength();
		 ///qDebug()<<"creating a mutant at "<<pos+i<<"routes"<< mutant.routeLength;
		 newGen.replace(pos+i,mutant);
		//qDebug()<<newGen.size();
		}
	}
开发者ID:aliceylan,项目名称:camnest,代码行数:35,代码来源:gatsp.cpp

示例6: while

void Sorting::sort(std::vector<Chromosome>& pop)
{
	std::vector<Chromosome> sorted;

	while (pop.size() != 0)
	{
		double bestFitness = -100000;
		Chromosome bestChromosome;
		int bestChromomeIndex = -1;

		for (size_t i = 0; i < pop.size(); i++)
		{
			if (pop.at(i).getFitness() > bestFitness)
			{
				bestChromosome = pop.at(i);
				bestFitness = bestChromosome.getFitness();
				bestChromomeIndex = i;
			}
		}
		sorted.push_back(bestChromosome);
		pop.erase(pop.begin() + bestChromomeIndex);
	}

	for (size_t i = 0; i < sorted.size(); i++)
	{
		pop.push_back(sorted.at(i));
	}
}
开发者ID:Excolo,项目名称:StarcraftBot,代码行数:28,代码来源:Sorting.cpp

示例7: mutate

	void Popu::mutate(int pos){
	 
	 int pos1=0,pos2=3;//size=offspring.elements.size();
	  //QTime t;
	  int rd=3;
	  Chromosome mutant;
	 
	 for (int i=0;i<2;i++){
		 if (i==0)
				mutant=parentOne;
			else 
				mutant=parentTwo;

		 for (int j=0;j<chromoSize;j++){
			 ///@todo make it dependant on a variable value Mut_prob the probability should be small
			 rd=qrand()%chromoSize;
			 if (rd >chromoSize-(chromoSize/5)) {
				 //qDebug()<<"creating a mutant";
				 pos1=qrand()%chromoSize;
				 //qsrand(QTime::msec ());
				 pos2=qrand()%chromoSize;
				 //qDebug()<<pos2<<pos1;
				 swapVals(mutant.elements,pos1,pos2);
				}		
			 //qDebug()<<mutant.elements<<"route"<< mutant.routeLength;			 
		    }
		 mutant.calcRouteLength();
		 //qDebug()<<"creating a mutant at "<<pos+i<<"routes"<< mutant.routeLength;
	///@NOTE: As we kept the 2 best parents as are (ellitisme) and i>0 at while loop end we keep the elite
		 //newGen.replace(pos+i,mutant);
		newGen.replace(pos,mutant);		 
		//qDebug()<<newGen.size();
		}
	}
开发者ID:aliceylan,项目名称:camnest,代码行数:34,代码来源:gatsp.cpp

示例8: qDebug

         QPFWPVector Popu::init(QPFWPVector points,bool randomtartupPop){
	 
	 int i=0;
         chromoSize=points.size();
          qDebug()<<"Creating initial Rpop";
	 ///create a population of @see popSize chromosome. The chromosome elements are taken randomly from parent @see points
	 while (i<popSize){
		 Chromosome member;
                 member.setElements(points,randomtartupPop);
		 content.append(member);
                 //fixme: need to be computed only once
                 totalRoute=member.routeLength;
		 i++;
		}
	
         qDebug()<<"Created an initial Random pop with route:"<<totalRoute;
	
         sortContent();
	 /// copy the created population into newGen
	 newGen=content;
	 /// Keep creating new genrations until @see Max_iter
         for (curGen=0;curGen<Max_iter;curGen++){
		 createNewGen();
		}

	return content[0].elements;

	 }
开发者ID:aliceylan,项目名称:camnest,代码行数:28,代码来源:gatsp.cpp

示例9: trial

void DSMGA2::backMixingE(Chromosome& source, list<int>& mask, Chromosome& des) {
    cout <<"_bme";
    Chromosome trial(ell);
    trial = des;
    for (list<int>::iterator it = mask.begin(); it != mask.end(); ++it)
        trial.setVal(*it, source.getVal(*it));

    if (trial.getFitness() > des.getFitness()) {
        pHash.erase(des.getKey());
        pHash[trial.getKey()] = trial.getFitness();

        EQ = false;
        //des.getIndex()++;
        des = trial;
        return;
    }

    if (trial.getFitness() >= des.getFitness()) {
        pHash.erase(des.getKey());
        pHash[trial.getKey()] = trial.getFitness();

        des = trial;
        return;
    }

}
开发者ID:entryword,项目名称:20150422_dsmga2,代码行数:26,代码来源:dsmga2.cpp

示例10: compare

int Dilemma::compare(const void *x, const void *y){
	const Chromosome xx = *(Chromosome*)x;
	const Chromosome yy = *(Chromosome*)y;
	if(xx.getFitness() < yy.getFitness()) return 1;
	if(xx.getFitness() > yy.getFitness()) return -1;
	return 0;
}
开发者ID:regicsf2010,项目名称:Prisoners_dilemma,代码行数:7,代码来源:Dilemma.cpp

示例11: if

bool Chromosome::operator < (const Chromosome& another)const
{
    if(this->TestCaseCount < another.getCount())
        return true;
    else if(this->TestCaseCount > another.getCount())
        return false;
    else
        return((this->fitness)< another.getFitness());
}
开发者ID:abhinavarora,项目名称:Model-Based-Testing-and-Test-Case-Prioritization-using-Genetic-Algorithm,代码行数:9,代码来源:chromosome.cpp

示例12:

size_t DSMGA2::findSize(Chromosome& ch, list<int>& mask, Chromosome& ch2) const {
    cout <<"_findsize2";
    size_t size = 0;
    for (list<int>::iterator it = mask.begin(); it != mask.end(); ++it) {
        if (ch.getVal(*it) == ch2.getVal(*it)) break;
        ++size;
    }
    return size;
}
开发者ID:entryword,项目名称:20150422_dsmga2,代码行数:9,代码来源:dsmga2.cpp

示例13: crossover

void crossover(Chromosome& chromosome1, Chromosome& chromosome2)
{
	float randomVal = randomRange(0.0f, 1.0f);
	if (randomVal < CROSSOVER_RATE) {

		int count = std::min(chromosome1.getGeneCount(), chromosome2.getGeneCount());
		int start = randomRange(0, count - 1);
		for (int i = start; i < count; ++i) {
			geneSwap(chromosome1[i], chromosome2[i]);
		}
	}
}
开发者ID:Backman,项目名称:Artificiell-Intelligence-Course,代码行数:12,代码来源:Main.cpp

示例14: Chromosome

Chromosome Chromosome::combination(Chromosome &mate){
	Chromosome newChromosome = Chromosome(_genes.substr(0));
	
	for (size_t i = 0; i < CHROMOSOME_LENGTH; i++) {
		if (eventHappenedWithProbability(CROSSOVER_CHANCE)){
			int crossoverLength = binomialRandomAroundTarget(CROSSOVER_AVERAGE_LENGTH);
			newChromosome.addCrossover(mate, i, crossoverLength);
		}
	}
	
	return newChromosome;
}
开发者ID:ChrisCooper,项目名称:Equation_Evolution,代码行数:12,代码来源:Chromosome.cpp

示例15: report_repetitive_seed

int GenomeMaps::report_repetitive_seed(Chromosome const &chr, int chr_start, int count)
{
	//fprintf(stdout, "repetitive_seed:\tchr=%s\tpos=%i\tcount=%i\n", CHR_DESC[chr], chr_start, count) ;

	if (count<Config::REPORT_REPETITIVE_SEED_COUNT)
		return 0 ;
	if (!(chr_start>=0 && (size_t)chr_start<=chr.length()))
	{
		if (_config.VERBOSE>0)
			fprintf(stdout, "report_mapped_region: start out of bounds\n") ;
		if (chr_start<0)
			chr_start = 0 ;
		else
			chr_start = chr.length() ;
	}
	assert(chr_start>=0 && (size_t)chr_start<chr.length()) ;
	
	//fprintf(stdout, "repetitive_seed:\tchr=%s\tpos=%i\tcount=%i\n", CHR_DESC[chr], chr_start, count) ;
	reported_repetitive_seeds++ ;

	for (unsigned int i=chr_start; i<chr_start+_config.INDEX_DEPTH+REPORT_REPETITIVE_SEED_DEPTH_EXTRA && i<chr.length(); i++)
		if ((CHR_MAP(chr,i) & MASK_REPETITIVE_SEED) == 0)
		{
			covered_repetitive_seed_positions++ ;
			CHR_MAP_set(chr,i, CHR_MAP(chr,i) + MASK_REPETITIVE_SEED) ;
		}

	do_reporting() ;

	if (count<Config::REPORT_REPETITIVE_SEED_COUNT_MANY1)
		return 0 ;

	for (unsigned int i=chr_start; i<chr_start+_config.INDEX_DEPTH+REPORT_REPETITIVE_SEED_DEPTH_EXTRA && i<chr.length(); i++)
		if ((CHR_MAP(chr,i) & MASK_REPETITIVE_SEED_MANY1) == 0)
		{
			covered_repetitive_seed_positions_many1++ ;
			CHR_MAP_set(chr, i, CHR_MAP(chr,i) + MASK_REPETITIVE_SEED_MANY1) ;
		}

	if (count<Config::REPORT_REPETITIVE_SEED_COUNT_MANY2)
		return 0 ;

	for (unsigned int i=chr_start; i<chr_start+_config.INDEX_DEPTH+REPORT_REPETITIVE_SEED_DEPTH_EXTRA && i<chr.length(); i++)
		if ((CHR_MAP(chr,i) & MASK_REPETITIVE_SEED_MANY2) == 0)
		{
			covered_repetitive_seed_positions_many2++ ;
			CHR_MAP_set(chr, i, CHR_MAP(chr,i) + MASK_REPETITIVE_SEED_MANY2) ;
		}


	return 1 ;
}
开发者ID:boya888,项目名称:oqtans_tools,代码行数:52,代码来源:GenomeMaps.cpp


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