-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathessAllocate.c
105 lines (74 loc) · 2.32 KB
/
essAllocate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "ess.h"
/**
* Allocate memory for an Individual
*/
void allocate_Ind(eSSType *eSSParams, Individual *ind){
ind->params = (double *)malloc(eSSParams->n_params * sizeof(double));
// ind->params_means = (double *)malloc(eSSParams->n_params * sizeof(double));
// ind->params_vars = (double *)malloc(eSSParams->n_params * sizeof(double));
ind->mean_cost = 0;
ind->var_cost = 0;
ind->cost = 0;
ind->dist = 0;
ind->n_not_randomized = 0;
ind->n_stuck = 0;
}
/**
* Deallocate memory for an Individual
*/
void deallocate_Ind(eSSType *eSSParams, Individual *ind){
free(ind->params);
// free(ind->means);
// free(ind->stds);
}
/**
* Allocate memory of a set
*/
void allocate_Set(eSSType *eSSParams, Set *set){
set->members = (Individual *)malloc(set->size * sizeof(Individual));
for (int i = 0; i < set->size; ++i)
allocate_Ind(eSSParams, &(set->members[i]));
set->params_means = (double *)malloc(eSSParams->n_params * sizeof(double));
}
/**
* Deallocate memory of a set
*/
void deallocate_Set(eSSType *eSSParams, Set *set){
for (int i = 0; i < set->size; ++i)
deallocate_Ind(eSSParams, &(set->members[i]));
free(set->members);
free(set->params_means);
}
void deallocate_eSSParams(eSSType *eSSParams){
deallocate_Set(eSSParams, eSSParams->refSet);
free(eSSParams->refSet);
deallocate_Set(eSSParams, eSSParams->scatterSet);
free(eSSParams->scatterSet);
deallocate_Set(eSSParams, eSSParams->childsSet);
free(eSSParams->childsSet);
deallocate_Set(eSSParams, eSSParams->candidateSet);
free(eSSParams->candidateSet);
eSSParams->archiveSet->size = 100;
deallocate_Set(eSSParams, eSSParams->archiveSet);
free(eSSParams->archiveSet);
deallocate_Set(eSSParams, eSSParams->localSearchCandidateSet);
free(eSSParams->localSearchCandidateSet);
free(eSSParams->min_real_var);
free(eSSParams->max_real_var);
/**
* Deallocating the stats struct
*/
for (int i = 0; i < eSSParams->n_params; ++i)
{
free(eSSParams->stats->freqs_matrix[i]);
free(eSSParams->stats->probs_matrix[i]);
// Deallocation min/max_boundary_matrices
free(eSSParams->min_boundary_matrix[i]);
free(eSSParams->max_boundary_matrix[i]);
}
free(eSSParams->min_boundary_matrix);
free(eSSParams->max_boundary_matrix);
free(eSSParams->stats->freqs_matrix);
free(eSSParams->stats->probs_matrix);
free(eSSParams->stats);
}