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


C++ Individual类代码示例

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


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

示例1: main_alt

int main_alt()
{
  Individual ind;
  ind.genInitial();

  display_init();

  std::ifstream fd("current.csv");

  {
    std::string ign;
    fd >> ign;
  }

  ISSDraw model;

  {
    char ign;
    fd >> model.alpha;
    fd >> ign >> beta;
    fd >> ign >> model.yaw;
    fd >> ign >> ind.state[0].SARJ[0].a;
    fd >> ign >> ind.state[0].SARJ[1].a;
    for(int j = 0; j < 8; ++j) {
      fd >> ign >> ind.state[0].BGA[j].a;
    }
  }

  model.state = &ind.state[0];

  while(handle_input())
    frame(model);
}
开发者ID:lvella,项目名称:isslongeron,代码行数:33,代码来源:main.cpp

示例2: qDebug

void Selection::addIndividualToOutOfGridIndividualList(Individual * outOfGridIndividual)
{
    qDebug("Selection::addIndividualToOutOfGridIndividualList");

    if (outOfGridList.empty())
    {
        outOfGridList.append(outOfGridIndividual);
        qDebug("lista vacio, se inserto el individuo que cayo fuera de la grid");
        return;
    }

    // verificar que el individuo no exista; si no existe se agrega en caso contrario se ignora

    Individual * auxIndividual;

    for (int i=0; i<outOfGridList.count(); i++)
    {
        auxIndividual = outOfGridList.at(i);

        if (auxIndividual->getIndividualId() == outOfGridIndividual->getIndividualId())
        {
            qDebug("el individuo que cayo fuera de la grid ya se inserto en la lista y se ignora");
            return;
        }
    }
    outOfGridList.append(outOfGridIndividual);
    qDebug("se inserto el individuo que cayo fuera de la grid a la lista");
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例3: modifiedAnt

void Ant::modifiedAnt(Individual<CodeVInt> &parent)
{
	if (m_iteIndivl.data().m_x[m_loc] != m_x[m_loc])
	{
		double obj = m_iteIndivl.data().m_obj[0];
		TravellingSalesman *ptr = dynamic_cast<TravellingSalesman*>(Global::msp_global->mp_problem.get());
		int pos = -1;
		for (int i = m_loc + 1; i < getNumDim(); i++)
		{
			if (m_iteIndivl.data().m_x[i] == m_x[m_loc])
			{
				pos = i;
				break;
			}
		}
		obj = obj - ptr->getCost()[m_iteIndivl.data().m_x[pos]][m_iteIndivl.data().m_x[pos - 1]] - ptr->getCost()[m_iteIndivl.data().m_x[pos]][m_iteIndivl.data().m_x[(pos + 1) % getNumDim()]]\
			- ptr->getCost()[m_iteIndivl.data().m_x[m_loc]][m_iteIndivl.data().m_x[m_loc - 1]];
		obj = obj + ptr->getCost()[m_iteIndivl.data().m_x[pos]][m_iteIndivl.data().m_x[m_loc - 1]] + ptr->getCost()[m_iteIndivl.data().m_x[pos]][m_iteIndivl.data().m_x[m_loc]]\
			+ ptr->getCost()[m_iteIndivl.data().m_x[pos - 1]][m_iteIndivl.data().m_x[(pos + 1) % getNumDim()]];
		m_iteIndivl.data().m_obj[0] = obj;
		for (int i = pos - 1; i >= m_loc; i--)
		{
			m_iteIndivl.data().m_x[i + 1] = m_iteIndivl.data().m_x[i];
		}
		m_iteIndivl.data().m_x[m_loc] = m_x[m_loc];
		if ((ptr->getOptType() == MIN_OPT && obj < parent.data().m_obj[0]) || (ptr->getOptType() == MAX_OPT && obj > parent.data().m_obj[0]))
		{
			parent.data().m_obj[0] = obj;
			for (int i = 0; i < getNumDim(); i++)
				parent.data().m_x[i] = m_iteIndivl.data().m_x[i];
			parent.setFlag(true);
		}
	}
}
开发者ID:Changhe160,项目名称:OFEC,代码行数:34,代码来源:Ant.cpp

示例4: Individual

void ImmigrationOperator::replace_worst_with_random(
  int n, AlgorithmState & st, const Instance & instance) const
{
  Population & P = st.population();

  // generate n random
  std::vector<Individual *> immigrants;
  for(int i = P.size() - n; i < P.size(); i++){
    Individual * next = new Individual(instance.num_words());
    st.inc_processed();
    next->randomize();
    next->set_cost(instance.evaluate(next));
    immigrants.push_back(next);
  }

  for(int i = 0; i < steps_; i++){
    local_search_(st, immigrants);
  }

  for(int i = 0; i < n; i++){
    delete P[i + P.size() - n];
    P.swap(i + P.size() - n, immigrants[i]);
  }
  
  P.update_stats();
}
开发者ID:krzychu,项目名称:superstring,代码行数:26,代码来源:immigration.cpp

示例5: chronoCrossover

float chronoCrossover(ParametersMap* parametersMap, unsigned repetitions)
{
    START

    Individual* other = individual->newCopy(false);
    individual->setFitness(1);
    other->setFitness(1.5);

    CrossoverAlgorithm crossoverAlgorithm = (CrossoverAlgorithm) parametersMap->getNumber(
            Enumerations::enumTypeToString(ET_CROSS_ALG));
    CrossoverLevel crossoverLevel = (CrossoverLevel) parametersMap->getNumber(
            Enumerations::enumTypeToString(ET_CROSS_LEVEL));

    float probability =  parametersMap->getNumber(PROBABILITY);

    unsigned numTimes = parametersMap->getNumber(NUM_TIMES);

    START_CHRONO
        switch (crossoverAlgorithm) {
            case CA_UNIFORM:
                individual->uniformCrossover(crossoverLevel, other, probability);
                break;
            case CA_PROPORTIONAL:
                individual->proportionalCrossover(crossoverLevel, other);
                break;
            case CA_MULTIPOINT:
                individual->multipointCrossover(crossoverLevel, other, numTimes);
                break;
        }STOP_CHRONO

    delete (other);

    END
}
开发者ID:jtimon,项目名称:preann,代码行数:34,代码来源:chronoGenIndividual.cpp

示例6: TEST

TEST(BestOfReplacement, SelectsBest){
  AlgorithmState state;  
  Population & p = state.population();

  const int n = 3;
  double costs[] = {1,3,5,2,4,6};
  for(int i = 0; i < n; i++){
    Individual * ind = new Individual(10);
    ind->set_cost(costs[i]);
    p.add(ind);
  }

  std::vector<Individual *> children;
  for(int i = n ; i < 2*n; i++){
    Individual * ind = new Individual(10);
    ind->set_cost(costs[i]);
    children.push_back(ind);
  }

  BestOfReplacement repl;
  repl(state, children);
  
  p.update_stats();
  for(int i = 0; i < n ; i++)
    ASSERT_EQ(i + 1, p[i]->cost());
}
开发者ID:krzychu,项目名称:superstring,代码行数:26,代码来源:best_of_replacement.cpp

示例7: FHwrite

// ----------------------------------------------------------------------------------------
// FHwrite
// ----------------------------------------------------------------------------------------
void FileHandler::FHwrite (const age_idx& cur_age, const sex_t& cur_sex, ostream& FILE,
      Patch* current_patch, const int& patch_id, const int& nbPatchDigit, const int& position){

  unsigned char** seq;
  Individual *ind;
  int ploidy, nb_locus;

  for (unsigned int j = 0, nbInd = current_patch->size(cur_sex, cur_age); j < nbInd; ++j) {
    FILE << setfill('0') << setw(nbPatchDigit) << (patch_id+1) << setfill(' ') << " ";
	  ind = current_patch->get(cur_sex, cur_age, j);
    for(int t=0; t<_nb_trait; ++t){   // for multiple instanciations of a trait
      ploidy   = _trait[t]->get_ploidy();
      nb_locus = _trait[t]->get_nb_locus();
	    seq = (unsigned char**)ind->getTrait(_TTidx[t])->get_sequence();

      for(int k = 0; k < nb_locus; ++k) {
        for (int l = 0; l < ploidy; ++l) {
          FILE.fill('0');
          FILE.width(position);
          FILE<<(unsigned int)(seq[k][l]+1);
        }
        FILE<<" ";
      }
    }
	  if(_fstat_choice==2){
			write_individual_info_to_stream(FILE, ind, cur_age, cur_sex, ' ');
		}
		FILE << "\n";
	}
}
开发者ID:sodatoad,项目名称:quantiNEMO_Taylor2010,代码行数:33,代码来源:filehandler.cpp

示例8: getFittest

Individual * Population::iterate (int iterations) {
    Individual * fittest = getFittest ();
    for (int i = 0; i < iterations; i++)
    {
        if (fittest->getFitness () == 0) {
            return fittest;
        } else {
            pop_stats.average_fitness.push_back (calcAvFitness (individuals, size));
            pop_stats.highest_fitness.push_back (fittest->getFitness ());
            
            Individual * winners = tournament ();
            mutation (winners);
            Individual * children = crossOver (winners);
            merge (winners, children);
            
            delete [] winners;
            delete [] children;
            
            calcFittest ();
            fittest = getFittest ();
        }
    }
    
    return fittest;
}
开发者ID:isaidhiptohop,项目名称:ops_2015,代码行数:25,代码来源:population.cpp

示例9: operator

void Worker::operator()() {
    for (int i = _begin; i < _end; i++) {
            /* Current thread will simulate child strings from begin
             * to end */
       
            /* the simulate method runs the simulator, zfgenerator 3 times
             * lower voltage bound will be -60mV in all cases
             * (1) the upper voltage bound = -34
             * (2) the upper voltage bound = -30
             * (3) the upper voltage bound = -26
             *
             * Store the fmax shift in a variable associated with the
             * Individual object
             */
        
       
        Individual *ind = _pop->ind[i];
        ind->simulate(_id);
        _lock->lock(); //acquire lock
   
        cout << "Thread " << _id << " is simulating child at position " << i << "\n";
        _lock->unlock();  //release lock
    }
    
}
开发者ID:Foxy1987,项目名称:testFresShifts,代码行数:25,代码来源:worker.cpp

示例10: file

void Simulation::initializePopulation()
{
    Individual * individuo;


    QFile file("/tmp/algorithmResult.txt");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
    {
        QMessageBox msg;
        msg.setText("Simulation::initializePopulation(): No se pudo abrir el archivo /tmp/algorithmResult.txt\n para escribir resultados de la ejecucion del algoritmo.");
        return;
    }
    QTextStream out(&file);
    out << endl << "Inicializacion de la poblacion." <<"\n";


    // inicializacion de la poblacion
    for (int i = 0; i < populationSize; i++)
    {
        individuo = new Individual(deployedAPs);
        individuo->printIndividual();
        qDebug("individualId: %d", individuo->getIndividualId());
        populationList.append(individuo);

        out << individuo->getIndividualAsQString() << endl;
    }
    qDebug("tamano de la poblacion: %d",populationList.count());
    //return populationList;
}
开发者ID:antonioaraujob,项目名称:omocac2,代码行数:29,代码来源:simulation.cpp

示例11: evaluate

void Beagle::MPI::EvaluationOp::individualEvaluation(Individual& ioIndividal, Context& ioContext) {
	Fitness::Handle lFitness = evaluate(ioIndividal, ioContext);
	//Assign the fitness
	ioIndividal.setFitness(lFitness);
	ioIndividal.getFitness()->setValid();
	return;
}
开发者ID:ComputationalIntelligenceAndMechatronics,项目名称:MPIBeagle,代码行数:7,代码来源:MPI_EvaluationOp.cpp

示例12: initialise

void initialise(Individual& indiv, const Data& data) {

    // Adding 15 starting nodes to increase entropy
    auto nb_starting_nodes = (rand() % 15) + 1;

    for (int i = 0; i < nb_starting_nodes; i++) {
        
        auto regulation_id = (rand() % data.regulations().size());
        
        struct vertex new_pos =
            indiv.findClosestNode(rand() % MAX_NB_LAYER - 1,
                                  rand() % MAX_NB_NODE_PER_LAYER);
        
        struct vertex new_pos2 =
            indiv.findClosestNode(rand() % MAX_NB_LAYER - 1,
                                  rand() % MAX_NB_NODE_PER_LAYER);

        Node new_node(new_pos.x, new_pos.y, new_pos2.x, new_pos2.y,
                      regulation_id);
        

        int min_layer = std::max(new_pos.x, new_pos2.x);

        indiv.addNode(new_node,
                      rand() % (MAX_NB_LAYER - min_layer) + min_layer + 1);
    }
}
开发者ID:SIben,项目名称:RegGAe,代码行数:27,代码来源:initialisation.cpp

示例13: all_pairwise_MRCA

std::vector<int> all_pairwise_MRCA(std::vector<Individual*> population) {
  std::vector<int> gs;
  
  int pop_size = population.size();
  
  if (pop_size <= 1) {
    throw std::invalid_argument("expected pop_size of at least 2");
  }
  
  Rcout << "Considers " << pop_size*(pop_size-1)/2 << " pairs of individuals" << std::endl;
  
  for (int idx1 = 0; idx1 < (pop_size - 1); ++idx1) {
    Individual* i1 = population[idx1];
    
    for (int idx2 = (idx1 + 1); idx2 < pop_size; ++idx2) {
      Individual* i2 = population[idx2];
      
      // i1 and i2 can originate from different founders, warn about more generations required
      try {
        Individual* mrca = find_MRCA(i1, i2);
        int g = i1->get_generation() - mrca->get_generation();
        gs.push_back(g);
      } catch( const std::invalid_argument& e ) {
        std::ostringstream warningstream;
        warning(e.what());
      }
    }
  }
  
  Rcout << "Got " << gs.size() << " actual pairs of individuals with common founder" << std::endl;
  
  return gs;
}
开发者ID:cran,项目名称:fwsim,代码行数:33,代码来源:proto.cpp

示例14: while

QList<Individual*> StructureNiechingSelection::createSeed(QList<Individual*> currentGeneration,
								int numberOfIndividuals, 
								int numberOfPreservedParents,
								int numberOfParentsPerIndividual)
{
	//TODO
	currentGeneration.size();
	numberOfIndividuals = numberOfIndividuals;
	numberOfPreservedParents = numberOfPreservedParents;
	numberOfParentsPerIndividual = numberOfParentsPerIndividual;


	QList<Individual*> newGeneration;


	int numberOfSeparateNieches = mNumberOfSeparateNieches->get();

	QList<QList<Individual*>*> nieches;
	for(int i = 0; i < numberOfSeparateNieches; ++i) {
		nieches.append(new QList<Individual*>());
	}
	while(mNiecheBestFitness.size() < nieches.size()) {
		mNiecheBestFitness.append(0.0);
	}

	QList<Individual*> modifiedIndividuals;
	QList<Individual*> freeIndividuals;
	QList<Individual*> removedIndividuals;

	for(QListIterator<Individual*> i(currentGeneration); i.hasNext();) {
		Individual *ind = i.next();
		if(ind->hasProperty("Nieche")) {
			QStringList niecheList = ind->getProperty("Nieche").split(",");
			for(QListIterator<QString> j(niecheList); j.hasNext();) {
// 				int niecheid = j.next().toInt();
				
// 				QList<Individual*> *nieche = nieches.value(niecheName);
// 				if(nieche == 0) {
// 					removedIndividuals.append(ind);
// 				}
// 				else {
// 					if(!nieche->contains(ind)) {
// 						nieche->append(ind);
// 					}
// 				}
			}
		}
		else {
			freeIndividuals.append(ind);
		}
	}

	//distribute the free individuals to the nieches.
	
	
	

	return newGeneration;
}
开发者ID:nerd-toolkit,项目名称:nerd,代码行数:59,代码来源:StructureNiechingSelection.cpp

示例15: Lawnmower

Individual *LawnmowerScenario::randomIndividual() const
{
    Individual *individual = new Lawnmower(new Environment(gridSize(), gridSize()), maxMoves());
    Node *rootNode = treeFactory->build();
    individual->setRootNode(rootNode);

    return individual;
}
开发者ID:aliceresearch,项目名称:MAGPIE,代码行数:8,代码来源:LawnmowerScenario.cpp


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