diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e73fae9f30a8365647d78b7c2081f288896c5ec6..d1af05820b5c73405224f5813b0ccf7d50e5ca75 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ before_script: h1: stage: test - script: + script: - cd tests - gcc -std=c99 -o test geraMapa.c - chmod +x runTests.sh @@ -18,7 +18,7 @@ h1: - gnuplot "piores.plot" artifacts: paths: - - tests/tabuleiros.txt + - tests/tabuleiros*.txt - tests/tempos.txt - tests/medias.txt - tests/piores.txt @@ -29,7 +29,7 @@ h1: - ubuntu h2: stage: test - script: + script: - cd tests - gcc -std=c99 -o test geraMapa.c - chmod +x runTests.sh @@ -39,7 +39,7 @@ h2: - gnuplot "piores.plot" artifacts: paths: - - tests/tabuleiros.txt + - tests/tabuleiros*.txt - tests/tempos.txt - tests/medias.txt - tests/piores.txt @@ -51,7 +51,7 @@ h2: h4: stage: test - script: + script: - cd tests - gcc -std=c99 -o test geraMapa.c - chmod +x runTests.sh @@ -61,7 +61,7 @@ h4: - gnuplot "piores.plot" artifacts: paths: - - tests/tabuleiros.txt + - tests/tabuleiros*.txt - tests/tempos.txt - tests/medias.txt - tests/piores.txt @@ -73,7 +73,7 @@ h4: h6: stage: test - script: + script: - cd tests - gcc -std=c99 -o test geraMapa.c - chmod +x runTests.sh @@ -83,7 +83,7 @@ h6: - gnuplot "piores.plot" artifacts: paths: - - tests/tabuleiros.txt + - tests/tabuleiros*.txt - tests/tempos.txt - tests/medias.txt - tests/piores.txt diff --git a/libs/jogador.c b/libs/jogador.c index ee8d15d8405e6d963d826238cfaec0943acf4bda..d92e656da5ef5703438d7688212589bc5068da7c 100644 --- a/libs/jogador.c +++ b/libs/jogador.c @@ -11,13 +11,13 @@ Lista Joga(Grafo g, Lista grupo){ int counter = 1; 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; while(tamanhoLista(grupo) < tamanhoLista(g->vertices)) { // Calcula a altura int altura = calculaAltura(g, grupo); int naoConsumidos = tamanhoLista(g->vertices) - tamanhoLista(grupo); int profundidade = (sqrt(max) * (sqrt(altura) / sqrt(min)) * (altura/sqrt(naoConsumidos))); - // if(min <= 5) profundidade=altura; Lista filhos = filhosGrupo(grupo); @@ -160,12 +160,13 @@ void calculaBonus(Lista grupo, Grafo g, int profundidade) { for(No o = primeiroNoLista(g->vertices); o; o = getSucessorNo(o)) { Vertice x = (Vertice) getConteudo(o); if(x->grupo) continue; + if(x->altura < w->altura) continue; if(x->cor == w->cor) { somaCor += x->peso; } } if(w->peso == somaCor) { - w->bonus += 150; + v->bonus += 150; } } destroiLista(vFilhos, NULL); @@ -200,7 +201,7 @@ void calculaBonus(Lista grupo, Grafo g, int profundidade) { // for igual ao peso do vértice agrupado, esta é a // última jogada com aquela cor if(v->peso == somaCor) { - v->bonus += 250; // Mais bonus para que essa cor seja a escolhida + v->bonus += 350; // Mais bonus para que essa cor seja a escolhida } } @@ -215,6 +216,7 @@ int calculaBonusRec(Vertice v, Vertice pai, Grafo g, int profundidade) { Vertice filho = (Vertice) getConteudo(n); if((filho->altura > v->altura)) { int preBonus = filho->peso + calculaBonusRec(filho, v, g, profundidade-1); + Lista fFilhos = agrupaCores(filho->filhos); bonus += preBonus; } } diff --git a/tests/runTests.sh b/tests/runTests.sh index bc517cdfc5ae2687de7688266e918a35896df136..02fa15e1150e1af810bef66f5ee2aae2b4232d1e 100755 --- a/tests/runTests.sh +++ b/tests/runTests.sh @@ -23,7 +23,7 @@ echo $HEUR tempo_max=120000 #120s # tamanhos do tabuleiro -tams=(32 64 100) +tams=(3 4 8 16) # lista de cores cores=(2 3 4 6 8 10) @@ -35,7 +35,9 @@ BLUE='\033[0;34m' CYAN='\033[0;36m' NC='\033[0m' # Sem cor -echo -ne "" > tabuleiros.txt +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 @@ -57,20 +59,26 @@ do printf "%03d" $(($T_max_cor/1000000%1000)) echo -ne ")"\\r semente=$RANDOM - # echo "Usando semente: ${semente}" ./test $i $i $cor $semente + T_inicial=$(date +%s%N) - eval $MAIN < "/tmp/${semente}.in" > /tmp/resp.out + + 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.out - RESP=$(cat /tmp/resp.out | tail -n2 | head -n1) - HRESP=$(cat /tmp/heur.out | tail -n2 | head -n1) + + 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 -ne "${RED}HeurÃstica ${HEUR} fez tabuleiro ${i} ${i} ${cor} ${semente} em ${HRESP} e nós em ${RESP}${NC}\n" - echo "${i} ${i} ${cor} ${semente} (${H1})" >> tabuleiros.txt + echo -ne "${RED}HeurÃstica $(basename ${HEUR}) fez tabuleiro ${i} ${i} ${cor} ${semente} em ${HRESP} e nós em ${RESP}${NC}\n" + echo "${i} ${i} ${cor} ${semente} (${HRESP})" >> ${TABULEIROS} fi + # tempo em segundos S=$(($T_gasto/1000000000)) # tempo em milisegundos @@ -79,13 +87,10 @@ do if [ $T_max_cor -lt $T_gasto ]; then T_max_cor=$T_gasto fi - # if (($M>$tempo_max)); then - # echo -e "\n${RED}Tabuleiro ${i} ${i} ${cor} ${semente} levou mais de ${tempo_max} milisegundos: ${S}.${M}s${NC}" - # echo "${i} ${i} ${cor} ${semente}" >> tabuleiros.txt - # fi + rm "/tmp/${semente}.in" - rm "/tmp/resp.out" - rm "/tmp/heur.out" + rm "/tmp/resp${semente}.out" + rm "/tmp/heur${semente}.out" done T_medio_cor=$(($T_soma_cor/${N_TESTES})) S_medio_cor=$(($T_medio_cor/1000000000)) @@ -105,10 +110,10 @@ do echo -e "${i}\t${M_medio_total}" >> medias.txt done -fs=$(cat tabuleiros.txt | wc -l) +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.txt + cat ${TABULEIROS} exit 1 else echo -e "${GREEN}Nenhum tabuleiro perdeu para as outras heurÃsticas${NC}"