std::multimap<double,unsigned int,Ant::MultiMapComp> Ant::get_feasible_vertices(OptimizationProblem &op, PheromoneMatrix &pheromones, double alpha, double beta) { std::map<unsigned int,double> vertices; bool should_debug = false; if(current_vertex() == -1) { vertices = op.get_feasible_start_vertices(); } else { vertices = op.get_feasible_neighbours(current_vertex()); } double denominator = 0.0; std::map<unsigned int,double>::iterator it; for(it=vertices.begin();it!=vertices.end();it++) { unsigned int vertex = (*it).first; double heuristic_value = (*it).second; if(current_vertex() == -1) { double numerator = pow(pheromones.get(pheromones.size()-1, vertex), alpha) * pow(heuristic_value, beta); (*it).second = numerator; denominator += numerator; } else { double numerator = pow(pheromones.get(current_vertex(), vertex), alpha) * pow(heuristic_value, beta); (*it).second = numerator; denominator += numerator; if (should_debug) { std::cerr << "\tEdge to " << vertex << std::endl; std::cerr << "\tpow(" << pheromones.get(current_vertex(), vertex) << "," << alpha << ") * pow(" << heuristic_value << "," << beta << ")" << std::endl; std::cerr << "\tNumertor is " << numerator << " and current denom = " << denominator << std::endl; } } } std::multimap<double,unsigned int,MultiMapComp> probabilities; for(it=vertices.begin();it!=vertices.end();it++) { //std::cout << pheromones.get(pheromones.size()-1, (*it).first) << std::endl; unsigned int vertex = (*it).first; //double heuristic_value = (*it).second; double probability; if(denominator == 0) { probability = 1.0 / vertices.size(); } else { probability = (*it).second / denominator; } if (should_debug) std::cerr << "Edge to " << vertex << " has probability " << probability << std::endl; //std::cout << pheromones.get(current_vertex(), vertex) << " " << heuristic_value << std::endl; //std::cout << "vertex: " << vertex << " heuristic: " << heuristic_value << " probability: " << probability << std::endl; probabilities.insert(std::pair<double,unsigned int>(probability, vertex)); } //std::cout << "***************************************" << std::endl; return probabilities; }