Compare commits
4 Commits
6fb7e5bf68
...
6dc06d021a
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dc06d021a | |||
| 2f53e5de27 | |||
| a1d6ed7d75 | |||
| 07cea8fa77 |
28
run.bat
28
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
|
||||
@ECHO off
|
||||
setlocal enabledelayedexpansion
|
||||
echo %TIME%
|
||||
|
||||
if not defined EXEC (
|
||||
set EXEC="build\solucao.exe"
|
||||
)
|
||||
@ -10,16 +10,14 @@ 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%
|
||||
)
|
||||
|
||||
for /f "tokens=1,2 skip=1" %%a in (%SOLUTIONS_FILE%) do (
|
||||
set solutions[%%a]=%%b
|
||||
if defined SOLUTIONS_FILE (
|
||||
for /f "tokens=1,2 skip=1" %%a in (%SOLUTIONS_FILE%) do (
|
||||
set solutions[%%a]=%%b
|
||||
)
|
||||
)
|
||||
|
||||
for %%g in (%TEST_FOLDER%\*) do (
|
||||
@ -29,15 +27,17 @@ 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!
|
||||
echo Resultado ótimo: !optimal!
|
||||
if !res! EQU !optimal! (
|
||||
echo Resultado ótimo^^!
|
||||
) else (
|
||||
set /a diff= !res!-!optimal!
|
||||
echo Diferença de !diff!
|
||||
if defined optimal (
|
||||
echo Resultado ótimo: !optimal!
|
||||
if !res! EQU !optimal! (
|
||||
echo Resultado ótimo^^!
|
||||
) else (
|
||||
set /a diff= !res!-!optimal!
|
||||
echo Diferença de !diff!
|
||||
)
|
||||
)
|
||||
)
|
||||
echo %TIME%
|
||||
|
||||
endlocal
|
||||
set EXEC=
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
6
sa.hpp
6
sa.hpp
@ -94,9 +94,9 @@ class box {
|
||||
|
||||
class solution {
|
||||
std::vector<box> boxes;
|
||||
std::default_random_engine gen;
|
||||
std::mt19937_64 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