From 6c7ba2832062be7f93b50bdf6f1ad74173d51b2e Mon Sep 17 00:00:00 2001 From: Segcolt <9hmbzr275@mozmail.com> Date: Sun, 13 Oct 2024 11:41:05 -0300 Subject: [PATCH] Upgrade the script --- run.sh | 19 ++++++++++++++++++- sa.cpp | 1 - 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index 271657f..b15392f 100755 --- a/run.sh +++ b/run.sh @@ -10,7 +10,24 @@ if [[ -z $TEST_FOLDER ]]; then TEST_FOLDER="test" fi +if [[ -z $SOLUTIONS_FILE ]]; then + SOLUTIONS_FILE=solucoes.txt +fi + +declare -A solutions +while read line; do + solutions[$(awk '{print $1}' <<< "$line")]=$(awk '{print $2}' <<< "$line") +done < "$SOLUTIONS_FILE" + for file in $(find "$TEST_FOLDER" -type f); do echo "Arquivo de teste: $file" - "$EXEC" < "$file" + res=$("$EXEC" -i -c < "$file" | awk '{print $4}') + optimal=${solutions[$(basename "$file")]} + echo "Resultado do programa: ${res}" + echo "Resultado ótimo: ${optimal}" + if [[ $res = $optimal ]]; then + echo "Resultado ótimo!" + else + echo "Diferença de $(bc <<< "${res} - ${optimal}")" + fi done diff --git a/sa.cpp b/sa.cpp index c2cebf8..14cfc81 100644 --- a/sa.cpp +++ b/sa.cpp @@ -27,7 +27,6 @@ auto sa::solution::simulated_annealing(int capacity, const std::vector