Class: JGAP::Salesman
- Inherits:
-
Object
- Object
- JGAP::Salesman
- Defined in:
- lib/JGAP/salesman.rb
Instance Attribute Summary collapse
-
#best_solution ⇒ Object
readonly
Returns the value of attribute best_solution.
Class Method Summary collapse
Instance Method Summary collapse
- #distance(from, to) ⇒ Object
- #get_name(num) ⇒ Object
-
#initialize ⇒ Salesman
constructor
A new instance of Salesman.
- #print_best ⇒ Object
- #read(subject, name) ⇒ Object
- #read_best(name) ⇒ Object
- #run ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize ⇒ Salesman
Returns a new instance of Salesman.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/JGAP/salesman.rb', line 35 def initialize super @config = create_configuration(nil) @chromosome = nil @population_size = 512 @builder = ChromosomeBuilder.new(@config) @best_solution = nil chromosome population_size end |
Instance Attribute Details
#best_solution ⇒ Object (readonly)
Returns the value of attribute best_solution.
33 34 35 |
# File 'lib/JGAP/salesman.rb', line 33 def best_solution @best_solution end |
Class Method Details
.chromosome(&block) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/JGAP/salesman.rb', line 91 def self.chromosome(&block) define_method(:chromosome) do @builder.instance_eval(&block) @chromosome = @builder.chromosome end define_method(:createSampleChromosome) do |init_data| @chromosome end end |
.population_size(size) ⇒ Object
MACROS
83 84 85 86 87 88 89 |
# File 'lib/JGAP/salesman.rb', line 83 def self.population_size(size) define_method(:population_size) do @population_size = size set_population_size(@population_size) @config.set_population_size(@population_size) end end |
Instance Method Details
#distance(from, to) ⇒ Object
46 47 48 |
# File 'lib/JGAP/salesman.rb', line 46 def distance(from, to) distance_function(from.allele, to.allele) end |
#get_name(num) ⇒ Object
50 51 52 |
# File 'lib/JGAP/salesman.rb', line 50 def get_name(num) @builder.get_name(num) end |
#print_best ⇒ Object
75 76 77 78 79 |
# File 'lib/JGAP/salesman.rb', line 75 def print_best @builder.names.each do |k, v| puts "#{k}: #{read_best k}" end end |
#read(subject, name) ⇒ Object
67 68 69 |
# File 'lib/JGAP/salesman.rb', line 67 def read(subject, name) @builder.read(subject, name) end |
#read_best(name) ⇒ Object
71 72 73 |
# File 'lib/JGAP/salesman.rb', line 71 def read_best(name) read(best_solution, name) end |
#run ⇒ Object
62 63 64 65 |
# File 'lib/JGAP/salesman.rb', line 62 def run Configuration.reset @best_solution = find_optimal_path(nil) end |
#setup ⇒ Object
54 55 56 |
# File 'lib/JGAP/salesman.rb', line 54 def setup # Override me! end |