Example #1
0
void ACSAnt::construct_pseudorandom_proportional_solution(OptimizationProblem &op, PheromoneMatrix &pheromones, double alpha, double beta) {
  while(!op.is_tour_complete(tour->get_vertices())) {
    std::multimap<double,unsigned int,MultiMapComp> vertices = get_feasible_vertices(op, pheromones, 1.0, beta);
    unsigned int q = Util::random_number(RAND_MAX);
    double q0 = q0_ * RAND_MAX;
    unsigned int vertex;
    if (q < q0) {
      vertex = (*vertices.begin()).second;
    } else {
      vertex = choose_next_vertex_with_likelihood(vertices);
    }
    add_vertex_to_tour(op, vertex);
  }
  update_tour_length(op);
  op.cleanup();

  //local pheromone update
  for(unsigned int i=0;i<tour->size();i++) {
    if(i==0) {
      ((ACSPheromoneMatrix &) pheromones).local_pheromone_update(pheromones.size()-1, (*tour)[i]);
    } else {
      ((ACSPheromoneMatrix &) pheromones).local_pheromone_update((*tour)[i-1], (*tour)[i]);
    }
  }
}
Example #2
0
void Ant::construct_rational_solution(OptimizationProblem &op, PheromoneMatrix &pheromones, double alpha, double beta) {
  while(!op.is_tour_complete(tour->get_vertices())) {
    std::multimap<double,unsigned int,MultiMapComp> vertices = get_feasible_vertices(op, pheromones, alpha, beta);
    unsigned int vertex = (*vertices.begin()).second;
    add_vertex_to_tour(op, vertex);
  }
  update_tour_length(op);
  op.cleanup();
}
Example #3
0
void Ant::construct_random_proportional_solution(OptimizationProblem &op, PheromoneMatrix &pheromones, double alpha, double beta) {
  while(!op.is_tour_complete(tour->get_vertices())) {
    std::multimap<double,unsigned int,MultiMapComp> vertices = get_feasible_vertices(op, pheromones, alpha, beta);
    unsigned int vertex = choose_next_vertex_with_likelihood(vertices);
    add_vertex_to_tour(op, vertex);
  }
  update_tour_length(op);
  op.cleanup();
}