-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.c
More file actions
48 lines (37 loc) · 980 Bytes
/
Copy pathinitialize.c
File metadata and controls
48 lines (37 loc) · 980 Bytes
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
/* Data initializtion routines */
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include "global.h"
# include "rand.h"
/* Function to initialize a population randomly */
void initialize_pop (population *pop, problem_instance *pi)
{
int i;
for (i=0; i<popsize; i++)
{
initialize_ind (&(pop->ind[i]), pi);
}
return;
}
/* Function to initialize an individual randomly */
void initialize_ind (individual *ind, problem_instance *pi)
{
/*Creamos una permutación aleatorea*/
int i;
for(i=0; i < pi->nObj; i++){
ind->rep[i] = i;
}
/*Ahora le hacemos un swap con uno random*/
for(i = 0; i < pi->nObj; i++){
/*Elegimos uno random*/
int j = rnd(0, pi->nObj-1);
/*Realizamos el swap*/
int temp = ind->rep[i];
ind->rep[i] = ind->rep[j];
ind->rep[j] = temp;
}
/*Le asignamos el constr_violation = 0*/
ind->constr_violation = 0;
return;
}