Ejemplo n.º 1
0
QString ChannelUrlSelectorEntry::best() {
    LOG_TRACE(logger, "best ...");
    updateFitness();
    QList<QString> urls = urlInformation.getUrls();
    double temp = fitness.first();
    int posOfMax = 0;

    for(int i=0;i<urls.size();i++) {
        if(temp < fitness.at(i)) {
            temp = fitness.at(i);
            posOfMax = i;
        }
    }
    return urls.at(posOfMax);
}
Ejemplo n.º 2
0
void PsoSolver::run(const bool enableGLNPSO, const double minIw) {
	this->enableGLNPSO = enableGLNPSO;
	initFitness();
	gBest        = particles[0].pBest;
	gBestFitness = particles[0].pBestFitness;
	updateGbest();

	for (iteration = 0; iteration < maxIteration; iteration++) {

		if (getDispersionIDX() < convergenceThreshold && getVelocityIDX() < convergenceThreshold) {
			break;
		}

		moveParticles();
		updateFitness();
		updateGbest();

		// linear interia weighting adjustment
		iw = max(iw - 1.0/maxIteration, minIw);
	} // end of iteration
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------------------------------------------------------
void BacteriumEvo::update(float dt)
{
  m_agent->update(dt);
  
  updateFitness(dt);

  // In the second half of trial shrink/inflate torus to half/double size
  /*
  if (m_phaseTime >= 0.5f * m_phaseDuration)
  {
    const std::vector<Positionable*>& objects = m_agent->getEnvironment().getObjects();
    float tprop = m_phaseTime / (m_phaseDuration / 2) - 1;
    
    if(isInnerPhase())
      ((Torus*)objects[1])->setRadius(0.3 + 0.2 * tprop);
    else
      ((Torus*)objects[1])->setRadius(0.8 - 0.3 * tprop);
  }
   */
  
  m_phaseTime += dt;
  if (m_phaseTime >= m_phaseDuration)
    nextPhase();
}
void StrongCausalityExperimentAgentObserver::step() 
{

	if ( _wm->_age == _lifetimeIterations )
	{			
		// stats for current agent
		_sumOfFitnesses = _sumOfFitnesses + _wm->_fitnessValue;
		
		if ( initPos[_wm->_generation][0] == -1 )  // genome iteration ends? display stats and restart with new genome
		{
			// * Display stats.
			
			//std::cout << _wm->_generation << "," << _wm->_fitnessValue;

			if ( _testIt == 0 )	// reference genome
				std::cout << "# ";
			std::cout << _testIt << "," << _sumOfFitnesses;

			if ( _testIt == 0 )	// reference genome
				std::cout << ",0";
			else
				std::cout << "," << _sigma;
			
			for ( int i = 0 ; i != 18 ; i++ ) // genome
			{
				std::cout << ",";
				std::cout << _wm->_genome[i];
				
			}
			std::cout << std::endl;
			
			reset();
			
			if ( _triesPerSigma == _nbOfTriesPerSigmaValue )
			{			
				if ( _sigma < _sigmaMax )
				{
					_sigma = _sigma * 2;
				}
				else
				{
					std::cout << "end." << std::endl;
					exit(0);
				}
				_triesPerSigma = 0;
			}
			else
				_triesPerSigma++;
			
			mutateWithBouncingBounds();

			_wm->_generation = 0;			
		}
		
		// prepare for new evaluation
		_wm->_generation++;

		_wm->_xReal = initPos[_wm->_generation][0];
		_wm->_yReal = initPos[_wm->_generation][1];
		_wm->_agentAbsoluteOrientation = initPos[_wm->_generation][2];
		_wm->_agentAbsoluteLinearSpeed = 0;
		
		_wm->_fitnessValue = 0;
		_wm->_age = 0; // age<0 means random mouvement until age=0D
		
	}	
	else
	{
		// udpate fitness
		updateFitness();
		_wm->_age++;
	}
}
//-------------------------------------Update-----------------------------
//
//	This is the main workhorse. The entire simulation is controlled from here.
//
//	The comments should explain what is going on adequately.
//-------------------------------------------------------------------------
bool CController::Update()
{
	//run the sweepers through CParams::iNumTicks amount of cycles. During
	//this loop each sweepers NN is constantly updated with the appropriate
	//information from its surroundings. The output from the NN is obtained
	//and the sweeper is moved. If it encounters a mine its fitness is
	//updated appropriately,
	cajas=0;
	if (m_iTicks++ < CParams::iNumTicks)
	{
		for (int i=0; i<m_NumSweepers; ++i)
		{
			//update the NN and position
			if (!m_vecSweepers[i]->Update())
			{
				//error in processing the neural net
				MessageBox(m_hwndMain, "Wrong amount of NN inputs!", "Error", MB_OK);

				return false;
			}
			
			updateFitness(i);
			m_vecSweepers[i]->mover();
			cajas=cajas+m_vecSweepers[i]->getArmasCogidas();
			/*if(m_iTicks % 30 == 0){
				double x, y = 0;
				m_vecSweepers[i]->getPosMasCercano(x,y);

				//if(x+y>0.5)
					//m_vecSweepers[i]->disminuyoFitness();

				//if(abs(x)+abs(y)<0.1)
					//sm_vecSweepers[i]->aumentoFitness();

			}*/
			/*
			if(m_iTicks+1 == CParams::iNumTicks && m_vecSweepers[i]->getArmasCogidas()==0)
				m_vecSweepers[i]->disminuyoFitness();
			*/

			//update the chromos fitness score
			m_vecThePopulation[i].dFitness = m_vecSweepers[i]->Fitness();

		}
	}

	//Another generation has been completed.

	//Time to run the GA and update the sweepers with their new NNs
	else
	{
		//update the stats to be used in our stat window
		m_vecAvFitness.push_back(m_pGA->AverageFitness());
		m_vecBestFitness.push_back(m_pGA->BestFitness());

		//increment the generation counter
		++m_iGenerations;

		//reset cycles
		m_iTicks = 0;

		//run the GA to create a new population
		m_vecThePopulation = m_pGA->Epoch(m_vecThePopulation);

		//insert the new (hopefully)improved brains back into the sweepers
		//and reset their positions etc
		
		double x = RandInt(0, dimMapa/dimCasilla)*dimCasilla;
		double y = RandInt(0, dimMapa/dimCasilla)*dimCasilla;
		for (int i=0; i<m_NumSweepers; ++i)
		{
			m_vecSweepers[i]->PutWeights(m_vecThePopulation[i].vecWeights);
			m_vecSweepers[i]->Reset(x, y);
		}
	}

	return true;
}