Class: EvoSynth::Problems::GraphColouring

Inherits:
Evaluator
  • Object
show all
Defined in:
lib/evosynth/problems/graph_colouring.rb

Instance Attribute Summary collapse

Attributes inherited from Evaluator

#calculated, #called

Instance Method Summary collapse

Methods inherited from Evaluator

#calculate_and_set_fitness, #calculate_and_set_initial_fitness, #calculate_initial_fitness, #reset_counters, #to_s

Constructor Details

#initialize(filename) ⇒ GraphColouring

Returns a new instance of GraphColouring.



36
37
38
39
# File 'lib/evosynth/problems/graph_colouring.rb', line 36

def initialize(filename)
  super()
  read_file(filename)
end

Instance Attribute Details

#matrixObject (readonly)

Returns the value of attribute matrix.



34
35
36
# File 'lib/evosynth/problems/graph_colouring.rb', line 34

def matrix
  @matrix
end

#node_countObject (readonly)

Returns the value of attribute node_count.



33
34
35
# File 'lib/evosynth/problems/graph_colouring.rb', line 33

def node_count
  @node_count
end

Instance Method Details

#calculate_fitness(individual) ⇒ Object



53
54
55
56
# File 'lib/evosynth/problems/graph_colouring.rb', line 53

def calculate_fitness(individual)
  fitness = 0.0 + individual.genome.uniq.size * (verletzungen(individual.genome) + 1)
  fitness
end

#verletzungen(genome) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/evosynth/problems/graph_colouring.rb', line 41

def verletzungen(genome)
  verletzungen = 0

  @node_count.times do |row|
    @node_count.times do |col|
      verletzungen += 1 if @matrix[row, col] == 1 && genome[row] == genome[col]
    end
  end

  verletzungen
end