From 5b5fe6c3ab8d9f41a85a407f70fe52565faeeb92 Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Sun, 18 Jun 2017 13:34:21 -0300
Subject: [PATCH] Deixa altura da busca fixa

---
 .gitlab-ci.yml            |  58 ++++++++++++++++-
 libs/jogador.c            |  15 +++--
 tests/runTests.sh         |   4 +-
 tests/runTests.sh.example | 132 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 200 insertions(+), 9 deletions(-)
 create mode 100644 tests/runTests.sh.example

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 780ad00..da90b69 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,6 +5,7 @@ before_script:
     - apt-get update
     - apt-get -y install build-essential make autoconf gcc gnuplot
     - make
+    - mv tests/runTests.sh.example tests/runTests.sh
     - chmod +x tests/runTests.sh
     - chmod +x tests/verifica
     - gcc -std=c99 -o tests/test tests/geraMapa.c
@@ -13,6 +14,8 @@ h1:
     stage: test
     script:
         - cd tests
+        - sed -i -e 's/tams=()/tams=(4 8 16 32 64)/g' runTests.sh
+        - sed -i -e 's/cores=()/cores=(3 4 6 8 10)/g' runTests.sh
         - ./runTests.sh -h "./floodit_h1"
         - gnuplot "tempos.plot"
         - gnuplot "medias.plot"
@@ -32,6 +35,8 @@ h2:
     stage: test
     script:
         - cd tests
+        - sed -i -e 's/tams=()/tams=(4 8 16 32 64)/g' runTests.sh
+        - sed -i -e 's/cores=()/cores=(3 4 6 8 10)/g' runTests.sh
         - ./runTests.sh -h "./floodit_h2"
         - gnuplot "tempos.plot"
         - gnuplot "medias.plot"
@@ -47,11 +52,35 @@ h2:
             - tests/piores.png
     tags:
         - ubuntu
+h4-min:
+    stage: test
+    script:
+        - cd tests
+        - sed -i -e 's/tams=()/tams=(16 32)/g' runTests.sh
+        - sed -i -e 's/cores=()/cores=(4 8 10)/g' runTests.sh
+        - ./runTests.sh -h "./floodit_h4"
+        - gnuplot "tempos.plot"
+        - gnuplot "medias.plot"
+        - gnuplot "piores.plot"
+    artifacts:
+        paths:
+            - tests/tabuleiros*.txt
+            - tests/tempos.txt
+            - tests/medias.txt
+            - tests/piores.txt
+            - tests/tempos.png
+            - tests/medias.png
+            - tests/piores.png
+    tags:
+        - ubuntu
 
-h4:
+h4-max:
     stage: test
     script:
         - cd tests
+        - sed -i -e 's/tams=()/tams=(100)/g' runTests.sh
+        - sed -i -e 's/cores=()/cores=(10)/g' runTests.sh
+        - sed -i -e 's/N_TESTES=100/N_TESTES=50/g' runTests.sh
         - ./runTests.sh -h "./floodit_h4"
         - gnuplot "tempos.plot"
         - gnuplot "medias.plot"
@@ -68,10 +97,35 @@ h4:
     tags:
         - ubuntu
 
-h6:
+h6-min:
+    stage: test
+    script:
+        - cd tests
+        - sed -i -e 's/tams=()/tams=(16 32)/g' runTests.sh
+        - sed -i -e 's/cores=()/cores=(4 8 10)/g' runTests.sh
+        - ./runTests.sh -h "./floodit_h6"
+        - gnuplot "tempos.plot"
+        - gnuplot "medias.plot"
+        - gnuplot "piores.plot"
+    artifacts:
+        paths:
+            - tests/tabuleiros*.txt
+            - tests/tempos.txt
+            - tests/medias.txt
+            - tests/piores.txt
+            - tests/tempos.png
+            - tests/medias.png
+            - tests/piores.png
+    tags:
+        - ubuntu
+
+h6-max:
     stage: test
     script:
         - cd tests
+        - sed -i -e 's/tams=()/tams=(100)/g' runTests.sh
+        - sed -i -e 's/cores=()/cores=(10)/g' runTests.sh
+        - sed -i -e 's/N_TESTES=100/N_TESTES=50/g' runTests.sh
         - ./runTests.sh -h "./floodit_h6"
         - gnuplot "tempos.plot"
         - gnuplot "medias.plot"
