diff --git a/main.cpp b/main.cpp index f2eb1d2..15992e4 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,11 @@ #endif #ifndef ALPHA -#define ALPHA 0.9999 +#define ALPHA 0.99 +#endif + +#ifndef TEMP_MIN +#define TEMP_MIN 10 #endif int main() @@ -23,7 +27,7 @@ int main() } sa::solution act = sa::solution::simulated_annealing(capacity, items, - TEMP, ALPHA); + TEMP, ALPHA, TEMP_MIN); act.print_sol(); } diff --git a/sa.cpp b/sa.cpp index bb96228..4e8721e 100644 --- a/sa.cpp +++ b/sa.cpp @@ -2,7 +2,8 @@ #include auto sa::solution::simulated_annealing(int capacity, const std::vector &items, - const double alpha, double temp)->sa::solution + const double alpha, double temp, + const double temp_min)->sa::solution { sa::solution best(items, capacity); best.randomize(); @@ -12,8 +13,7 @@ auto sa::solution::simulated_annealing(int capacity, const std::vector rand(0, 1); - const double temp_min = 0.30; - while (temp < temp_min) { + while (temp > temp_min) { sa::solution neighbor(prev); neighbor.setneighbor(); diff --git a/sa.hpp b/sa.hpp index 320ac3b..34723c6 100644 --- a/sa.hpp +++ b/sa.hpp @@ -93,7 +93,8 @@ class solution { } static auto simulated_annealing(int capacity, const std::vector &items, - double alpha, double temp)->solution; + double alpha, double temp, + double temp_min)->solution; }; } // namespace sa