genetic_algorithms 0.0.3 → 0.0.4
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 +7 -0
- data/.gitignore +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +21 -19
- data/README.md +6 -2
- data/genetic_algorithms.gemspec +3 -3
- data/lib/genetic_algorithms/roulette_wheel.rb +3 -2
- data/lib/genetic_algorithms/version.rb +1 -1
- data/spec/spec_helper.rb +5 -0
- metadata +23 -30
- data/.rvmrc +0 -48
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3cdba165112209c915a3bf890c3eeff94b662d3
|
4
|
+
data.tar.gz: a69f8d541663a499fae44fd2deaace58787e54c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71cfe4594501f7aa3f50aed4a197822ced2ff29b600a69ce3867c9bc88977718e000d73ad14bc0b86d263d01a6def4f270714bafa2516349682965217bfa646d
|
7
|
+
data.tar.gz: 20eebd164d5a001ab26ec8767b974f1cfc06d496ecbaaacb77b78dd2301eb2f06a6316f1cf9e4fafecc944ad70a6de6463526dc496e2d9c1a4a3272be5ac5eb0
|
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
genetic_algorithms
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.0
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,30 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
genetic_algorithms (0.0.
|
5
|
-
logging
|
4
|
+
genetic_algorithms (0.0.4)
|
5
|
+
logging
|
6
6
|
|
7
7
|
GEM
|
8
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
diff-lcs (1.
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
docile (1.1.3)
|
11
12
|
little-plugger (1.1.3)
|
12
|
-
logging (1.8.
|
13
|
+
logging (1.8.2)
|
13
14
|
little-plugger (>= 1.1.3)
|
14
|
-
multi_json (>= 1.
|
15
|
-
multi_json (1.
|
16
|
-
rspec (2.
|
17
|
-
rspec-core (~> 2.
|
18
|
-
rspec-expectations (~> 2.
|
19
|
-
rspec-mocks (~> 2.
|
20
|
-
rspec-core (2.
|
21
|
-
rspec-expectations (2.
|
22
|
-
diff-lcs (
|
23
|
-
rspec-mocks (2.
|
24
|
-
simplecov (0.
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
multi_json (>= 1.8.4)
|
16
|
+
multi_json (1.8.4)
|
17
|
+
rspec (2.14.1)
|
18
|
+
rspec-core (~> 2.14.0)
|
19
|
+
rspec-expectations (~> 2.14.0)
|
20
|
+
rspec-mocks (~> 2.14.0)
|
21
|
+
rspec-core (2.14.7)
|
22
|
+
rspec-expectations (2.14.5)
|
23
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
24
|
+
rspec-mocks (2.14.6)
|
25
|
+
simplecov (0.8.2)
|
26
|
+
docile (~> 1.1.0)
|
27
|
+
multi_json
|
28
|
+
simplecov-html (~> 0.8.0)
|
29
|
+
simplecov-html (0.8.0)
|
28
30
|
|
29
31
|
PLATFORMS
|
30
32
|
ruby
|
data/README.md
CHANGED
@@ -85,12 +85,16 @@ include GeneticAlgorithms
|
|
85
85
|
|
86
86
|
Engine.new(10,4).start(Knapsack::BEST_SCORE) do |chromosome|
|
87
87
|
score = Knapsack.new(chromosome).utilization
|
88
|
-
|
88
|
+
|
89
|
+
if score > Knapsack::BEST_SCORE
|
90
|
+
score = Knapsack::BEST_SCORE - (score - Knapsack::BEST_SCORE)
|
91
|
+
end
|
92
|
+
|
89
93
|
score
|
90
94
|
end
|
91
95
|
```
|
92
96
|
|
93
|
-
Take note of the line checking whether the score is greater than the best score. It is necessary because we don't want genetic_algorithms to think that the over-utilized knapsacks are better solutions. A knapsack with too much stuff in it would otherwise have a higher score.
|
97
|
+
Take note of the line checking whether the score is greater than the best score. It is necessary because we don't want genetic_algorithms to think that the over-utilized knapsacks are better solutions. A knapsack with too much stuff in it would otherwise have a higher score. I will be adding a feature so that the user can specify that lower return values from a fitness function are better than higher ones. The fitness function above will be cleaner once that is done.
|
94
98
|
|
95
99
|
The result of this run will be something like:
|
96
100
|
|
data/genetic_algorithms.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
15
15
|
s.require_paths = ["lib"]
|
16
16
|
|
17
|
-
s.add_dependency("logging", "~> 1.8
|
18
|
-
s.add_development_dependency("rspec")
|
19
|
-
s.add_development_dependency("simplecov")
|
17
|
+
s.add_dependency("logging", "~> 1.8")
|
18
|
+
s.add_development_dependency("rspec", "~> 2.14")
|
19
|
+
s.add_development_dependency("simplecov", "~> 0.8")
|
20
20
|
end
|
@@ -14,11 +14,12 @@ module GeneticAlgorithms
|
|
14
14
|
@normalized = normalized.sort_by { |chromosome, probability| probability }
|
15
15
|
end
|
16
16
|
|
17
|
+
# TODO: use inject here instead of each_pair
|
17
18
|
def spin
|
18
|
-
accumulator,
|
19
|
+
accumulator, prn = 0, rand
|
19
20
|
|
20
21
|
@normalized.each_pair do |chromosome, probability|
|
21
|
-
if
|
22
|
+
if prn <= probability + accumulator
|
22
23
|
@logger.debug "Choosing #{chromosome} with probability #{probability}"
|
23
24
|
return chromosome
|
24
25
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,73 +1,67 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genetic_algorithms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alexander Vanadio
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: logging
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.8
|
19
|
+
version: '1.8'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.8
|
26
|
+
version: '1.8'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '2.14'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '2.14'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: simplecov
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
47
|
+
version: '0.8'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
54
|
+
version: '0.8'
|
62
55
|
description: This gem allows you to evolve chromosomes in order to solve problems
|
63
56
|
email: execdd17@gmail.com
|
64
57
|
executables: []
|
65
58
|
extensions: []
|
66
59
|
extra_rdoc_files: []
|
67
60
|
files:
|
68
|
-
- .gitignore
|
69
|
-
- .
|
70
|
-
- .
|
61
|
+
- ".gitignore"
|
62
|
+
- ".ruby-gemset"
|
63
|
+
- ".ruby-version"
|
64
|
+
- ".travis.yml"
|
71
65
|
- Gemfile
|
72
66
|
- Gemfile.lock
|
73
67
|
- README.md
|
@@ -88,27 +82,26 @@ files:
|
|
88
82
|
- spec/spec_helper.rb
|
89
83
|
homepage: https://github.com/execdd17/genetic_algorithms
|
90
84
|
licenses: []
|
85
|
+
metadata: {}
|
91
86
|
post_install_message:
|
92
87
|
rdoc_options: []
|
93
88
|
require_paths:
|
94
89
|
- lib
|
95
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
91
|
requirements:
|
98
|
-
- -
|
92
|
+
- - ">="
|
99
93
|
- !ruby/object:Gem::Version
|
100
94
|
version: '0'
|
101
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
96
|
requirements:
|
104
|
-
- -
|
97
|
+
- - ">="
|
105
98
|
- !ruby/object:Gem::Version
|
106
99
|
version: '0'
|
107
100
|
requirements: []
|
108
101
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
102
|
+
rubygems_version: 2.2.2
|
110
103
|
signing_key:
|
111
|
-
specification_version:
|
104
|
+
specification_version: 4
|
112
105
|
summary: A simple API for using genetic algorithms in Ruby
|
113
106
|
test_files:
|
114
107
|
- spec/chromosome_spec.rb
|
data/.rvmrc
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
-
# development environment upon cd'ing into the directory
|
5
|
-
|
6
|
-
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
-
# Only full ruby name is supported here, for short names use:
|
8
|
-
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
-
environment_id="ruby-1.9.3@genetic_algorithms"
|
10
|
-
|
11
|
-
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
-
# rvmrc_rvm_version="1.16.6 (stable)" # 1.10.1 seams as a safe start
|
13
|
-
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
-
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
-
# return 1
|
16
|
-
# }
|
17
|
-
|
18
|
-
# First we attempt to load the desired environment directly from the environment
|
19
|
-
# file. This is very fast and efficient compared to running through the entire
|
20
|
-
# CLI and selector. If you want feedback on which environment was used then
|
21
|
-
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
-
then
|
25
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
-
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
-
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
-
else
|
29
|
-
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
-
rvm --create "$environment_id" || {
|
31
|
-
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
-
return 1
|
33
|
-
}
|
34
|
-
fi
|
35
|
-
|
36
|
-
# If you use bundler, this might be useful to you:
|
37
|
-
# if [[ -s Gemfile ]] && {
|
38
|
-
# ! builtin command -v bundle >/dev/null ||
|
39
|
-
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
-
# }
|
41
|
-
# then
|
42
|
-
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
-
# gem install bundler
|
44
|
-
# fi
|
45
|
-
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
-
# then
|
47
|
-
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
-
# fi
|