本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例6:
void
Strategies::FullGenerationalReplacement( Population &pop ) {
/* All adults die, all children become adults */
pop.SetAdults(pop.GetChildren());
/* Clear children */
pop.GetChildren().clear();
}
示例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 );
}
}
示例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;
}
示例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);
}
}
示例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());
}
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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();
}
示例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 );
}