Class: JGAP::ChromosomeBuilder
- Inherits:
-
Object
- Object
- JGAP::ChromosomeBuilder
- Defined in:
- lib/JGAP/problem.rb,
lib/JGAP/salesman.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
- #get_name(num) ⇒ Object
-
#initialize(config) ⇒ ChromosomeBuilder
constructor
A new instance of ChromosomeBuilder.
- #integer(name, opts = {}) ⇒ Object
- #read(subject, name) ⇒ Object
- #salesman(names) ⇒ 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
51 52 53 54 |
# File 'lib/JGAP/problem.rb', line 51 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
42 43 44 45 46 47 48 49 |
# File 'lib/JGAP/problem.rb', line 42 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 |
#get_name(num) ⇒ Object
26 27 28 |
# File 'lib/JGAP/salesman.rb', line 26 def get_name(num) @names.invert[num] end |
#integer(name, opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/JGAP/problem.rb', line 33 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(names) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/JGAP/salesman.rb', line 17 def salesman(names) names.each do |name| new_gene = IntegerGene.new(@config, 0, names.length) new_gene.set_allele java.lang.Integer.new(@genes.length) @names[name] = @genes.length @genes << new_gene end end |
#string(name, opts = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/JGAP/problem.rb', line 56 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 |