//************************************
// Method:    constructSolutions
// FullName:  CAntColonySystem::constructSolutions
// Access:    virtual public 
// Returns:   void
// Qualifier:
//************************************
void CAntColonySystem::constructSolutions()
{
	m_tourTime.startTimer();
	//clear ants memory and shuffle start pos
	initAnts();
	//place ants in ramdom citys for starting
	for (size_t k = 0; k <  m_Ants.size(); k++ )
	{
		m_Ants[k].setAntCity(0,m_randomPath[k]);
		m_Ants[k].setCityVisited(m_randomPath[k]);
	}
	uniform_real<double> rndSelTrsh(0.0, 1.0);
	uniform_real<double> m_ChoiceExplore(0.0 , 1.0);

	for(size_t step = 1 ; step < m_noNodes; step++)
	{
		for(size_t k = 0; k < m_Ants.size(); k++)
		{
			decisionRule(k,step, rndSelTrsh, m_ChoiceExplore);
		//	localPheromoneUpdate(k,m_Ants[k].getCity(step));
		}
	}

	for(size_t k = 0; k <  m_Ants.size(); k++)
	{
		int tourstart=m_Ants[k].getCity(0);
		m_Ants[k].setAntCity(m_noNodes,tourstart);
		m_Ants[k].setAntTourLength((int)this->calculateAntPathLength(m_Ants[k]));
	//	size_t idx1 = this->m_Ants[k].getCity(m_noNodes);
	//	size_t idx2 = m_Ants[k].getCity(m_noNodes-1);

	//	m_newPheromoneMatrix->local_pheromone_update(m_noNodes-1, m_Ants[k].getAntsCityTour()[0] ,xi, tau0);
	//	localPheromoneEndIndexUpdate(idx1, idx2);
	}
	
	for(size_t k = 0; k < m_Ants.size(); k++)
		for(size_t i=0;i<m_Ants[k].getAntsCityTour().size();i++) 
		{
			if(i==0)
				m_newPheromoneMatrix->local_pheromone_update(m_noNodes-1, m_Ants[k].getAntsCityTour()[i] ,xi, tau0);
			else 
				m_newPheromoneMatrix->local_pheromone_update(m_Ants[k].getAntsCityTour()[i-1], m_Ants[k].getAntsCityTour()[i],xi , tau0 );
		}
	
	m_tourStats.tourAverageTime = (m_tourTime.getElapsedTime())/  (m_Ants.size()-1);
	m_tourTime.stopTimer();
	updateBestSoFarPath();
}
示例#2
0
void main(void)
{
  FILE*fid1;
  FILE*fid2;
  FILE*fid3;
  fid1=fopen("hiddenweights","r");
  fid2=fopen("outputweights","r");
  fid3=fopen("inputvalues","r");
  double *ptrhid=&hiddenWeights;
  double *ptrout=&outputWeights;
  double *ptrin=&inputVector;
  fread(ptrhid,sizeof(double),numberofHiddenUnits*inputDimension,fid1);
  fread(ptrout,sizeof(double),numberofHiddenUnits*outputDimension,fid2);
  fread(ptrin,sizeof(double),inputDimension,fid3);
  fclose(fid1);
  fclose(fid2);
  fclose(fid3);
  activationfunction=logisticSigmoid;
  dActivationFunction=dLogisticSigmoid;
  evaluateTwoLayerPerceptron();
  decisionRule();
}