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.
- checksums.yaml +4 -4
- data/lib/gemetics.rb +15 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d0533b871cdce9b34b0498968c49c632cfd8dfd
|
4
|
+
data.tar.gz: 1741baf1f07902310855bf0751e27127afc143a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2595caadc1a4595d5a8236c0f695f183975d6a8a665627bdab4dda1e9d6db8c9b6f5489ed7d857b4a756991aa7b913467949ff71816ab70f81f295ccba5688b6
|
7
|
+
data.tar.gz: dae4e162910456dce31d552af1ae05df3b454a391a5c37719f9b29a38cea48afd4ab8f829096a0ec381e12f914d0e286ab308d92b150bbb336bdd6d6e7808a95
|
data/lib/gemetics.rb
CHANGED
@@ -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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|