Class: JGAP::Salesman

Inherits:
Object
  • Object
show all
Defined in:
lib/JGAP/salesman.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSalesman

Returns a new instance of Salesman.



18
19
20
21
22
23
24
25
26
27
# File 'lib/JGAP/salesman.rb', line 18

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_solutionObject (readonly)

Returns the value of attribute best_solution.



16
17
18
# File 'lib/JGAP/salesman.rb', line 16

def best_solution
  @best_solution
end

Class Method Details

.chromosome(&block) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/JGAP/salesman.rb', line 70

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

.fitness_function(&block) ⇒ Object



81
82
83
# File 'lib/JGAP/salesman.rb', line 81

def self.fitness_function(&block)
  define_method(:evaluate, &block)
end

.population_size(size) ⇒ Object

MACROS



63
64
65
66
67
68
# File 'lib/JGAP/salesman.rb', line 63

def self.population_size(size)
  define_method(:population_size) do
    @population_size = size
    @config.set_population_size(@population_size)
  end
end

Instance Method Details

#distance(from, to) ⇒ Object



57
58
59
# File 'lib/JGAP/salesman.rb', line 57

def distance(from, to)
  # Override me!
end


51
52
53
54
55
# File 'lib/JGAP/salesman.rb', line 51

def print_best
  @builder.names.each do |k, v|
    puts "#{k}: #{read_best k}"
  end
end

#read(subject, name) ⇒ Object



43
44
45
# File 'lib/JGAP/salesman.rb', line 43

def read(subject, name)
  @builder.read(subject, name)
end

#read_best(name) ⇒ Object



47
48
49
# File 'lib/JGAP/salesman.rb', line 47

def read_best(name)
  read(best_solution, name)
end

#runObject



38
39
40
41
# File 'lib/JGAP/salesman.rb', line 38

def run
  Configuration.reset
  @best_solution = find_optimal_path(nil)
end

#setupObject



30
31
32
# File 'lib/JGAP/salesman.rb', line 30

def setup
  # Override me!
end