-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathallocate.c
131 lines (122 loc) · 3.39 KB
/
allocate.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* Memory allocation and deallocation routines */
/* The Copyright belongs to Luis Felipe Ariza Vesga ([email protected]). You are free to use this algorithm (https://github.com/lfarizav/NSGA-III) for research purposes. All publications which use this code should acknowledge the author. Luis Felipe Ariza Vesga.
A Fast Nondominated Sorting Genetic Algorithm Extension to Solve Many-Objective Problems. March, 2019. */
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include "global.h"
# include "rand.h"
/* Function to allocate memory to a population */
void allocate_memory_pop (population *pop, int size)
{
int i;
pop->ind = (individual *)malloc(size*sizeof(individual));
for (i=0; i<size; i++)
{
allocate_memory_ind (&(pop->ind[i]));
}
return;
}
/* Function to allocate memory to an individual */
void allocate_memory_ind (individual *ind)
{
int j;
if (nreal != 0)
{
ind->xreal = (double *)malloc(nreal*sizeof(double));
}
if (nbin != 0)
{
ind->xbin = (double *)malloc(nbin*sizeof(double));
ind->gene = (int **)malloc(nbin*sizeof(int *));
for (j=0; j<nbin; j++)
{
ind->gene[j] = (int *)malloc(nbits[j]*sizeof(int));
}
}
ind->obj = (double *)malloc(nobj*sizeof(double));
ind->obj_minus_zmin = (double *)malloc(nobj*sizeof(double));
ind->obj_normalized = (double *)malloc(nobj*sizeof(double));
ind->obj_feasible = (double *)malloc(sizeof(double));
ind->obj_infeasible = (double *)malloc(sizeof(double));
if (ncon != 0)
{
ind->constr = (double *)malloc(ncon*sizeof(double));
}
if (neqcon != 0)
{
ind->equality_constr = (double *)malloc(neqcon*sizeof(double));
}
return;
}
/* Function to deallocate memory to a population */
void deallocate_memory_pop (population *pop, int size)
{
int i;
for (i=0; i<size; i++)
{
deallocate_memory_ind (&(pop->ind[i]));
}
free (pop->ind);
return;
}
/* Function to deallocate memory to an individual */
void deallocate_memory_ind (individual *ind)
{
int j;
if (nreal != 0)
{
free(ind->xreal);
}
if (nbin != 0)
{
for (j=0; j<nbin; j++)
{
free(ind->gene[j]);
}
free(ind->xbin);
free(ind->gene);
}
if (ncon != 0)
{
free(ind->constr);
}
if (neqcon != 0)
{
free(ind->equality_constr);
}
return;
}
/* Function to allocate memory to a population of refpoints*/
void allocate_memory_pop_refpoints (population_refpoints *pop_refpoints, int size)
{
int i;
pop_refpoints->ind = (individual_refpoints *)malloc(size*sizeof(individual_refpoints));
for (i=0; i<size; i++)
{
allocate_memory_ind_refpoints (&(pop_refpoints->ind[i]));
}
return;
}
/* Function to allocate memory to an individual of refpoints*/
void allocate_memory_ind_refpoints (individual_refpoints *ind)
{
return;
}
/* Function to deallocate memory to a population of refpoints */
void deallocate_memory_pop_refpoints (population *pop_refpoints, int size)
{
int i;
for (i=0; i<size; i++)
{
deallocate_memory_ind_refpoints (&(pop_refpoints->ind[i]));
}
free (pop_refpoints->ind);
return;
}
/* Function to deallocate memory to an individual of refpoints */
void deallocate_memory_ind_refpoints (individual_refpoints *ind)
{
int j;
return;
}