-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
70 lines (57 loc) · 1.73 KB
/
main.js
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
// // Genetic Algorithm
// // Number of Populatoin
// const n = 20
// // Number of Genetic Parents
// const p = 2
// const target = 'unicorn'
// var population = ['unijorm', 'pancake', 'aaaaaah', 'popcorn']
// var fitness = [0, 0, 0, 0]
// var real_fitness = [0, 0, 0, 0]
// function getFitness(word, target){
// var fitness = 0;
// for(char in word){
// if(word[char] == target[char]){
// fitness += 1;
// }
// }
// return fitness;
// }
// function getPopFitness(){
// for(index in population){
// fitness[index] = getFitness(population[index], target)
// real_fitness[index] = getFitness(population[index], target)
// }
// }
// function pickParents(){
// var parents = []
// for(iteration = 0; iteration < p; iteration++){
// var max = fitness[0]
// for(index = 1; index < fitness.length; index++){
// if(fitness[index] == 0){
// fitness[index] = fitness[index-1]
// }
// else{
// max += real_fitness[index]
// fitness[index] = real_fitness[index] + fitness[index-1]
// }
// }
// for(index = 0; index < fitness.length; index++){
// if(real_fitness[index] == 0){
// fitness[index] = - 1
// }
// }
// var random = Math.ceil(Math.random()*max)
// for(index = 0; index < fitness.length; index++){
// if(random <= fitness[index]){
// parents.push(index)
// fitness[index] = 0
// break
// }
// }
// }
// console.log(parents)
// }
// function crossOver(){
// }
// getPopFitness()
// pickParents()