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


C++ Organism类代码示例

本文整理汇总了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();
}
开发者ID:jeroenvlek,项目名称:evopic,代码行数:33,代码来源:GeneticAlgorithm.cpp

示例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();
}
开发者ID:ci-group,项目名称:tol-controllers,代码行数:25,代码来源:EvolverController.cpp

示例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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:32,代码来源:World.cpp

示例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;
}
开发者ID:ci-group,项目名称:tol-controllers,代码行数:10,代码来源:EvolverController.cpp

示例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;
 };
开发者ID:twiad,项目名称:Garden-Simulator,代码行数:11,代码来源:geneticSystemActions.cpp

示例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();
	}
}
开发者ID:supreme,项目名称:final_assignment,代码行数:20,代码来源:field.cpp

示例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);
				}
			}
		}
	}
}
开发者ID:supreme,项目名称:final_assignment,代码行数:17,代码来源:field.cpp

示例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;
}
开发者ID:joliva,项目名称:adaptive-ai,代码行数:16,代码来源:AdaptOrg.cpp

示例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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:16,代码来源:World.cpp

示例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
开发者ID:w0270525,项目名称:CplusplusGameOfLife,代码行数:17,代码来源:World.cpp

示例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 );    
}
开发者ID:murphyjtm,项目名称:undariaGEN,代码行数:20,代码来源:organism.cpp

示例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();
    }
}
开发者ID:rmxhaha,项目名称:JagatRaya,代码行数:17,代码来源:UniverseSTL.cpp

示例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;
}
开发者ID:jeetsukumaran,项目名称:Ginkgo,代码行数:18,代码来源:population.cpp

示例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);
}
开发者ID:rmxhaha,项目名称:JagatRaya,代码行数:19,代码来源:UniverseList.cpp

示例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;
}
开发者ID:supreme,项目名称:final_assignment,代码行数:22,代码来源:field.cpp


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