Compare commits

..

No commits in common. "6dc06d021a998118a894963290bbe75c5b27625a" and "6fb7e5bf68146d27a918e08f550f2cc85d75fa79" have entirely different histories.

3 changed files with 19 additions and 19 deletions

14
run.bat
View File

@ -1,7 +1,7 @@
:: Uso: [set EXEC="caminho\do\executavel.exe"]&&[set TEST_FOLDER=caminho\dos\casetests]&&[set ARGS=ic]&&[set SOLUTIONS_FILE=arquivo\de\solucoes.txt]&&run.bat
@ECHO off
setlocal enabledelayedexpansion
echo %TIME%
if not defined EXEC (
set EXEC="build\solucao.exe"
)
@ -10,14 +10,16 @@ if not defined TEST_FOLDER (
set TEST_FOLDER=Teste\Casos
)
if not defined SOLUTIONS_FILE (
set SOLUTIONS_FILE=Teste\Solucoes.txt
)
if defined ARGS (
set ARGS=-%ARGS%
)
if defined SOLUTIONS_FILE (
for /f "tokens=1,2 skip=1" %%a in (%SOLUTIONS_FILE%) do (
for /f "tokens=1,2 skip=1" %%a in (%SOLUTIONS_FILE%) do (
set solutions[%%a]=%%b
)
)
for %%g in (%TEST_FOLDER%\*) do (
@ -27,7 +29,6 @@ for %%g in (%TEST_FOLDER%\*) do (
echo Arquivo de teste: %%g
for /f "tokens=4" %%h in ('!EXEC! !ARGS! ^< %%g') do set res=%%h
echo Resultado do programa: !res!
if defined optimal (
echo Resultado ótimo: !optimal!
if !res! EQU !optimal! (
echo Resultado ótimo^^!
@ -35,9 +36,8 @@ for %%g in (%TEST_FOLDER%\*) do (
set /a diff= !res!-!optimal!
echo Diferença de !diff!
)
)
)
echo %TIME%
endlocal
set EXEC=
set TEST_FOLDER=

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);
neighbor.setneighbor();
long long diff = neighbor.fitness - prev.fitness;
if (diff < 0 || rand(eng) / temp < 0.8) {
int diff = neighbor.fitness - prev.fitness;
if (diff <= 0 || std::exp(-diff / temp) > rand(eng)) {
swap(prev, neighbor);
}

6
sa.hpp
View File

@ -94,9 +94,9 @@ class box {
class solution {
std::vector<box> boxes;
std::mt19937_64 gen;
long long fitness;
std::default_random_engine gen;
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),
fitness(other.fitness), capacity(other.capacity),
capacity(other.capacity), fitness(other.fitness),
iteration(itr) {}
solution(const std::vector<long long> &items, int capacity): // Gera a solução inicial