Compare commits

..

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

3 changed files with 19 additions and 19 deletions

28
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 :: 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 @ECHO off
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
echo %TIME%
if not defined EXEC ( if not defined EXEC (
set EXEC="build\solucao.exe" set EXEC="build\solucao.exe"
) )
@ -10,14 +10,16 @@ if not defined TEST_FOLDER (
set TEST_FOLDER=Teste\Casos set TEST_FOLDER=Teste\Casos
) )
if not defined SOLUTIONS_FILE (
set SOLUTIONS_FILE=Teste\Solucoes.txt
)
if defined ARGS ( if defined ARGS (
set ARGS=-%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
set solutions[%%a]=%%b
)
) )
for %%g in (%TEST_FOLDER%\*) do ( for %%g in (%TEST_FOLDER%\*) do (
@ -27,17 +29,15 @@ for %%g in (%TEST_FOLDER%\*) do (
echo Arquivo de teste: %%g echo Arquivo de teste: %%g
for /f "tokens=4" %%h in ('!EXEC! !ARGS! ^< %%g') do set res=%%h for /f "tokens=4" %%h in ('!EXEC! !ARGS! ^< %%g') do set res=%%h
echo Resultado do programa: !res! echo Resultado do programa: !res!
if defined optimal ( echo Resultado ótimo: !optimal!
echo Resultado ótimo: !optimal! if !res! EQU !optimal! (
if !res! EQU !optimal! ( echo Resultado ótimo^^!
echo Resultado ótimo^^! ) else (
) else ( set /a diff= !res!-!optimal!
set /a diff= !res!-!optimal! echo Diferença de !diff!
echo Diferença de !diff!
)
) )
) )
echo %TIME%
endlocal endlocal
set EXEC= set EXEC=
set TEST_FOLDER= 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); sa::solution neighbor(prev, iteration);
neighbor.setneighbor(); neighbor.setneighbor();
long long diff = neighbor.fitness - prev.fitness; int diff = neighbor.fitness - prev.fitness;
if (diff < 0 || rand(eng) / temp < 0.8) { if (diff <= 0 || std::exp(-diff / temp) > rand(eng)) {
swap(prev, neighbor); swap(prev, neighbor);
} }

6
sa.hpp
View File

@ -94,9 +94,9 @@ class box {
class solution { class solution {
std::vector<box> boxes; std::vector<box> boxes;
std::mt19937_64 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),
fitness(other.fitness), capacity(other.capacity), capacity(other.capacity), fitness(other.fitness),
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