Class: JGAP::ChromosomeBuilder
- Inherits:
-
Object
- Object
- JGAP::ChromosomeBuilder
- Defined in:
- lib/JGAP/problem.rb
Instance Attribute Summary collapse
-
#genes ⇒ Object
readonly
Returns the value of attribute genes.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Instance Method Summary collapse
- #boolean(name) ⇒ Object
- #chromosome ⇒ Object
- #decimal(name, opts = {}) ⇒ Object
-
#initialize(config) ⇒ ChromosomeBuilder
constructor
A new instance of ChromosomeBuilder.
- #integer(name, opts = {}) ⇒ Object
- #read(subject, name) ⇒ Object
- #salesman(name, cities) ⇒ Object
- #string(name, opts = {}) ⇒ Object
Constructor Details
#initialize(config) ⇒ ChromosomeBuilder
Returns a new instance of ChromosomeBuilder.
19 20 21 22 23 |
# File 'lib/JGAP/problem.rb', line 19 def initialize(config) @config = config @names = Hash.new @genes = Array.new end |
Instance Attribute Details
#genes ⇒ Object (readonly)
Returns the value of attribute genes.
17 18 19 |
# File 'lib/JGAP/problem.rb', line 17 def genes @genes end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
16 17 18 |
# File 'lib/JGAP/problem.rb', line 16 def names @names end |
Instance Method Details
#boolean(name) ⇒ Object
58 59 60 61 |
# File 'lib/JGAP/problem.rb', line 58 def boolean(name) @names[name] = @genes.length @genes << BooleanGene.new(@config) end |
#chromosome ⇒ Object
25 26 27 |
# File 'lib/JGAP/problem.rb', line 25 def chromosome Chromosome.new(@config, @genes.to_java(Java::OrgJgap::Gene)) end |
#decimal(name, opts = {}) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/JGAP/problem.rb', line 49 def decimal(name, opts={}) @names[name] = @genes.length unless opts.empty? @genes << DoubleGene.new(@config, opts[:min], opts[:max]) else @genes << DoubleGene.new(@config) end end |
#integer(name, opts = {}) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/JGAP/problem.rb', line 40 def integer(name, opts={}) @names[name] = @genes.length unless opts.empty? @genes << IntegerGene.new(@config, opts[:min], opts[:max]) else @genes << IntegerGene.new(@config) end end |
#read(subject, name) ⇒ Object
29 30 31 |
# File 'lib/JGAP/problem.rb', line 29 def read(subject, name) subject.gene(@names[name]).allele end |
#salesman(name, cities) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/JGAP/problem.rb', line 33 def salesman(name, cities) new_gene = IntegerGene.new(@config, 0, cities - 1) new_gene.set_allele java.lang.Integer.new(@genes.length) @names[name] = @genes.length @genes << new_gene end |
#string(name, opts = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/JGAP/problem.rb', line 63 def string(name, opts={}) @names[name] = @genes.length if !opts.empty? && opts[:alphabet] @genes << StringGene.new(@config, opts[:min], opts[:max], opts[:alphabet]) elsif opts @genes << StringGene.new(@config, opts[:min], opts[:max]) else @genes << StringGene.new(@config) end end |