Change some stuff
This commit is contained in:
parent
d3b3e682db
commit
07cea8fa77
4
sa.cpp
4
sa.cpp
@ -19,8 +19,8 @@ auto sa::solution::simulated_annealing(int capacity, const std::vector<long long
|
||||
sa::solution neighbor(prev, iteration);
|
||||
neighbor.setneighbor();
|
||||
|
||||
int diff = neighbor.fitness - prev.fitness;
|
||||
if (diff <= 0 || std::exp(-diff / temp) > rand(eng)) {
|
||||
long long diff = neighbor.fitness - prev.fitness;
|
||||
if (diff < 0 || rand(eng) / temp < 0.8) {
|
||||
swap(prev, neighbor);
|
||||
}
|
||||
|
||||
|
||||
4
sa.hpp
4
sa.hpp
@ -95,8 +95,8 @@ class box {
|
||||
class solution {
|
||||
std::vector<box> 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<long long> &items, int capacity): // Gera a solução inicial
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user