Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug de estouro de memória nas medidas geneticas #59

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/algorithms/aco.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ populacao *aco(populacao *population, int epoca_num, int population_num)
int generations_count = 0;
while (generations_count < parameters.num_generations_per_epoca && difftime(time_now, time_init) < parameters.time_limit)
{
DEBUG(print_individuo(individuos, d, best_individuo););
DEBUG(print_individuo(*individuos, d, best_individuo););
// Move each individuo to a new individuo_chromossome
select_next_position(pheromones, individuos, d, best_individuo);
evaporate_pheromones(pheromones, d);
Expand Down
4 changes: 2 additions & 2 deletions src/libs/commom.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

#define NO_RECORDING
#define STATISTICS(x)
#define DEBUG(x)
#define LOG(x) x
#define DEBUG(x) x
#define LOG(x)


#define COMMOM_H
Expand Down
2 changes: 1 addition & 1 deletion src/libs/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "log.h"
#include "types.h"
#include "utils.h"
#define DEBUG(x)
#define DEBUG(x) x

static int first_time = 1;

Expand Down
39 changes: 37 additions & 2 deletions src/utils/medidas_geneticas.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ typedef struct files_list_
int num_files;
} files_list;

void destroy_files_list(files_list files_destroy)
{
for (int i = 0; i < files_destroy.num_files; i++)
{
free(files_destroy.files[i]);
}
free(files_destroy.files);
}

void destroy_matriz(double **matriz, int size)
{
for (int i = 0; i < size; i++)
{
free(matriz[i]);
}
free(matriz);
}

void print_string_vector(char **files, int num)
{
int i = 0;
Expand Down Expand Up @@ -136,18 +154,28 @@ files_list filter_file_list_by(files_list files_list_original, int epoca, int ge
strcpy(filtered_files.files[filtered_files.num_files++], current_file);
}

for (int i = filtered_files.num_files; i < files_list_original.num_files; i++)
{
free(filtered_files.files[i]);
}

return filtered_files;
}

int extract_min_generations_from_epoca(files_list files_list_original, int epoca)
{
int n_populations = filter_file_list_by(files_list_original, epoca, 0, -1).num_files;
files_list files_aux;
files_aux = filter_file_list_by(files_list_original, epoca, 0, -1);
int n_populations = files_aux.num_files;
destroy_files_list(files_aux);
int min = (int)INFINITY;
int current_value;

for (int i = 0; i < n_populations; i++)
{
current_value = filter_file_list_by(files_list_original, epoca, -1, i).num_files;
files_aux = filter_file_list_by(files_list_original, epoca, -1, i);
current_value = files_aux.num_files;
destroy_files_list(files_aux);
if (current_value < min)
min = current_value;
}
Expand Down Expand Up @@ -297,6 +325,7 @@ double *densityPopulation(populacao **populations, int island_number)
result[1] = sd;
// DEBUG(printf("\nDensityPopulation\n"););
// DEBUG(printf("%lf;%lf;\n", average, sd););
free(sum);
return result;
}

Expand Down Expand Up @@ -374,6 +403,7 @@ double densityWorld(populacao **populations, int island_number)
// de uma execução com outra. Então, é somar tudo e retornar
// verificar se esta ideia acima está correta
*/
destroy_matriz(sum, island_number);
return total;
}

Expand Down Expand Up @@ -461,9 +491,14 @@ void write_metrics_for_each_files()
fprintf(output_metric, "%lf ", densityPopulationResult[0]);
fprintf(output_metric, "%lf ", densityPopulationResult[1]);
fprintf(output_metric, "%lf\n", densityWorldResult);
destroy_island(*populations, filtered_files.num_files - 1);
destroy_files_list(filtered_files);
free(densityPopulationResult);
free(populations);
}
fclose(output_metric);
}
destroy_files_list(all_files);
}

int main()
Expand Down