Skip to content

Commit

Permalink
add: automatizando captura de entrada para o furaaf
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhermeAGouveia committed Sep 1, 2023
1 parent 791a41a commit 1bbad66
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/algoritmoIlhaEscolhaProporcional.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,25 @@ void get_algoritms(int *result){

}

void print_arr_int(int *arr, int size){
for(int i = 0; i < size; i++){
if (i == size - 1)
printf("%d", arr[i]);
else
printf("%d,", arr[i]);
}
printf("\n");
}

int main(int argc, char *argv[])
{
// ./evol -t 1 -K 2 -k 3 -Q 30 -G 0 -D 68 -O 0 -L 49 -A 10
set_parameters(argc, argv); // Lê os parâmetros da linha de comando e repassa para as variáveis globais
int *algoritmos = calloc(parameters.num_algorithms, sizeof(int *));;
get_algoritms(algoritmos);
print_arr_int(algoritmos, parameters.num_algorithms);

return 0;
individuo *gbest_individuo = generate_population(1, 10, parameters.domain_function, 15);
individuo *pbest_individuo = generate_population(1, 10, parameters.domain_function, 15);
gbest_individuo->fitness = -10;
Expand Down
2 changes: 1 addition & 1 deletion src/coleta-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ set_color_progress() {
}

define_command_evol() {
echo "./evol -A $alg_config -f $function_number -t $time_limit -k 3"
echo "./evol -A $alg_config -f $function_number -t $time_limit -K 3"
}

show_indicator_algorithm() {
Expand Down
5 changes: 4 additions & 1 deletion src/furaaf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

# Coloque _ no inicio do nome dos algoritmos que não deseja executar
# Exemplo: _nome_do_algoritmo.sh
./inputForFuraaf.sh
echo "Executando o make"
export COD_NAME="algoritmoIlhaEscolhaDireta"
make
all_configurations=$(./combination 3 4 | tee)
all_configurations=$(cat ilhas.txt)
for config in $all_configurations; do
rm results/tcc/result_[$config].txt
clear
Expand Down
106 changes: 106 additions & 0 deletions src/getInputForFuraaf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @brief Este algoritmo de ilha seleciona os algoritmos que irão compor o conjunto de ilha com base na proporção de cada um, que é passada por parâmetro. Os parâmetros são:
* -Q: proporção do PSO
* -G: proporção do GA
* -D: proporção do DE
* -O: proporção do ACO
* -L: proporção do CLONALG
* O tamanho do conjunto de ilhas é passado por parâmetro com a flag -N.
*
* Exemplo de execução: ./evol -N 10 -Q 30 -G 0 -D 68 -O 0 -L 49 -K 2
*
* @author @gustavo1902
* @author @ViniciusBastoss
* @author @caioreius
* @author @GuilhermeAGouveia
* Orientador: Prof. Dr. @iagoac
* @date 2023-08-31
*/

#include <stdio.h>
#include <stdlib.h>
#include "algorithms/genetic.h"
#include "algorithms/pso.h"
#include "algorithms/clonalg.h"
#include "algorithms/aco.h"
#include "algorithms/diferencial.h"
#include "algorithms/parameters.h"
#include "algorithms/commom.h"
#include "libs/utils.h"
#include <math.h>

#define DEBUG(x)

void get_algoritms(int *result){

double soma_proporcoes = parameters.num_pso + parameters.num_aco + parameters.num_clonal + parameters.num_diferencial + parameters.num_genetico;
int cont = 0, total_islands = 0;
double total_islands_double;
proporcao_alg proporcoes[5];

proporcoes[0].proporcao = parameters.num_pso;
proporcoes[1].proporcao = parameters.num_diferencial;
proporcoes[2].proporcao = parameters.num_aco;
proporcoes[3].proporcao = parameters.num_clonal;
proporcoes[4].proporcao = parameters.num_genetico;

for(int i = 0; i < 5; i++){
total_islands_double = parameters.num_algorithms * (proporcoes[i].proporcao/soma_proporcoes);
proporcoes[i].alg = i;
if((total_islands_double - (int)total_islands_double) < 0.5)
proporcoes[i].total_islands = (int)total_islands_double;
else
proporcoes[i].total_islands = 1 + (int)total_islands_double;
total_islands += proporcoes[i].total_islands;
}

qsort(&proporcoes, 5, sizeof(proporcao_alg), comparador_proporcoes_alg);

//for(int i = 0; i < 5; i++){
// printf("proporção:%d\n",proporcoes[i].proporcao);
// }

//adiciona ilhas aos algoritmos até que total == num_algoritmos
while(total_islands < parameters.num_algorithms){
for(int i = 0; total_islands < parameters.num_algorithms && i < 5; i++){
proporcoes[i].total_islands += 1;
total_islands += 1;
}
}

while(total_islands > parameters.num_algorithms){
for(int i = 5; total_islands > parameters.num_algorithms && i > 0; i--){
proporcoes[i].total_islands -= 1;
total_islands -= 1;
}
}

//cria o vetor de algoritmos [0,0,0,1,1...]
for(int i = 0; i < 5; i++){
for(int j = 0; j < proporcoes[i].total_islands; j++, cont++){
result[cont] = proporcoes[i].alg;
}
}

}

void print_arr_int(int *arr, int size){
for(int i = 0; i < size; i++){
if (i == size - 1)
printf("%d", arr[i]);
else
printf("%d,", arr[i]);
}
printf("\n");
}

int main(int argc, char *argv[])
{
// ./evol -t 1 -K 2 -k 3 -Q 30 -G 0 -D 68 -O 0 -L 49 -A 10
set_parameters(argc, argv); // Lê os parâmetros da linha de comando e repassa para as variáveis globais
int *algoritmos = calloc(parameters.num_algorithms, sizeof(int *));;
get_algoritms(algoritmos);
print_arr_int(algoritmos, parameters.num_algorithms);

return 0;
}
13 changes: 13 additions & 0 deletions src/ilhas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1,0
0,0,1
0,0,1,1
1,3,2,0,4
0,0,3,2,1,4
1,1,3,3,4,2,0
0,0,0,0,1,1,3,4
0,0,0,0,1,1,1,3,4
3,3,3,2,2,2,0,0,4,1
3,3,3,3,3,2,2,0,0,4,1
0,0,0,0,0,3,3,3,1,1,1,2
2,2,2,2,4,4,4,4,3,3,0,0,1
0,0,0,0,0,0,4,4,4,4,4,1,1,3
13 changes: 13 additions & 0 deletions src/inputForFuraaf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
echo "Coletando as informações de entrada para o furaaf.sh"
echo "Executando o make"

export COD_NAME="getInputForFuraaf"
make

echo "Limpando ilhas.txt"
rm -rf ilhas.txt

for i in $(cat irace/results/results-island-model/results/results-evol-1-25.txt | grep "./" | cut -d'l' -f2 | sed "s/ /_/g"); do
params=$(echo $i | sed "s/_/ /g" | sed "s/A/N/g");
./evol $params >> ilhas.txt;
done
4 changes: 3 additions & 1 deletion src/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# codname = algoritmoIlhaEscolhaProporcional
codname = algoritmoIlhaEscolhaDireta
# codname = algoritmoIlhaEscolhaDireta
# codname = getInputForFuraaf
codname = ${COD_NAME}

compil:;
gcc -o evol $(codname).c ./libs/statistics.c ./libs/log.c ./libs/crossover.c ./libs/types.c ./libs/utils.c ./libs/funcoes_cec_2015/cec15_test_func.c ./libs/funcoes_cec_2015/ecr_iml.c ./libs/funcoes_cec_2015/evaluation_count_iml.c ./libs/funcoes_cec_2015/record_result_iml.c ./libs/funcoes_cec_2015/rp_iml.c ./algorithms/genetic.c ./algorithms/pso.c ./algorithms/parameters.c ./algorithms/commom.c ./algorithms/clonalg.c ./algorithms/aco.c ./algorithms/diferencial.c -lm; \
Expand Down
4 changes: 2 additions & 2 deletions src/makefile_
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
codname = <codname>

compil:;
gcc -o evol $(codname).c ./libs/statistics.c ./libs/log.c ./libs/crossover.c ./libs/types.c ./libs/utils.c ./libs/funcoes_cec_2015/cec15_test_func.c ./libs/funcoes_cec_2015/ecr_iml.c ./libs/funcoes_cec_2015/evaluation_count_iml.c ./libs/funcoes_cec_2015/record_result_iml.c ./libs/funcoes_cec_2015/rp_iml.c -lm; \
gcc -o evol $(codname).c ./libs/statistics.c ./libs/log.c ./libs/crossover.c ./libs/types.c ./libs/utils.c ./libs/funcoes_cec_2015/cec15_test_func.c ./libs/funcoes_cec_2015/ecr_iml.c ./libs/funcoes_cec_2015/evaluation_count_iml.c ./libs/funcoes_cec_2015/record_result_iml.c ./libs/funcoes_cec_2015/rp_iml.c ./algorithms/genetic.c ./algorithms/pso.c ./algorithms/parameters.c ./algorithms/commom.c ./algorithms/clonalg.c ./algorithms/aco.c ./algorithms/diferencial.c -lm; \
gcc utils/combinationK.c -o combination; \

run: compil;
./evol; \
Expand Down
3 changes: 0 additions & 3 deletions src/results/tcc/result_[0,0,0].txt

This file was deleted.

1 change: 1 addition & 0 deletions src/results/tcc/result_[1,0].txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resultado para função 1: Minimo: 126.547534 Maximo: 8386.436448 Média: 4649.74566240000000000000 Desvio padrão: 2464.07017994474973408365

0 comments on commit 1bbad66

Please sign in to comment.