View
222
Download
0
Embed Size (px)
Citation preview
GA Applications
• Peaks function C- code GOAT package for MATLAB minimization and maximization• Traveling Salesman Problem genotype and phenotype encoding customizing operators rank scaling• Hillis Sorting Problem• Sequence Alignment• Floating point GAs• Constraint optimization• Multi-objective optimization• The schemata theorem
Components of binary GA in Feature Selection
Problem: max R2
110101111111000000
f1 = 0.60f2 = 0.30f3 = 0.10
0.60.3
0.1
110101110101000000
Crossover point
111111000000
111100000011Crossover
Selection
Population Fitness
Selected gene
111111 111110Mutation
SelectedPopulation
Mutated gene
R2 = Goodness of fit
• Uniform Crossover
5 24 131 534 603 Parent 1
19 33 255 334 508 Parent 2
19 33 131 534 603 Child 1
5 24 255 334 508 Child 2
5 24 131 534 603
5 24 344 534 603
• Mutation
Parent
Child
Genetic Operators
222222 15312
3
1
51013, yxyxyx eeyx
xexyxfx
222222 15312
3
1
51013, yxyxyx eeyx
xexyxfx
222222 15312
3
1
51013, yxyxyx eeyx
xexyxfx
Traveling Salesman Problem
33 34 35 36 37 38 39 40 41 42-10
-5
0
5
10
15
20
25
3052 CITY TSP BENCHMARK
X-coordinate
Y-c
oord
inat
e
tourlength =73.9876
1312
161
32
4
8
15
5
11
9
1076
14
33 34 35 36 37 38 39 40 41 42-10
-5
0
5
10
15
20
25
3052 CITY TSP BENCHMARK
X-coordinate
Y-c
oord
inat
e
tourlength =73.9998
8
4
2 3
16
131276 10
9
11
5
15 14
1
0 200 400 600 800 1000 1200 1400 1600 18000
200
400
600
800
1000
120052 CITY TSP BENCHMARK
X-coordinate
Y-c
oord
inat
e
tourlength =8386.4347
52
1112
51
33
43
1524483739363534
44
502023
3027
42
21
17
3
18
31 22149
32
109
841
1945
403856 4
25
46
16
29
47
26
28
27
13
14
0 200 400 600 800 1000 1200 1400 1600 18000
200
400
600
800
1000
120052 CITY TSP BENCHMARK
X-coordinate
Y-c
oord
inat
e
tourlength =8231.2415
4
43
109 33
51
11
52
14
13
47
2627
28
1225
4644
16
29
5020
3027
42
2123
31
1817
3
418
1945
32
22149363534
3940373848245156
0 200 400 600 800 1000 1200 1400 1600 18000
200
400
600
800
1000
120052 CITY TSP BENCHMARK
X-coordinate
Y-c
oord
inat
e
tourlength =7992.4585
3027
42
21
17
3
418
910
1945
3249363534
3940373848245156
4
43
33
51
11
52
14
13
47
2627
28
1225
4644
12218
31
232050 16
29
void main(int argc, char *argv[]) {char mombassa[80], root[80];data b;double alpha, beta; //user dataint num_cities;MATRIX distances;
Container box; //user data to objective function in boxdouble (* fptr) (data*, VECTOR); //function pointer to objective fnctngenotype pop;
fptr = Salesman3; MatrixAllocate(&distances, 500, 500); userData(&b, &box); // tells pointer of userdata in data struct for b Read_User_Data(&alpha, &beta, &num_cities, distances); box.pop = &pop; box.alpha = alpha; box.beta = beta; box.num_cities = num_cities; box.distances = distances; if (argc == 2) strcpy( mombassa, argv[1]); Allocate_GA(&pop, &b, argc, mombassa, root, fptr); b.print_flag=0; Loop_GA(&b, &pop, root, fptr); Write_User_Data(&b, &pop, root, fptr); De_Allocate_GA(&pop, &b, root, fptr); MatrixFree(distances, 500);}
double Salesman2(data *a, VECTOR x) {int i, isum=0;double tour= 0, pen1=0, pen2=0;double alpha, beta;int num_cities, one, two, help;
Container * box = (Container *)(a->ud); alpha = box->alpha; beta = box->beta; num_cities = box->num_cities; help = num_cities/2*(num_cities-1); if (num_cities%2 == 1) help = help+num_cities%2; for (i = 0; i < num_cities-1;i++) { one = (int) x[i]; two = (int) x[i+1]; tour = tour + box->distances[one][two]; } one = (int) x[num_cities-1]; two = (int) x[0]; tour = tour + box->distances[one][two]; for (i = 0; i < num_cities;i++) isum += (int) x[i]; if (isum!=help) pen1=alpha; getche(); box->penn1=pen1; box->penn2=pen2; return tour + pen1;}