Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The letter 'z' was not a possible letter in mutation #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion C#/GAHelloWorld/Chromosome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Chromosome Mutate()
char[] mutatedGene = this.Gene.ToCharArray();

int randomIndex = rand.Next(0, this.Gene.Length);
int mutateChange = rand.Next(32, 122);
int mutateChange = rand.Next(32, 123);

mutatedGene[randomIndex] = (char)mutateChange;

Expand Down
4 changes: 2 additions & 2 deletions clojure/src/net/auxesia/chromosome.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
[c]
(let [old-gene (:gene c)
idx (rand-int (count old-gene))
new-gene (assoc old-gene idx (char (mod (+ (int (get old-gene idx)) (+ 32 (rand-int 90))) 122)))]
new-gene (assoc old-gene idx (char (mod (+ (int (get old-gene idx)) (+ 32 (rand-int 90))) 123)))]
(Chromosome. new-gene (fitness new-gene))))

(defn generate
Expand All @@ -69,4 +69,4 @@
(let [pivot (rand-int (count *target-gene*))
child1 (into (subvec (:gene c1) 0 pivot) (subvec (:gene c2) pivot))
child2 (into (subvec (:gene c2) 0 pivot) (subvec (:gene c1) pivot))]
(vector (generate child1) (generate child2))))
(vector (generate child1) (generate child2))))
2 changes: 1 addition & 1 deletion java/src/main/java/net/auxesia/Chromosome.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Chromosome mutate() {
char[] arr = gene.toCharArray();
int idx = rand.nextInt(arr.length);
int delta = (rand.nextInt() % 90) + 32;
arr[idx] = (char) ((arr[idx] + delta) % 122);
arr[idx] = (char) ((arr[idx] + delta) % 123);

return new Chromosome(String.valueOf(arr));
}
Expand Down
4 changes: 2 additions & 2 deletions python/gahelloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def mutate(self):
gene = list(self.gene)
delta = randint(32, 121)
idx = randint(0, len(gene) - 1)
gene[idx] = chr((ord(gene[idx]) + delta) % 122)
gene[idx] = chr((ord(gene[idx]) + delta) % 123)

return Chromosome(''.join(gene))

Expand Down Expand Up @@ -179,4 +179,4 @@ def evolve(self):
if pop.population[0].fitness == 0: break
else:pop.evolve()
else:
print("Maximum generations reached without success.")
print("Maximum generations reached without success.")
2 changes: 1 addition & 1 deletion ruby/lib/gahelloworld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
module GAHelloWorld
RAND_SEED=srand
TARGET_GENE='Hello World!'
ALLOWED_LETTERS = (32..122).to_a.map{|i| i.chr}
ALLOWED_LETTERS = (32..123).to_a.map{|i| i.chr}

class Chromosome
attr_reader :gene_ary, :target_ary, :gene
Expand Down
4 changes: 2 additions & 2 deletions scala/src/main/scala/net/auxesia/Chromosome.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object Chromosome {
*/
def mutate(ch: Chromosome) = {
var arr = ch.gene.toArray
arr(Random.nextInt(ch.gene.length)) = (Random.nextInt(90) + 32).toChar
arr(Random.nextInt(ch.gene.length)) = (Random.nextInt(91) + 32).toChar
Chromosome(arr.mkString)
}
}
}