Change some stuff

This commit is contained in:
Segcolt 2024-10-14 11:19:21 -03:00
parent d3b3e682db
commit 07cea8fa77
2 changed files with 4 additions and 4 deletions

4
sa.cpp
View File

@ -19,8 +19,8 @@ auto sa::solution::simulated_annealing(int capacity, const std::vector<long long
sa::solution neighbor(prev, iteration); sa::solution neighbor(prev, iteration);
neighbor.setneighbor(); neighbor.setneighbor();
int diff = neighbor.fitness - prev.fitness; long long diff = neighbor.fitness - prev.fitness;
if (diff <= 0 || std::exp(-diff / temp) > rand(eng)) { if (diff < 0 || rand(eng) / temp < 0.8) {
swap(prev, neighbor); swap(prev, neighbor);
} }

4
sa.hpp
View File

@ -95,8 +95,8 @@ class box {
class solution { class solution {
std::vector<box> boxes; std::vector<box> boxes;
std::default_random_engine gen; std::default_random_engine gen;
long long fitness;
int capacity; int capacity;
int fitness;
int iterations; int iterations;
int iteration; int iteration;
@ -140,7 +140,7 @@ class solution {
solution() = default; solution() = default;
solution(const solution &other, int itr): boxes(other.boxes), gen(other.gen), solution(const solution &other, int itr): boxes(other.boxes), gen(other.gen),
capacity(other.capacity), fitness(other.fitness), fitness(other.fitness), capacity(other.capacity),
iteration(itr) {} iteration(itr) {}
solution(const std::vector<long long> &items, int capacity): // Gera a solução inicial solution(const std::vector<long long> &items, int capacity): // Gera a solução inicial