本文整理汇总了C++中Organism类的典型用法代码示例。如果您正苦于以下问题:C++ Organism类的具体用法?C++ Organism怎么用?C++ Organism使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Organism类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void GeneticAlgorithm::createOffspring(Population& newPopulation,
bool doMutation) {
Image& targetImage = *TargetImage::Instance();
Population tmpResult;
while (m_population.size() > 1) {
m_inputLock.lock();
if (m_population.size() <= 1) {
m_inputLock.unlock();
break;
}
std::pair<Organism*, Organism*> couple =
m_pairGenerator.removeRandomPair(m_population);
m_inputLock.unlock();
Organism* child = new Organism(*couple.first, *couple.second, doMutation);
double score = averagePixelDistance(targetImage, child->getPhenotype());
child->setScore(score);
tmpResult.push_back(child);
tmpResult.push_back(couple.first);
tmpResult.push_back(couple.second);
}
m_outputLock.lock();
newPopulation.insert(newPopulation.end(), tmpResult.begin(),
tmpResult.end());
m_outputLock.unlock();
}
示例2: if
void EvolverController::storePopulationSizesOnFile(double currentTime)
{
ofstream parentsFile;
boost::filesystem::path filePath = RESULTS_PATH + simulationDateAndTime + "/populations.txt";
if(!boost::filesystem::exists(filePath)){
parentsFile.open(filePath.string(), ios::app);
parentsFile << "#time infants adults total" << std::endl;
}else{
parentsFile.open(filePath.string(), ios::app);
}
int infants = 0;
int adults = 0;
for (int i = 0; i < organismsList.size(); i++)
{
Organism org = organismsList[i];
if (org.getState() == Organism::INFANT){
infants++;
}else if (org.getState() == Organism::ADULT)
{
adults++;
}
}
parentsFile << currentTime << " " << infants << " " << adults << " " << (infants+adults) << std::endl;
parentsFile.close();
}
示例3: moveAnts
void World::moveAnts()
{
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
if (org->whoIsThis() == "ant" && org->getMoved() != true)
{
vector<int> newMove = this->getLandscapePosition(row, column).move(this->findAvailSpots(false, row, column));
if (newMove[0] != -1 && newMove[1] != -1)
{
this->setOrganism(&this->getLandscapePosition(row, column), newMove[0], newMove[1]);
this->setOrganism(NULL, row, column);
}
Organism *x = &this->getLandscapePosition(newMove[0], newMove[1]);
if (x != NULL)
{
x->hasMoved();
}
}
} //end null check
} //end for
} //end for
} //end moveAnts
示例4: getOrganismsListAsString
std::string EvolverController::getOrganismsListAsString()
{
std::string text = "";
for (int i = 0; i < organismsList.size(); i++)
{
Organism org = organismsList[i];
text = text + std::to_string(i) + ") " + "ID: " + std::to_string(org.getId()) + "NAME: " + org.getName() + "STATE: " + std::to_string(org.getState()) + "\n";
}
return text;
}
示例5: execute
bool GeneticDropSeedAction::execute() {
Organism* parentOrganism = bp->getParentOrganism();
GeneticCode* code = bp->getGeneticCode();
bp->setBodypartState(BSP_seed);
if(parentOrganism != 0) {
code->setSubSpeciesIdentifier(parentOrganism->getFitnessValue());
};
code->incGeneration();
bp->detachToNewOrganism(blockParentSpawnpointForBodyparttype);
return true;
};
示例6: getSymbol
/* Get a printable representation of what is in a cell
* in a particular place on the field.
* @param x X-coordinate (horizontal)
* @param y Y-coordinate (vertical)
* @return Symbol of Organism at that location
* Blank if uninhabited.
* '?' if invalid cell coordinates.
*/
char Field::getSymbol(int x, int y) {
if ((array == NULL) || (x >= width) || (y >= height)) {
return '?';
}
Organism* org = array[x][y];
if (org == NULL) {
return ' ';
} else {
return org->getSymbol();
}
}
示例7: getInhabitant
/**
* Handles the main logic of updating organsims.
* @param symbol The symbol of the organism to update.
*/
void Field::step(char symbol) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
Organism* o = getInhabitant(Position(x, y));
if (o != NULL && !o->hasUpdated()) {
if (o->getSymbol() == symbol) {
o->update();
o->setUpdated(true);
}
}
}
}
}
示例8:
Organism Organism::operator + (const Organism &Org) const {
Organism Temp;
if (StateCount != Org.StateCount || SensorCount != Org.SensorCount) {
throw;
}
Temp = *this;
Temp.OrgGenome = OrgGenome + Org.OrgGenome;
// Mutate the offspring's genome:
Temp.Mutate ();
return Temp;
}
示例9: resetMoveSwitches
void World::resetMoveSwitches()
{
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
org->resetMoved();
}
}
}
} //end resetMoveSwitches
示例10: lifeCounters
void World::lifeCounters()
{
for (int row = 0; row < GRID_HEIGHT; row++)
{
for (int column = 0; column < GRID_WIDTH; column++)
{
Organism *org = &this->getLandscapePosition(row, column);
if (org != NULL)
{
org->increaseLifeCounter();
org->takeTurn();
}
}
}
} //end lifeCounter
示例11: getCell
//
// - Produce new sporophyte agent from gametophyte reproduction
//
void Organism::tryToReproduce()
{
Organism *ptrOrganism ;
Direction_t dir;
int rank = seedlingID / 1000;
int i = seedlingID % 1000;
// Create and initialise new sporophyte agent
ptrOrganism = fabricPtr_->newAgent() ;
ptrOrganism->init(i, rank, baitParamsPtr_->startStock);
ptrOrganism->resetAge();
ptrOrganism->setGametophyte(false);
// Add to current patch
dir = NONE;
( (Patch*) getCell()->getNeighbour(dir, true))->addOrganism( ptrOrganism );
}
示例12: update
void UniverseSTL::update( float dt ){
int c = 0;
for( int i = 0; i < MList.size(); ++ i ){
Organism* it = MList[i];
if( it->isAlive() ){
it->update(dt);
++c;
}
}
cout << c;
for( auto&it: RList ){
if( it->getState()!=RaceState::RACE_END )
it->updateRace();
}
}
示例13: purge_expired_organisms_
PopulationCountType purge_expired_organisms_(OrganismPointers& organism_ptrs) {
PopulationCountType num_purged = 0;
OrganismMemoryManager& organism_memory_manager = OrganismMemoryManager::get_instance();
std::vector<Organism *> to_keep_ptrs;
to_keep_ptrs.reserve(organism_ptrs.size());
for (OrganismPointers::iterator i = organism_ptrs.begin(); i != organism_ptrs.end(); ++i) {
Organism * org = *i;
if (org->is_expired()) {
++num_purged;
organism_memory_manager.deallocate(org);
} else {
to_keep_ptrs.push_back(org);
}
}
organism_ptrs.clear();
to_keep_ptrs.swap(organism_ptrs);
return num_purged;
}
示例14: update
void UniverseList::update( float dt ){
int count = 0;
for( auto its = MList.begin(); its != MList.end(); its = its->next) {
Organism* it = its->val;
if( it->isAlive() ){
it->update(dt);
++ count;
}
}
for( auto its = RList.begin(); its != RList.end(); its = its->next) {
Race* it = its->val;
if( it->getState()!=RaceState::RACE_END ){
it->updateRace();
++ count;
}
}
printf("%d ", count);
}
示例15: printf
/** Prints the field to standard output
* @return Just a 0 for now
*/
int Field::print() {
int x, y; // Coordinates
printf("\n-----------------------\n");
for (y = 0; y < height; y++) { // Print one complete row
for(x = 0; x < width; x++) { // Print each cell
Organism* o = getInhabitant(Position(x, y));
if (o != NULL) {
// Reset the updated flag so the organism can be updated
// again on the next step
o->setUpdated(false);
}
printf("%c", getSymbol(x, y));
}
printf("\n"); // End of line
}
printf("-----------------------\n");
return 0;
}