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


C++ DNA类代码示例

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


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

示例1: initSultan5

 DNA* initSultan5(int& m, int& n)
 {
   SmartArrayPtr<double> *diag, *sdiag, *kap;
   m = 5;
   n = 6;
  
   DNA* dna = new DNA(n, n - m);
   diag = dna->getDiag();
   sdiag = dna->getSDiag();
   kap = dna->getKap();

   diag->alloc(m);
   sdiag->alloc(m);
   kap->alloc(m);
   
   for(int i = 0; i < 5; i ++) {
     (*diag)[i] = 0.;
     (*sdiag)[i] = 1.;
   }
   (*kap)[0] = 24.;
   (*kap)[1] = 27.;
   (*kap)[2] = 33.;      
   (*kap)[3] = 37.;      
   (*kap)[4] = 24.;

   return dna;
 }
开发者ID:yesyestian,项目名称:BNB-solver,代码行数:27,代码来源:sult.hpp

示例2: randInt

// Making the next generation
void Population::reproduction()
{
    // Refill the population with children from the mating pool
    for( int i = 0; i < mPopulation.size(); i++ )
	{
		// Sping the wheel of fortune to pick two parents
		int m = randInt( mMatingPool.size() );
		int d = randInt( mMatingPool.size() );
		// Pick two parents
		RocketRef mom = mMatingPool[m];
		RocketRef dad = mMatingPool[d];
		// Get their genes
		DNA *momgenes = mom->getDNA();
		DNA *dadgenes = dad->getDNA();
		// Mate their genes
		DNA *child = momgenes->crossover( dadgenes );
		// Mutate their genes
		child->mutate( mMutationRate );
		// Fill the new population with the new child
		Vec2f location = Vec2f( getWindowWidth() / 2.0, getWindowHeight() + 20.0 );
		
		mPopulation[i].reset(); // get rid of the old rocket
		mPopulation[i] = std::make_shared<Rocket>( location, child, mTarget );
    }
    mGenerations++;
}
开发者ID:gregkepler,项目名称:The-Nature-of-Code-Examples,代码行数:27,代码来源:Population.cpp

示例3: int

//--------------------------------------------------------------
void ofApp::draw()
{
	if (!foundSolution)
	{
		for (int i = 0; i < ArrayCount(population); i++)
		{
			population[i].Fitness();
		}

		vector<DNA> matingPool = vector<DNA>();
		for (int i = 0; i < ArrayCount(population); i++)
		{
			int n = int(population[i].fitness * ArrayCount(population));
			for (int k = 0; k < n; k++)
			{
				matingPool.push_back(population[i]);
			}
		}

		for (int i = 0; i < ArrayCount(population); i++)
		{
			int a = int(ofRandom(0, matingPool.size()));
			int b = int(ofRandom(0, matingPool.size()));

			DNA parentA = matingPool[a];
			DNA parentB = matingPool[b];

			DNA child = parentA.crossover(parentB);
			child.mutate();

			population[i] = child;
		}
	}

	ofClear(ofColor::white);

	ofSetColor(ofColor::black);
	for (int i = 0; i < ArrayCount(population); i++)
	{
		//string str = population[i].genes;
		population[i].genes[ArrayCount(population[i].genes)] = '\0';

		if (population[i].genes == target)
		{
			foundSolution = true;
			ofNoFill();
			ofSetLineWidth(6);
			ofSetCurveResolution(200);
			ofCircle(ofPoint((int(i / POPULATION_PER_COLUMN) * Y_SPACING) + 100, 
								((i % POPULATION_PER_COLUMN) * X_SPACING) + BUFFER_SPACING), 120);
		}
		

		myFont.drawString(population[i].genes, 
							(int(i / POPULATION_PER_COLUMN) * Y_SPACING) + BUFFER_SPACING, 
							((i % POPULATION_PER_COLUMN) * X_SPACING) + BUFFER_SPACING);

	}

}
开发者ID:Velro,项目名称:Nature-Of-Code-Projects,代码行数:61,代码来源:ofApp.cpp

示例4: add_DNA_CrossTalk

