void PheromoneMatrix::evaporate_all() { for(unsigned int i=0;i<matrix_->size();i++) { for(unsigned int j=0;j<matrix_->size();j++) { evaporate(i,j); } } }
static void update_pheromone_trails(void) {/*{{{*/ int k; evaporate(); for (k = 0; k < M; k++) { deposit_pheromone(k); } compute_choice_information(); }/*}}}*/
void Gevap_wrap( GridCell &gc, const float spl, const int day ) { // calculate the exchange of energy between the earth's surface and the atmosphere unsigned int dn = day-1; float tair, fsun, lat, aet, pet, eet, det, par; // getting tair = gc.get_dTEMP(dn); fsun = gc.get_dFSUN(dn); // make sure that this is already between 0 & 1 lat = gc.get_Lat(); // calculations evaporate( tair, fsun, lat, spl, day, par, aet, eet, pet, det ); // setting gc.set_dAET( aet, dn ); gc.set_dEET( eet, dn ); gc.set_dPET( pet, dn ); gc.set_dDET( det, dn ); gc.set_dPAR( par, dn ); }
void Graph::train(int ants, int max_repetitions, double t0, bool reset) { if (reset) std::fill(pheromone[0], pheromone[0] + m * n, t0); double **tmp = new double*[m]; tmp[0] = new double[m * n]; for (int i = 1; i < m; ++i) tmp[i] = tmp[i - 1] + n; for (int r = 0; r < max_repetitions; ++r) { evaporate(); std::copy(pheromone[0], pheromone[0] + m * n, tmp[0]); for (int a = 0; a < ants; ++a) { auto solution = buildSolution(); updatePheromone(tmp, solution); } std::copy(tmp[0], tmp[0] + m * n, pheromone[0]); } delete[] tmp[0]; delete[] tmp; }
void ants::start() { clrscr(); randomize(); fstream fin("tabu.txt",ios::out); nmin=t;nmax=0; for(int i=0;i<q;i++) { int *tour=generate(); float eff1=evaluate(tour); //cout<<eff1<<' '<<i<<' '; //getch(); fin<<eff1<<'\t'; for(int xi=0;xi<m+n;xi++) fin<<btour[xi]<<' '; fin<<endl; if(eff1>nmax && eff1>nmin) { //cout<<eff1<<endl; //fin<<eff1<<endl; nmax=eff1; for(int xi=0;xi<m+n;xi++) btour[xi]=tour[xi]; updatepher(tour,eff1); } evaporate(); //cout<<endl; delete tour; } cout<<"best tour"<<endl; for(int xi=0;xi<m+n;xi++) cout<<btour[xi]<<' '; cout<<"max eff= : "<<nmax<<endl; show_pm(btour); fin<<nmax; fin.close(); }