gemetics 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gemetics.rb +15 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86fcaddbfc978710844aa2d936c5bd029d540d3a
4
- data.tar.gz: 725b5e5a24345f6a9bcaa71614592afdb121b17b
3
+ metadata.gz: 7d0533b871cdce9b34b0498968c49c632cfd8dfd
4
+ data.tar.gz: 1741baf1f07902310855bf0751e27127afc143a0
5
5
  SHA512:
6
- metadata.gz: 6b64516f052a9aed2126fc3ddd9e2179e1c03f3ea717d1d30a1fe5fe2fdfbffefb27c8cf3134a4de821a69f0ed521e14e42bd7c11b4f746bfb5d679a8b0726e8
7
- data.tar.gz: 41295cc8f858d002b00e2bf09bf5f0b2f4038374d0bdf2d2d2958b3994d6507824a81bf4a47582a31825dcaffadf85a8978b2d6c8af6f7a01c8b2977af02d889
6
+ metadata.gz: 2595caadc1a4595d5a8236c0f695f183975d6a8a665627bdab4dda1e9d6db8c9b6f5489ed7d857b4a756991aa7b913467949ff71816ab70f81f295ccba5688b6
7
+ data.tar.gz: dae4e162910456dce31d552af1ae05df3b454a391a5c37719f9b29a38cea48afd4ab8f829096a0ec381e12f914d0e286ab308d92b150bbb336bdd6d6e7808a95
@@ -37,12 +37,16 @@ def runAlgorithm(initialPopulation, eval, threshold, options)
37
37
  mates = selection(sortedPopulation.clone(), options[:selectionStyle])
38
38
 
39
39
  # mate and replace
40
- results = mates[0].mate(mates[1])
41
- replace = Array.new(2, Random.new.rand(population.size()))
42
- # don't replace same org
43
- replace[1] = Random.new.rand(population.size())while(replace[1] == replace[0])
44
- population[replace[0]] = results[0]
45
- population[replace[1]] = results[1]
40
+ reaplaced = []
41
+ for i in 0...results.size()
42
+ results[i].mutate() if Random.new.rand() < options[:mutation_percent]
43
+ temp = Random.new.rand(population.size())
44
+ while(!replaced.includes?(temp)) do
45
+ temp = Random.new.rand(population.size())
46
+ end
47
+ replaced.append(temp)
48
+ population[replaced[-1]] = results[i]
49
+ end
46
50
  else
47
51
  # Repalce every single organism
48
52
  needed = population.size()
@@ -53,11 +57,11 @@ def runAlgorithm(initialPopulation, eval, threshold, options)
53
57
 
54
58
  # mate and put them into new pop
55
59
  results = mates[0].mate(mates[1])
56
- results[0].mutate() if Random.new.rand() < options[:mutation_percent]
57
- results[1].mutate() if Random.new.rand() < options[:mutation_percent]
58
- newPopulation[have] = results[0]
59
- newPopulation[have+1] = results[1] if (have+1) < needed
60
- have += 2
60
+ for i in 0...results.size()
61
+ results[i].mutate() if Random.new.rand() < options[:mutation_percent]
62
+ newPopulation[have+i] = result[i] if (have+i) < needed
63
+ end
64
+ have += results.size()
61
65
  end
62
66
  population = newPopulation
63
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemetics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Huelsman