Compare commits
No commits in common. "6dc06d021a998118a894963290bbe75c5b27625a" and "6fb7e5bf68146d27a918e08f550f2cc85d75fa79" have entirely different histories.
6dc06d021a
...
6fb7e5bf68
14
run.bat
14
run.bat
@ -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,7 +29,6 @@ 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^^!
|
||||||
@ -35,9 +36,8 @@ for %%g in (%TEST_FOLDER%\*) do (
|
|||||||
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
4
sa.cpp
@ -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
6
sa.hpp
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user