Class: FeldtRuby::Optimize::EliteArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/feldtruby/optimize/elite_archive.rb

Overview

This keeps a record of the best/elite candidate solutions found during an optimization search. It keeps separate top lists per goal being optimized as well as for the aggregate quality value (fitness) itself. The top lists are all sorted to allow for fast checks and insertion.

Defined Under Namespace

Classes: GlobalTopList, GoalTopList

Constant Summary collapse

DefaultParams =
{
  :NumTopPerGoal => 10,
  :NumTopAggregate => 25
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objective, options = DefaultParams.clone) ⇒ EliteArchive

Returns a new instance of EliteArchive.



17
18
19
20
21
# File 'lib/feldtruby/optimize/elite_archive.rb', line 17

def initialize(objective, options = DefaultParams.clone)
  @objective = objective
  @options = options
  init_top_lists
end

Instance Attribute Details

#bestObject (readonly)

Returns the value of attribute best.



15
16
17
# File 'lib/feldtruby/optimize/elite_archive.rb', line 15

def best
  @best
end

#objectiveObject (readonly)

Returns the value of attribute objective.



15
16
17
# File 'lib/feldtruby/optimize/elite_archive.rb', line 15

def objective
  @objective
end

#top_per_goalObject (readonly)

Returns the value of attribute top_per_goal.



15
16
17
# File 'lib/feldtruby/optimize/elite_archive.rb', line 15

def top_per_goal
  @top_per_goal
end

Instance Method Details

#add(candidate) ⇒ Object



85
86
87
88
# File 'lib/feldtruby/optimize/elite_archive.rb', line 85

def add(candidate)
  @best.add candidate
  @top_per_goal.each {|tl| tl.add(candidate)}
end

#init_top_listsObject



77
78
79
80
81
82
83
# File 'lib/feldtruby/optimize/elite_archive.rb', line 77

def init_top_lists
  @top_per_goal = Array.new
  @objective.num_goals.times do |i|
    @top_per_goal << GoalTopList.new(@options[:NumTopPerGoal], @objective, i)
  end
  @best = GlobalTopList.new(@options[:NumTopAggregate], @objective)
end