Class: EvoSynth::Problems::GraphColouring
- Defined in:
- lib/evosynth/problems/graph_colouring.rb
Instance Attribute Summary collapse
-
#matrix ⇒ Object
readonly
Returns the value of attribute matrix.
-
#node_count ⇒ Object
readonly
Returns the value of attribute node_count.
Attributes inherited from Evaluator
Instance Method Summary collapse
- #calculate_fitness(individual) ⇒ Object
-
#initialize(filename) ⇒ GraphColouring
constructor
A new instance of GraphColouring.
- #verletzungen(genome) ⇒ Object
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
#matrix ⇒ Object (readonly)
Returns the value of attribute matrix.
34 35 36 |
# File 'lib/evosynth/problems/graph_colouring.rb', line 34 def matrix @matrix end |
#node_count ⇒ Object (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 |