RNA DnaConfig::add_DNA_CrossTalk(DNA& dnaTotal)
{
	DNA dnaCrossTalk;
	RNA rnaCrossTalk;

    //Cross Talk
    if (m_chkCrossTalk)
    {
        dnaCrossTalk.AddCell(CrsTlk , Pn4, m_CTFE);
        dnaCrossTalk.AddCell(CrsTlkD, Pn4, m_CTFE);
        dnaCrossTalk.AddCell(CrsTlkW, Pn4, m_CTFE);
    }

	if (dnaCrossTalk.Size()) 
	{
		Ts->Trans(dnaCrossTalk, rnaCrossTalk);
		rnaCrossTalk.SortQuackMsr();
	}

	showRNA(rnaCrossTalk);
	dnaTotal += dnaCrossTalk;

	return rnaCrossTalk;
	
}
开发者ID:dwatow,项目名称:ColorEyeI,代码行数:25,代码来源:DNAconfig.cpp

示例5: gs

GenePool::GenePool(char* filename, int nseed, int nrlock, int simtype, int runs, int smult, int lmult)
{
   seed = nseed;
   reactionlock = nrlock;
   //for (int i = 0;i < 30;i++)
   //{
      DNA a;a.load(filename);
      dnavect.push_back(a);
      
      
      int addfit = 0;
      for (int aja = 0;aja < runs;aja++)
      {
         AIPlayer ai;
         KeyState ks;
      //Random ran;
         GameSpace gs(1, 0, 800, 0, 600, (seed-1) + aja, true, "test.lua", "shinku.lua");
         while (gs.updateGameState(ks) == 1)
	      {
            ks = ai.update(&gs, gs.thePlayer, dnavect[0], ks);
         }
      addfit += gs.thePlayer->getScore()*smult;
      addfit += gs.thePlayer->getLives()*lmult;
      }
      fitness.push_back(addfit / runs);
   
   return;
}
开发者ID:nbcwell,项目名称:AliceGame,代码行数:28,代码来源:genepool.cpp

示例6: while

DNA Chromosome::getDNAObj() const
{
	DNA ret;
	list<DNA>::const_iterator iter = strands.cbegin();
	while (iter != strands.cend())
	{
		ret.setDNAInParts(iter->getDNA());
		iter++;
	}
	return ret;
}
开发者ID:smmahdad,项目名称:Personal-Projects,代码行数:11,代码来源:Chromosome.cpp

示例7: DNA

DNA DNA::crossover(DNA partner){
    DNA child = DNA();
    // Picking a random “midpoint” in the genes array
    int midpoint = ofRandom(genes.size());
    for (int i = 0; i < genes.size(); i++) {
      // Before midpoint copy genes from one parent, after midpoint copy genes from the other parent
      if (i>midpoint) child.addGene(genes[i]);
      else child.addGene(partner.genes[i]);
    }
    //Return the new child DNA
    return child;
}
开发者ID:rossanag,项目名称:Nature-Of-Code-Open-Frameworks-Port,代码行数:12,代码来源:DNA.cpp

示例8: DelCell

void DNA::DelCell(const DNA& compData)
{
    if (compData.Size())//裡面這些不要修改,影響再次量測的資料擺放
    {
        std::vector<Nucleotide>::const_iterator dnaItor = 0, compItor;
        std::vector<Nucleotide>::iterator rmBeginItor(End());

        for (compItor = compData.Begin(); compItor != compData.End(); ++compItor)
                rmBeginItor = std::remove(Begin(), rmBeginItor, *compItor);
        
        nChain.erase(rmBeginItor, End());
    }
}
开发者ID:dwatow,项目名称:ColorEyeI,代码行数:13,代码来源:DNA.cpp

示例9: ofRandom

void Population::reproduce() {
  for (int i = 0; i < popSize; i++) {
    int a = ofRandom(matingPool.size());
    int b = ofRandom(matingPool.size());
    DNA partnerA = matingPool[a];
    DNA partnerB = matingPool[b];
    //Step 3a: Crossover
    DNA child = partnerA.crossover(partnerB);
    //Step 3b: Mutation
    child.mutate(mutationRate);
    //Note that we are overwriting the population with the new children. When draw() loops, we will perform all the same steps with the new population of children.
    population[i] = child;
  }
}
开发者ID:anteaterho,项目名称:natureOFcode,代码行数:14,代码来源:Population.cpp

示例10: crossover

