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


C++ Population类代码示例

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


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

示例1: nextGeneration

void GaTTP::nextGeneration(){

    Population* nextPop = new Population;

    current->GenerateNewPopulation(nextPop);

    generation++;

    nextPop->CalcFitness();

    if(nextPop->GetBestFitness()>=current->GetBestFitness()) {
        genNoImprov++;
    }
    else{
        genNoImprov = 0;
    }

    delete current;
    current = nextPop;

    //bestIndividual = newPop->GetBestIndividual();

    endClock = clock();

}
开发者ID:fongoses,项目名称:trab-otimizacao-TTP,代码行数:25,代码来源:GaTTP.cpp

示例2: genPopulation

void WorldGenerator::genPopulation( Population& population, Level& level, PopulationGenerationRanges& ranges, float blockDimension )
{
    struct OpenBlock{
        ushort i;
        ushort j;
    };

    //Allocate space for open blocks
    ushort numOpens = 0;
    OpenBlock* opens = new OpenBlock[ level.getWidth() * level.getDepth() ];

    population.clear();

    //fill the array with open blocks
    for(ushort i = 0; i < level.getWidth(); i++){
        for(ushort j = 0; j < level.getDepth(); j++){
            if( level.getBlock(i, j).getCollidableType() == Level::Block::Collidable::None ){
                opens[ numOpens ].i = i;
                opens[ numOpens ].j = j;
                numOpens++;
            }
        }
    }

    float popDensity = ranges.density.gen( mRand );
    int popCount = static_cast<int>( static_cast<float>( numOpens ) * popDensity ) + 1;
    int gennedPop = 0;
    int attempts = 0;
    float halfBlockDimension = blockDimension * 0.5f;

    while( gennedPop < popCount ){
        if( attempts > WORLD_GEN_ATTEMPTS ){
            break;
        }

        //Generate a spot in the list
        ushort genOpen = mRand.gen( 0, numOpens );

        //Spawn an entity 0 to start
        population.spawn( 0, 
                          XMFLOAT4( static_cast<float>( opens[ genOpen ].i ) * blockDimension + halfBlockDimension,
                                    0.32f,
                                    static_cast<float>( opens[ genOpen ].j ) * blockDimension + halfBlockDimension,
                                    1.0f ) );

        //Remove the spot from the list
        numOpens--;

        if( genOpen < numOpens ){
            for(ushort i = genOpen; i < numOpens; i++){
                opens[i] = opens[i+1];
            }
        }

        gennedPop++;
    }

    delete[] opens;
}
开发者ID:justy989,项目名称:MultiFall,代码行数:59,代码来源:WorldGenerator.cpp

示例3: InitialisePopulation

Population InitialisePopulation(int populationSize, std::vector<std::vector<int>>& vehicleConfigurationParameters) {
 Population population;
 for(int i=0;i<populationSize;i++) {
	Individual tempInd = GetIndividual(vehicleConfigurationParameters);	// Individual = std::vector<float> - vector of floats
  population.push_back(tempInd);
 }
 return population;
}
开发者ID:carthikvenkataraman,项目名称:MasterThesis-PropOpt,代码行数:8,代码来源:GeneticAlgorithm.cpp

示例4: Merge

        void Merge(const Population& population) {
            samples.resize(children_start + population.size());
            copy(population.begin(), population.end(), samples.begin()+children_start);
            sort(samples.begin(), samples.end());
            samples.resize(capacity());

            children_start = capacity();
        }
开发者ID:antoshkaplus,项目名称:Opt_GraphColoring,代码行数:8,代码来源:GC_GA.hpp

示例5: do_crossover

void Crossover::do_crossover(Population& population) {
  shuffle(population.begin(), population.end(), rng);
  for (int index = 0; index + 1 < int(population.size()); index += 2)
    if (decide_to_do_crossover()) {
      auto crossed = do_crossover(population[index], population[index + 1]);
      show_crossing(crossed);
    }
}
开发者ID:zahlenteufel,项目名称:GA-FLM,代码行数:8,代码来源:Crossover.cpp

示例6:

void
Strategies::FullGenerationalReplacement( Population &pop ) {
   /* All adults die, all children become adults */
   pop.SetAdults(pop.GetChildren());

   /* Clear children */
   pop.GetChildren().clear();
}
开发者ID:khskrede,项目名称:AI,代码行数:8,代码来源:strategies.cpp

示例7: sample

void
APG::ConstraintSolver::fill_population( Population& population )
{
    for ( int i = population.size(); quint32(i) < m_populationSize; i++ ) {
        Meta::TrackList* tl = new Meta::TrackList( sample( m_domain, playlist_size() ) );
        double s = m_constraintTreeRoot->satisfaction( (*tl) );
        population.insert( tl, s );
    }
}
开发者ID:KDE,项目名称:amarok,代码行数:9,代码来源:ConstraintSolver.cpp

示例8: main

