From dd2aacb284a4c381d6bcc0423dd6d710b1971cdc Mon Sep 17 00:00:00 2001 From: Daneck1988 Date: Sun, 13 Oct 2024 08:53:37 -0300 Subject: [PATCH] =?UTF-8?q?Adicionados=20flags=20para=20truncar=20sa=C3=AD?= =?UTF-8?q?da?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 16 ++++++++++++++-- run.bat | 8 ++++++-- sa.hpp | 40 +++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/main.cpp b/main.cpp index f3db368..5f06795 100644 --- a/main.cpp +++ b/main.cpp @@ -15,8 +15,20 @@ #define TEMP_MIN 0.01 #endif -int main() +int main(int argc, char *argv[]) { + char flags = 0; + for(int i = 1; i < argc; i++){ + if(argv[i][0] == '-'){ + int j = 1; + while(argv[i][j] != '\0'){ + if(argv[i][j] == 'i') flags |= SIMULATED_ANNEALING_DISABLE_SHOWITRNUM; + else if(argv[i][j] == 'c') flags |= SIMULATED_ANNEALING_DISABLE_SHOWCRATES; + j++; + } + } + } + int number_of_items = 0; int capacity = 0; std::cin >> number_of_items >> capacity; @@ -29,5 +41,5 @@ int main() sa::solution act = sa::solution::simulated_annealing(capacity, items, ALPHA, TEMP, TEMP_MIN); - act.print_sol(); + act.print_sol(flags); } diff --git a/run.bat b/run.bat index d0f3765..f29074e 100644 --- a/run.bat +++ b/run.bat @@ -1,4 +1,4 @@ -:: Uso: [set EXEC="caminho/do/executavel.exe"] && [set TEST_FOLDER="caminho/dos/casetests"] && run.bat +:: Uso: [set EXEC="caminho/do/executavel.exe"] && [set TEST_FOLDER=caminho/dos/casetests] && [set ARGS=ic] && run.bat @ECHO off if not defined EXEC ( @@ -11,5 +11,9 @@ if not defined TEST_FOLDER ( for %%g in (%TEST_FOLDER%/*) do ( echo Arquivo de teste: %TEST_FOLDER%/%%g - %EXEC% < %TEST_FOLDER%/%%g + if defined ARGS ( + %EXEC% -%ARGS% < %TEST_FOLDER%/%%g + ) else ( + %EXEC% < %TEST_FOLDER%/%%g + ) ) \ No newline at end of file diff --git a/sa.hpp b/sa.hpp index f28a5c0..15a8933 100644 --- a/sa.hpp +++ b/sa.hpp @@ -1,5 +1,7 @@ #ifndef SIMULATED_ANNEALING_HEADER_12647_H #define SIMULATED_ANNEALING_HEADER_12647_H +#define SIMULATED_ANNEALING_DISABLE_SHOWCRATES 1 +#define SIMULATED_ANNEALING_DISABLE_SHOWITRNUM 2 #include #include @@ -105,28 +107,32 @@ class solution { std::swap(iteration, other.iteration); } - void print_sol() const { - std::cout << "Iteração da solução: " << iteration << '\n'; - std::cout << "Número de iterações calculadas: " << iterations << '\n'; + void print_sol(char flags = 0) const { + if(!(flags & SIMULATED_ANNEALING_DISABLE_SHOWITRNUM)){ + std::cout << "Iteração da solução: " << iteration << '\n'; + std::cout << "Número de iterações calculadas: " << iterations << '\n'; + } std::cout << "Número de caixas: " << fitness << '\n'; - int box_now = 1; - long long now = 0; - std::queue items_stored; + if(!(flags & SIMULATED_ANNEALING_DISABLE_SHOWCRATES)){ + int box_now = 1; + long long now = 0; + std::queue items_stored; - for (auto i : items) { - if (now + i > capacity) { - print_box(box_now, items_stored); - box_now++; - now = i; - } else { - now += i; + for (auto i : items) { + if (now + i > capacity) { + print_box(box_now, items_stored); + box_now++; + now = i; + } else { + now += i; + } + items_stored.push(i); } - items_stored.push(i); - } - print_box(box_now, items_stored); - std::cout << '\n'; + print_box(box_now, items_stored); + std::cout << '\n'; + } } void setiterations(int itr) {