@@ -27,7 +27,7 @@ type populationItem struct {
27
27
Value float64
28
28
}
29
29
30
- func genetic_string (target string , charmap []rune ) (int , int , string ) {
30
+ func geneticString (target string , charmap []rune ) (int , int , string ) {
31
31
// Define parameters
32
32
// Maximum size of the population. bigger could be faster but is more memory expensive
33
33
populationNum := 200
@@ -77,7 +77,7 @@ func genetic_string(target string, charmap []rune) (int, int, string) {
77
77
78
78
// This loop will end when we will find a perfect match for our target
79
79
for {
80
- gen += 1
80
+ gen ++
81
81
generatedPop += len (pop )
82
82
83
83
// Random population created now it's time to evaluate
@@ -112,11 +112,11 @@ func genetic_string(target string, charmap []rune) (int, int, string) {
112
112
for i := 0 ; i < int (selectionNum ); i ++ {
113
113
parent1 := pop [i ]
114
114
// Generate more child proportionally to the fitness score
115
- child_n := (parent1 .Value * 100 ) + 1
116
- if child_n >= 10 {
117
- child_n = 10
115
+ nChild := (parent1 .Value * 100 ) + 1
116
+ if nChild >= 10 {
117
+ nChild = 10
118
118
}
119
- for x := 0.0 ; x < child_n ; x ++ {
119
+ for x := 0.0 ; x < nChild ; x ++ {
120
120
parent2 := pop [rand .Intn (selectionNum )]
121
121
// Crossover
122
122
split := rand .Intn (utf8 .RuneCountInString (target ))
@@ -152,6 +152,6 @@ func main() {
152
152
// Define parameters
153
153
target := string ("This is a genetic algorithm to evaluate, combine, evolve and mutate a string!" )
154
154
charmap := []rune (" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,;!?+-*#@^'èéòà€ù=)(&%$£/\\ " )
155
- gen , generatedPop , best := genetic_string (target , charmap )
155
+ gen , generatedPop , best := geneticString (target , charmap )
156
156
fmt .Println ("Generation:" , strconv .Itoa (gen ), "Analyzed:" , generatedPop , "Best:" , best )
157
157
}
0 commit comments