diff --git a/libs/jogador.c b/libs/jogador.c
index 3f86f45..a0a2e1c 100644
--- a/libs/jogador.c
+++ b/libs/jogador.c
@@ -12,14 +12,19 @@ Lista Joga(Grafo g, Lista grupo){
     double max = 2*(g->x) + (sqrt(2*g->cores))*(g->x) + g->cores;
     double min = (sqrt(g->cores - 1)*g->x/2) - (g->cores/2);
     if (min < 1) min = 1;
+    int altura = calculaAltura(g, grupo);
+    int naoConsumidos = tamanhoLista(g->vertices) - tamanhoLista(grupo);
+    double razao = (altura/sqrt(naoConsumidos));
+    int profundidade = (sqrt(max) * (sqrt(altura) / sqrt(min)) * razao);
+    if(profundidade < 1) profundidade = 1;
     while(tamanhoLista(grupo) < tamanhoLista(g->vertices)) {
         // Calcula a altura
-        int altura = calculaAltura(g, grupo);
+        altura = calculaAltura(g, grupo);
 
-        int naoConsumidos = tamanhoLista(g->vertices) - tamanhoLista(grupo);
-        double razao = (altura/sqrt(naoConsumidos));
-        int profundidade = (sqrt(max) * (sqrt(altura) / sqrt(min)) * razao);
-        if(profundidade < 1) profundidade = 1;
+        // int naoConsumidos = tamanhoLista(g->vertices) - tamanhoLista(grupo);
+        // double razao = (altura/sqrt(naoConsumidos))*1.5;
+        // int profundidade = (sqrt(max) * (sqrt(altura) / sqrt(min)) * razao);
+        // if(profundidade < 1) profundidade = 1;
 
         Lista filhos = filhosGrupo(grupo);
 
diff --git a/tests/runTests.sh b/tests/runTests.sh
index 25207fc..f6e39d9 100755
--- a/tests/runTests.sh
+++ b/tests/runTests.sh
@@ -23,10 +23,10 @@ echo $HEUR
 tempo_max=120000 #120s
 
 # tamanhos do tabuleiro
-tams=(64 100)
+tams=(100)
 
 # lista de cores
-cores=(4 8 10)
+cores=(10)
 
 #-- Cores do terminal
 RED='\033[0;31m'
diff --git a/tests/runTests.sh.example b/tests/runTests.sh.example
new file mode 100644
index 0000000..60455b6
--- /dev/null
+++ b/tests/runTests.sh.example
@@ -0,0 +1,132 @@
+#!/bin/bash
+
+OPTIND=1
+MAIN="../main"
+HEUR="./floodit_h6"
+
+while getopts ":m:h:" opt; do
+    case "$opt" in
+        m)  MAIN=$OPTARG
+            ;;
+        h)  HEUR=$OPTARG
+            ;;
+    esac
+done
+
+shift $((OPTIND-1))
+[ "$1" = "--" ] && shift
+
+echo $MAIN
+echo $HEUR
+
+# tempo máximo para executar, em milisegundos
+tempo_max=120000 #120s
+
+# tamanhos do tabuleiro
+tams=()
+
+# lista de cores
+cores=()
+
+#-- Cores do terminal
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+BLUE='\033[0;34m'
+CYAN='\033[0;36m'
+NC='\033[0m' # Sem cor
+
+TABULEIROS="tabuleiros_$(basename ${HEUR}).txt"
+
+echo -ne "" > $TABULEIROS
+echo -ne "#Tam tabuleiro\t#N cores\t#Tempo médio\n" > tempos.txt
+echo -ne "#Tam tabuleiro\t#Tempo médio\n" > medias.txt
+echo -ne "#Tam tabuleiro\t#N cores\t#Tempo médio\n" > piores.txt
+
+echo "Iniciado testes"
+for i in ${tams[*]}
+do
+    echo "Tamanho do tabuleiro: ${i}"
+    T_soma_total=0
+    for cor in ${cores[*]}
+    do
+        echo "Número de cores: ${cor}"
+        T_soma_cor=0
+        T_max_cor=0
+        N_TESTES=100
+        VIT=0
+        EMP=0
+        DER=0
+        for j in $(seq 1 ${N_TESTES})
+        do
+            semente=$RANDOM
+            ./test $i $i $cor $semente
+
+            T_inicial=$(date +%s%N)
+
+            eval $MAIN < "/tmp/${semente}.in" > "/tmp/resp${semente}.out"
+
+            T_gasto=$(($(date +%s%N) - $T_inicial))
+            T_soma_cor=$(($T_gasto + $T_soma_cor))
+            T_soma_total=$(($T_gasto + $T_soma_total))
+
+            eval $HEUR < "/tmp/${semente}.in" > "/tmp/heur${semente}.out"
+
+            RESP=$(cat "/tmp/resp${semente}.out" | tail -n2 | head -n1)
+            HRESP=$(cat "/tmp/heur${semente}.out" | tail -n2 | head -n1)
+
+            if [ $RESP -gt $HRESP ]; then
+                echo "${i} ${i} ${cor} ${semente} (${HRESP})" >> ${TABULEIROS}
+                DER=$(($DER + 1))
+            fi
+            if [ $RESP -eq $HRESP ]; then
+                EMP=$(($EMP + 1))
+            fi
+            if [ $RESP -lt $HRESP ]; then
+                VALIDO=$(cat "/tmp/${semente}.in" "/tmp/resp${semente}.out" | ./verifica)
+                if [[ $VALIDO -eq 1 ]]; then
+                    echo -ne "${RED}Nossa resposta para ${i} ${i} ${cor} ${semente} não é válida!!!${NC}\n\n"
+                fi
+                VIT=$(($VIT + 1))
+            fi
+            # tempo em segundos
+            S=$(($T_gasto/1000000000))
+            # tempo em milisegundos
+            M=$(($T_gasto/1000000))
+            # tempo máximo por cor
+            if [ $T_max_cor -lt $T_gasto ]; then
+                T_max_cor=$T_gasto
+            fi
+
+            rm "/tmp/${semente}.in"
+            rm "/tmp/resp${semente}.out"
+            rm "/tmp/heur${semente}.out"
+
+            echo -ne "Tabuleiro ${i}x${i} com ${cor} cores: (${j}/${N_TESTES}) (T max: $(($T_max_cor/1000000000))."
+            printf "%03d" $(($T_max_cor/1000000%1000))
+            echo -ne ") (${GREEN}${VIT}${NC}/${BLUE}${EMP}${NC}/${RED}${DER}${NC})"\\r
+        done
+        T_medio_cor=$(($T_soma_cor/${N_TESTES}))
+        S_medio_cor=$(($T_medio_cor/1000000000))
+        M_medio_cor=$(($T_medio_cor/1000000))
+        echo -ne "\n${CYAN}Tempo médio com ${cor} cores: ${S_medio_cor}."
+        printf "%03d" $((${M_medio_cor}%1000))
+        echo -e "s (${T_medio_cor})${NC}\n"
+        echo -e "${i}\t${cor}\t${M_medio_cor}" >> tempos.txt
+        echo -e "${i}\t${cor}\t$(($T_max_cor/1000000))" >> piores.txt
+    done
+    T_medio_total=$(( $T_soma_total/(${N_TESTES} * ${#cores[*]}) ))
+    S_medio_total=$(($T_medio_total/1000000000))
+    M_medio_total=$(($T_medio_total/1000000))
+    echo -ne "${BLUE}Tempo médio com tamanho ${i}: ${S_medio_total}."
+    printf "%03d" $((${M_medio_total}%1000))
+    echo -e "s (${T_medio_total})${NC}\n"
+    echo -e "${i}\t${M_medio_total}" >> medias.txt
+done
+
+fs=$(cat "${TABULEIROS}" | wc -l)
+if [ ${fs} -gt "1" ]; then
+    echo -e "${RED}${fs} tabuleiro(s) perdeu(perderam) para outras heurísticas${NC}"
+    cat ${TABULEIROS}
+else
+    echo -e "${GREEN}Nenhum tabuleiro perdeu para as outras heurísticas${NC}"
+fi
-- 
GitLab