From 07cea8fa770b04b4976b9db124d150a8dd239e80 Mon Sep 17 00:00:00 2001 From: Segcolt <9hmbzr275@mozmail.com> Date: Mon, 14 Oct 2024 11:19:21 -0300 Subject: [PATCH] Change some stuff --- sa.cpp | 4 ++-- sa.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sa.cpp b/sa.cpp index 3e5f762..371ae41 100644 --- a/sa.cpp +++ b/sa.cpp @@ -19,8 +19,8 @@ auto sa::solution::simulated_annealing(int capacity, const std::vector rand(eng)) { + long long diff = neighbor.fitness - prev.fitness; + if (diff < 0 || rand(eng) / temp < 0.8) { swap(prev, neighbor); } diff --git a/sa.hpp b/sa.hpp index bec18ac..44a7f19 100644 --- a/sa.hpp +++ b/sa.hpp @@ -95,8 +95,8 @@ class box { class solution { std::vector boxes; std::default_random_engine gen; + long long fitness; int capacity; - int fitness; int iterations; int iteration; @@ -140,7 +140,7 @@ class solution { solution() = default; 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) {} solution(const std::vector &items, int capacity): // Gera a solução inicial