-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutation.c
More file actions
56 lines (40 loc) · 1.05 KB
/
Copy pathmutation.c
File metadata and controls
56 lines (40 loc) · 1.05 KB
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
/* Mutation routines */
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include "global.h"
# include "rand.h"
/* Function to perform mutation in a population */
void mutation_pop (population *pop, problem_instance *pi)
{
int i;
for (i=0; i<popsize; i++)
{
mutation_ind(&(pop->ind[i]), pi);
}
return;
}
/*Función para mutar una permutación (swap simple)*/
void random_swap(individual *ind, problem_instance *pi){
/*Obtenemos un número entre 0 y 1 para ver si mutarlo*/
double rand_val = randomperc();
if(rand_val < pmut){
nmut++;
int i = rnd(0, pi->nObj-1);
int j = rnd(0, pi->nObj-1);
while(i == j){
j = rnd(0, pi->nObj-1);
}
int k;
/*Intercambiamos la permutacion*/
int temp = ind->rep[i];
ind->rep[i] = ind->rep[j];
ind->rep[j] = temp;
}
}
/* Function to perform mutation of an individual */
void mutation_ind (individual *ind, problem_instance *pi)
{
random_swap(ind, pi);
return;
}