Esempio n. 1
0
t_cycle opt_cycle(int nbVilles, double ** distances, t_cycle cycle) {
  if(nbVilles > 4) {
    for(int i = 0; i < nbVilles - 5; i ++) {
      cycle = two_opt(i, nbVilles, distances, cycle);
    }
  }
  return cycle;
}
Esempio n. 2
0
File: ant.c Progetto: gpolo/QAP
void aco_local_search(QAP_t *prob){
    int i = 0;
    calc_reduction_exchange function = (prob->flags & SYMMETRIC)? symmetric_calc_reduction : asymmetric_calc_reduction;

    for (i = 0; i < prob->nants; i++){
        two_opt(prob, ant[i], function); 
        if (ant[i]->cst < best_solution->cst){
            *best_solution = *ant[i]; 
            best_solution->time = current_user_time_secs();
            //if ((prob->flags & BESTSTOP) && (best_solution->cst == prob->best_know_solution)) break;
            if ((prob->flags & BESTSTOP) && (best_solution->cst == prob->best_know_solution)) found_artificial_value = 1;
        }
    }
}
int main (int argc, char **argv)
{
  EDAMetasearchStart (argc, argv);
  if (argc != 2)
  {
    std::cerr << "Usage : ./" <<  __progname
              << " [instance]" << std::endl;
  }
  else
  {
            
    Graph graph(argv[1]);
    edaSolutionList list;
    for(unsigned int i = 0; i < 40; i++) {
      tspSolution *route = new tspSolution (graph); 
      route->init();
      list.push_back(route);
    }	     

    
    tspTwoOpt two_opt (graph);
    tspTwoOptNext two_opt_next (graph);   
    edaFirstImprSelect moveSelect;
    edaGenContinue cont(1500);  
    edaHC hcSearch (&two_opt, &two_opt_next, &moveSelect, &cont); 
    
    // Use the declaration below to run on single machine:
    edaSeqWrapperControl sfControl;          
    sfControl.insertVertex (&hcSearch);  
    if (!sfControl.search (list))
    {
      cerr << "Error: Cannot execute search" << endl;
    }
    else
    {
      tspSolution route = *( (tspSolution*) list.getBest() );
      cout << "[Route] " << route << endl;
      cout << "[Fitness] " << route.evaluate () << endl;
//      route.save("route.txt");
    }
  }

  EDAMetasearchStop ();

  return 0;
}
Esempio n. 4
0
int main (int argc, char **argv)
{
  EDAMetasearchStart (argc, argv);

  if (argc != 2)
  {
    std::cerr << "Usage : ./" <<  __progname
              << " [instance]" << std::endl;
  }
  else
  {    

    Graph graph(argv[1]);
  
    edaSolutionList list;
    for(unsigned int i = 0; i < 20; i++) {
      tspSolution *route = new tspSolution (graph); 
      route->init();
      list.push_back(route);
    }	     

    tspTwoOpt two_opt (graph);
    tspTwoOptNext two_opt_next (graph);      
    edaFirstImprSelect moveSelect;
    edaGenContinue cont(1500);      
    edaHC hcSearch (&two_opt, &two_opt_next, &moveSelect, &cont);   

    tspTwoOptMoveRandom two_ran_opt (graph);
    edaExpCoolingSchedule coolingSchedule (0.01, 0.98);
    edaSA saSearch (&two_opt, &two_ran_opt, &cont,
            50, &coolingSchedule);        

    edaSimpleMoveTabuList tabuList;
    edaImprBestFitAspirCrit aspirCrit;
    edaTS tsSearch (&two_opt, &two_opt_next, &tabuList, &aspirCrit, &cont);   
    
    
    // Use the declaration below to run on single machine:
    edaSeqWrapperControl sfControl; 
    edaFullSelectWrapper fSlect;
    
    int said0 = sfControl.insertVertex (&saSearch, fSlect);     
    int tsid1 = sfControl.insertVertex (&tsSearch, fSlect);
    int hcid2 = sfControl.insertVertex (&hcSearch, fSlect);
    
    sfControl.insertEdge(said0, tsid1);
    sfControl.insertEdge(tsid1, hcid2);
    
    if (!sfControl.search (list))
    {
      std::cerr << "Error: Cannot execute search" << std::endl;
    }
    else
    {
      tspSolution route = *( (tspSolution*) list[0]);
      std::cout << "[Route] " << route << std::endl;
      std::cout << "[Fitness] " << route.evaluate () << std::endl;
    }
  }

  EDAMetasearchStop ();

  return 0;
}