int main(int argc, char* argv[])
{
    try
    {
        ostringstream usage;
        usage << "Usage: simrecomb_aux <function> [args]\n";
        usage << endl;
        usage << "Functions:\n";
        usage << "    simrecomb_aux txt2pop filename_in filename_out\n";
        usage << "    simrecomb_aux pop2txt filename_in filename_out\n";
        usage << endl;
        usage << "Darren Kessner\n";
        usage << "John Novembre Lab, UCLA\n";

        string function = argc>1 ? argv[1] : "";

        if (function == "txt2pop")
        {
            if (argc < 4) throw runtime_error(usage.str().c_str());
            string filename_in = argv[2];
            string filename_out = argv[3];

            cout << "reading " << filename_in << endl << flush;
            ifstream is(filename_in.c_str());
            if (!is) throw runtime_error(("[simrecomb_aux] Unable to open file " + filename_in).c_str());
            Population p;
            is >> p;

            cout << "writing " << filename_out << endl << flush;
            ofstream os(filename_out.c_str(), ios::binary);
            p.write(os);
            os.close();
        }
        else if (function == "pop2txt")
        {
            if (argc < 4) throw runtime_error(usage.str().c_str());
            string filename_in = argv[2];
            string filename_out = argv[3];

            cout << "reading " << filename_in << endl << flush;
            ifstream is(filename_in.c_str(), ios::binary);
            if (!is) throw runtime_error(("[simrecomb_aux] Unable to open file " + filename_in).c_str());
            Population p;
            p.read(is);

            cout << "writing " << filename_out << endl << flush;
            ofstream os(filename_out.c_str());
            os << p;
            os.close();
        }
        else
        {
            throw runtime_error(usage.str().c_str());
        }

        return 0;
    }
开发者ID:dkessner,项目名称:simrecomb,代码行数:57,代码来源:simrecomb_aux.cpp

示例9: removeDependentRelations

void Population::removeDependentRelations(){
//    std::cout << "Population::removeDependentRelations called on " << (*this);
    for(auto itRec = m_dependentRelations.begin(); itRec != m_dependentRelations.end(); itRec++ ){
        Population* ptrOtherPop = (Population*) (itRec->ptrPopAddr);
        std::list<Relation>::iterator itOtherRel = itRec->itRelAddr;

        ptrOtherPop->removeRelation(itOtherRel);
    }
}
开发者ID:abernatskiy,项目名称:epdm,代码行数:9,代码来源:population.cpp

示例10:

void PerPointStopCriterion<TFunction>::update(const Population& population) {
  for (Population::Iterator it = population.begin();
       it != population.end();
       ++it) {
    typename OnePointStopCriterion<TFunction>::Ptr one_point_stop_criterion =
      stop_criterion_info_->getInfoById(it.point_id());
    one_point_stop_criterion->update(it.point());
  }
}
开发者ID:runrunliuliu,项目名称:ltr,代码行数:9,代码来源:per_point_stop_criterion.hpp

示例11: Population

Population* Population::GenerateRandPopulation( size_t chromosomeCount )
{
	Population* population = new Population(chromosomeCount);
	for (size_t i = 0; i < chromosomeCount; ++i)
	{
		population->AddChromosome(i, Chromosome::GenerateRandChromosome());
	}
	return population;
}
开发者ID:vromanov,项目名称:CuttingProblem,代码行数:9,代码来源:Population.cpp

示例12: make_population

  Population make_population(const Mat& oImg, const Mat& pImg, const size_t size) {
    Population pop;
    for(size_t i = 0; i < size; ++i) {
      std::cerr << '\r' << i;
      pop.push_back(Painter(oImg, pImg));
    }
    std::cerr << std::endl;

    return pop;
  }
开发者ID:kallaballa,项目名称:Mimikry,代码行数:10,代码来源:mimikry.cpp

示例13: sort

void
Strategies::Elitism( Population &pop ) {
   unsigned int elitism = pop.GetElitism();
   if (elitism > 0) {
      sort(pop.GetAdults().begin(), pop.GetAdults().end(), IndividualSort);
      for (unsigned int i = 0; i<elitism; i++) {
         pop.GetChildren().push_back(pop.GetAdults().at(i));
      }
   }
}
开发者ID:khskrede,项目名称:AI,代码行数:10,代码来源:strategies.cpp

示例14: printResume

void Simulation::printResume(const Population &population) const {
    _display.basicLine("generation " + std::to_string(_currentGeneration) + "/" + std::to_string(config.simulationNumber));
    _display.basicLine("Best: ");
    _problem->print(population.best());
    _display.basicLine("Mid: ");
    _problem->print(population.at(config.populationSize / 2));
    _display.basicLine("Worst: ");
    _problem->print(population.worst());
    _display.newLine();
}
开发者ID:JeremyPouyet,项目名称:cpp-gaf,代码行数:10,代码来源:Simulation.cpp

示例15: saveMutationSample

void MainWindow::saveMutationSample(const Population &p)
{
    QPolygonF samples;
    qint16 size = p.getIndividualNum();
    for( qint16 i = 0; i < size; i ++)
    {
        samples += QPointF( p.getValueAt( i ), p.getFitnessAt( i ) );
    }
    mutation_operator_indi.append( samples );
}
开发者ID:LyonGao,项目名称:Genetic-Algorithm_Qt,代码行数:10,代码来源:mainwindow.cpp


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