//-----------------------------------------------------------------
// Crossover
DNA DNA::crossover(DNA partner) {
    // A new child
    DNA child;
    child.setup(geneSize);
    //int midpoint = int(ofRandom(genes.size())); // Pick a midpoint (NO RESPECT FOR GENE INTEGRITY)
    int midpoint = int(ofRandom(geneSize)); // Pick a midpoint (RESPECTING GENE INTEGRITY)

    // Half from one, half from the other
    for (int i = 0; i < genes.size(); i++) {
        if (i > midpoint) child.genes[i] = genes[i];
        else              child.genes[i] = partner.genes[i];
    }
    return child;

}
开发者ID:jamiecoe,项目名称:exploringFeikskeip,代码行数:17,代码来源:DNA.cpp

示例11: print

// Output the DNA
void Parser::print(std::ostream& iStream, const DNA& iDNA) {
    for (unsigned int i = 0; i < iDNA.genes(); i++) {
        // Extract the gene
        unsigned char* tGene;
        unsigned int tSize;
        iDNA.extract_gene(i, tGene, tSize);

        // Print the block
        std::cout << "* Human-readable version of block " << i << std::endl;
        print_block(iStream, tGene, tSize);

        // Free the block
        free(tGene);
    }
}
开发者ID:maleadt,项目名称:genetic,代码行数:16,代码来源:parser.cpp

示例12: resultSize

af::array Synthesizer::Impl::decodeAsArray(const DNA& dna)
{
    af::array result = af::constant(0, resultSize(), f32);
    unsigned dnaBeginIndex = 0;
    unsigned resultBeginIndex = 0;
    for (unsigned ruleIndex = 0; ruleIndex < rules.size(); ruleIndex++) {
        auto rule = rules[ruleIndex];

        unsigned ruleDnaSize = rule->dnaSize();
        unsigned ruleResultSize = rule->resultSize();
        unsigned dnaEndIndex = dnaBeginIndex + ruleDnaSize - 1;
        unsigned resultEndIndex = resultBeginIndex + ruleResultSize - 1;

        rule->decode(make_tuple(
            af::array(dna.array()(af::seq(dnaBeginIndex, dnaEndIndex))),
            std::ref(result),
            af::seq(resultBeginIndex, resultEndIndex),
            std::ref(states[ruleIndex])));

        dnaBeginIndex += ruleDnaSize;
        resultBeginIndex += ruleResultSize;
    }

    result.eval();
    return result;
}
开发者ID:unbornchikken,项目名称:genevo,代码行数:26,代码来源:synthesizer.cpp

示例13: permute

PermutationTest& PermutationTest::permute (const char* filename, const int niter, Random &ran) {
	if (dna == 0) {
		dna = new DNA;
	}
	dna->readFASTA (filename);
	return permute (dna, niter, ran);
}
开发者ID:agapow,项目名称:omegamip,代码行数:7,代码来源:permute.cpp

示例14: evaluate

// Evaluate DNA
void Parser::evaluate(const DNA& iDNA) {
    // Reset the quotum
    mInstructionCounter = 0;

    // Evaluate all blocks
    for (unsigned int i = 0; i < iDNA.genes(); i++) {
        // Extract the blocks
        unsigned char* tGene;
        unsigned int tSize;
        iDNA.extract_gene(i, tGene, tSize);

        // Evaluate the block
        evaluate_block(tGene, tSize);

        // Free the block
        free(tGene);
    }
}
开发者ID:maleadt,项目名称:genetic,代码行数:19,代码来源:parser.cpp

示例15: add_DNA_Gamma

RNA DnaConfig::add_DNA_Gamma(DNA& dnaTotal)
{
	DNA dnaGamma;
	RNA rnaGamma;
	//Gamma
    if (m_chkWGamma || m_chkDGamma)        
                        dnaGamma.AddCell(White, PnGamma, m_WGammaBegin, m_WGamma_End, m_WGamma_Avg );  
    if (m_chkRGamma)    dnaGamma.AddCell(Red  , PnGamma, m_RGammaBegin, m_RGamma_End, m_RGamma_Avg );
    if (m_chkGGamma)    dnaGamma.AddCell(Green, PnGamma, m_GGammaBegin, m_GGamma_End, m_GGamma_Avg );
    if (m_chkBGamma)    dnaGamma.AddCell(Blue , PnGamma, m_BGammaBegin, m_BGamma_End, m_BGamma_Avg );

	if (dnaGamma.Size()) 
	{
		Ts->Trans(dnaGamma, rnaGamma);
		rnaGamma.SortOrigMsr();
	}
	dnaTotal += dnaGamma;

	return rnaGamma;
}
开发者ID:dwatow,项目名称:ColorEyeI,代码行数:20,代码来源:DNAconfig.cpp


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