-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.js
63 lines (60 loc) · 2.58 KB
/
demo.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
// GENETIC EXPERIENCE MANAGEMENT
// by Paul Prae
// First created December 5th
var Individual = require('./Individual');
var Population = require('./Population');
console.log('\n' + '============================================================================');
console.log('~ Evolution of Color Traits: Desired Traits are \'purple\' and \'turquoise\' ~');
console.log('============================================================================');
console.log('\n\nFirst generation:');
console.log('--------------------------');
var population = new Population();
population.prettyPrintGeneration();
console.log('\nA most fit individual:');
console.log('------------------------------------');
fittest = population.findAMostFitIndividual();
fittest.prettyPrint();
console.log('\nA least fit individual:');
console.log('------------------------------------');
fittest = population.findALeastFitIndividual();
fittest.prettyPrint();
console.log('\nAverage fitness:');
console.log('--------------------');
console.log(population.averageFitness());
console.log('\n\nAfter evolving the current generation 5 times (selection, crossover, mutation):');
console.log('--------------------------------------------------------------------------------');
for(var i = 0; i < 5; i++){
population.evolve();
}
population.prettyPrintGeneration();
console.log('\nA most fit individual:');
console.log('------------------------------------');
fittest = population.findAMostFitIndividual();
fittest.prettyPrint();
console.log('\nA least fit individual:');
console.log('------------------------------------');
fittest = population.findALeastFitIndividual();
fittest.prettyPrint();
console.log('\nAverage fitness:');
console.log('--------------------');
console.log(population.averageFitness());
console.log('\n\nAfter evolving the current generation 50 more times (selection, crossover, mutation):');
console.log('--------------------------------------------------------------------------------');
for(var i = 0; i < 50; i++){
population.evolve();
}
population.prettyPrintGeneration();
console.log('\nA most fit individual:');
console.log('------------------------------------');
fittest = population.findAMostFitIndividual();
fittest.prettyPrint();
console.log('\nA least fit individual:');
console.log('------------------------------------');
fittest = population.findALeastFitIndividual();
fittest.prettyPrint();
console.log('\nAverage fitness:');
console.log('--------------------');
console.log(population.averageFitness());
console.log();
console.log('===================================================================================');
console.log();