Skip to content
Snippets Groups Projects
Commit c3c578aa authored by Cyprien Borée's avatar Cyprien Borée
Browse files

replace HC with PLS

parent 649bc99c
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,7 @@ int main(int argc, char* argv[]){ ...@@ -16,8 +16,7 @@ int main(int argc, char* argv[]){
unsigned INITIAL_SOLUTIONS = 1000000; unsigned INITIAL_SOLUTIONS = 1000000;
unsigned ARCHIVE_BOUND = 100; unsigned ARCHIVE_BOUND = 100;
unsigned MAX_ITER = 100; long long int TIME_LIMIT = 20000; //ms
long long int TIME_LIMIT = 20; //ms per solution
std::cout << "Reading instance files..." << std::endl; std::cout << "Reading instance files..." << std::endl;
tsp::TSP tsp_instance1("../../instances/tsp/tsp_test/cgC50_10_01.txt"); tsp::TSP tsp_instance1("../../instances/tsp/tsp_test/cgC50_10_01.txt");
...@@ -41,38 +40,29 @@ int main(int argc, char* argv[]){ ...@@ -41,38 +40,29 @@ int main(int argc, char* argv[]){
std::cout << "Initial archive contains " << bounded_archive.size() << " solutions : " << std::endl; std::cout << "Initial archive contains " << bounded_archive.size() << " solutions : " << std::endl;
std::cout << bounded_archive << std::endl; std::cout << bounded_archive << std::endl;
opt::TimeCriterion<SOL> time_criterion(TIME_LIMIT); opt::TimeCriterion<BOUNDED_ARCHIVE> time_criterion(TIME_LIMIT);
for(unsigned i = 0; i < MAX_ITER; ++i){ core::HammingDiversityCriterion<SOL> global_diversity;
// Pick a random solution within the archive.
SOL tmp_sol;
if(bounded_archive.size()){
unsigned random_sol_idx = core::RNGHelper::get()->random(bounded_archive.size());
tmp_sol = bounded_archive[random_sol_idx];
}else{
tmp_sol = bounded_archive[0];
}
// Explore solution's neighborhood. std::cout << "initial global diversity: " << global_diversity.recompute_all(bounded_archive) << std::endl;
representation::TwoOptNeighbor<SOL> optNeighbor;
opt::OrderNeighborhood<SOL> orderNeighborhood(optNeighbor); opt::SelectAll<BOUNDED_ARCHIVE> *select = new opt::SelectAll<BOUNDED_ARCHIVE>();
opt::FirstImprNeighborhoodExplorer<SOL> firstImprNeighborhoodExplorer(orderNeighborhood, eval);
opt::HillClimbing<SOL> hillClimbing(firstImprNeighborhoodExplorer, eval); representation::TwoOptNeighbor<SOL> twoOptNeighbor;
optNeighbor.init(tmp_sol); opt::RndWithoutRemplNeighborhood<SOL> rndWithoutRemplNeighborhood(twoOptNeighbor);
hillClimbing.init(tmp_sol);
auto initial_fitness = tmp_sol.fitness(); opt::Neighborhood<SOL> *neighborhood = &rndWithoutRemplNeighborhood;
hillClimbing(tmp_sol,time_criterion);
auto new_fitness = tmp_sol.fitness();
opt::Explorer<BOUNDED_ARCHIVE> *explorer = new opt::NDomExplorer<BOUNDED_ARCHIVE>(*neighborhood, eval);
if(new_fitness > initial_fitness){ opt::ParetoLocalSearch<BOUNDED_ARCHIVE> *paretoLocalSearch = new opt::ParetoLocalSearch<BOUNDED_ARCHIVE>(*select, *explorer);
std::cout << "fitness improved!" << std::endl;
}
bounded_archive(tmp_sol);
}
time_criterion.init();
paretoLocalSearch->operator()(bounded_archive, time_criterion);
std::cout << "Final archive contains " << bounded_archive.size() << " solutions : " << std::endl; std::cout << "Final archive contains " << bounded_archive.size() << " solutions : " << std::endl;
std::cout << bounded_archive << std::endl; std::cout << bounded_archive << std::endl;
std::cout << "final global diversity: " << global_diversity.recompute_all(bounded_archive) << std::endl;
std::cout << "Program ended!" << std::endl; std::cout << "Program ended!" << std::endl;
return 0; return 0;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment