I am an idiot :)

This commit is contained in:
Segcolt 2024-10-12 18:53:12 -03:00
parent cd382540a4
commit d8086caa18
3 changed files with 11 additions and 6 deletions

View File

@ -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();
}

6
sa.cpp
View File

@ -2,7 +2,8 @@
#include <cmath>
auto sa::solution::simulated_annealing(int capacity, const std::vector<long long> &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<long long
std::default_random_engine eng(rdevice());
std::uniform_real_distribution<> rand(0, 1);
const double temp_min = 0.30;
while (temp < temp_min) {
while (temp > temp_min) {
sa::solution neighbor(prev);
neighbor.setneighbor();

3
sa.hpp
View File

@ -93,7 +93,8 @@ class solution {
}
static auto simulated_annealing(int capacity, const std::vector<long long> &items,
double alpha, double temp)->solution;
double alpha, double temp,
double temp_min)->solution;
};
} // namespace sa