Skip to content

Commit 6d09e83

Browse files
committed
Fix golint
1 parent af323c9 commit 6d09e83

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

genetic-algorithm/genetic_algo.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type populationItem struct {
2727
Value float64
2828
}
2929

30-
func genetic_string(target string, charmap []rune) (int, int, string) {
30+
func geneticString(target string, charmap []rune) (int, int, string) {
3131
// Define parameters
3232
// Maximum size of the population. bigger could be faster but is more memory expensive
3333
populationNum := 200
@@ -77,7 +77,7 @@ func genetic_string(target string, charmap []rune) (int, int, string) {
7777

7878
// This loop will end when we will find a perfect match for our target
7979
for {
80-
gen += 1
80+
gen++
8181
generatedPop += len(pop)
8282

8383
// Random population created now it's time to evaluate
@@ -112,11 +112,11 @@ func genetic_string(target string, charmap []rune) (int, int, string) {
112112
for i := 0; i < int(selectionNum); i++ {
113113
parent1 := pop[i]
114114
// 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
118118
}
119-
for x := 0.0; x < child_n; x++ {
119+
for x := 0.0; x < nChild; x++ {
120120
parent2 := pop[rand.Intn(selectionNum)]
121121
// Crossover
122122
split := rand.Intn(utf8.RuneCountInString(target))
@@ -152,6 +152,6 @@ func main() {
152152
// Define parameters
153153
target := string("This is a genetic algorithm to evaluate, combine, evolve and mutate a string!")
154154
charmap := []rune(" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,;!?+-*#@^'èéòà€ù=)(&%$£/\\")
155-
gen, generatedPop, best := genetic_string(target, charmap)
155+
gen, generatedPop, best := geneticString(target, charmap)
156156
fmt.Println("Generation:", strconv.Itoa(gen), "Analyzed:", generatedPop, "Best:", best)
157157
}

0 commit comments

Comments
 (0)