feldtruby 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -175,7 +175,7 @@ end
175
175
  module Logging
176
176
  attr_accessor :logger
177
177
 
178
- def setup_logger_and_distribute_to_instance_variables(loggerOrOptions = nil)
178
+ def setup_logger_and_distribute_to_instance_variables(loggerOrOptions = nil, visited = [])
179
179
 
180
180
  if Hash === loggerOrOptions
181
181
  options = loggerOrOptions
@@ -194,12 +194,19 @@ module Logging
194
194
  new_default_logger(options)
195
195
 
196
196
  # Now distribute the preferred logger to all instance vars, recursively.
197
+ # Save all visited ones to a list though and check that we do not get into
198
+ # infinite regress if two objects refer to each other.
197
199
  self.instance_variables.each do |ivar_name|
198
200
 
199
201
  ivar = self.instance_variable_get ivar_name
200
202
 
201
- if ivar.respond_to?(:setup_logger_and_distribute_to_instance_variables)
202
- ivar.setup_logger_and_distribute_to_instance_variables self.logger
203
+ unless visited.include?(ivar)
204
+
205
+ visited << ivar
206
+
207
+ if ivar.respond_to?(:setup_logger_and_distribute_to_instance_variables)
208
+ ivar.setup_logger_and_distribute_to_instance_variables self.logger, visited
209
+ end
203
210
  end
204
211
 
205
212
  end
@@ -39,7 +39,7 @@ module FeldtRuby::Optimize
39
39
  # specialists (doing one thing very, very good, sub-objective fitness best)
40
40
  # weirdos (different but with clear qualitites, ok but diverse)
41
41
  class Archive
42
- #include FeldtRuby::Logging
42
+ include FeldtRuby::Logging
43
43
 
44
44
  DefaultParams = {
45
45
  :NumTopPerGoal => 5, # Number of solutions in top list per individual goal
@@ -68,6 +68,7 @@ class Archive
68
68
  self.diversity_objective = diversityObjective
69
69
  @params = DefaultParams.clone.update(params)
70
70
  init_top_lists
71
+ setup_logger_and_distribute_to_instance_variables(@params)
71
72
  end
72
73
 
73
74
  def diversity_objective=(diversityObjective)
@@ -105,12 +106,12 @@ class Archive
105
106
  # they are relative and must be recalculated. Note that this might incur
106
107
  # a big penalty if there are frequent changes at the top.
107
108
  if prev_best != best
108
- # logger.log_data :new_best, {
109
- # "New best" => best,
110
- # "New quality" => @objective.quality_of(best),
111
- # "Old best" => prev_best,
112
- # "Old quality" => @objective.quality_of(prev_best)},
113
- # "Archive: New best solution found", true
109
+ prev_qv = prev_best.nil? ? "" : @objective.quality_of(prev_best)
110
+ logger.log_data :new_best, {
111
+ "New best" => best,
112
+ "New quality" => @objective.quality_of(best),
113
+ "Old best" => prev_best,
114
+ "Old quality" => prev_qv}, "Archive: New best solution found", true
114
115
 
115
116
  @weirdos.each {|w| @diversity_objective.invalidate_quality_of(w)}
116
117
  elsif good_enough_quality_to_be_interesting?(candidate)
@@ -147,13 +148,11 @@ class Archive
147
148
 
148
149
  def add(candidate)
149
150
  last = @top_list.last
150
- #puts "In #{self},\nlast = #{last}, candidate = #{candidate}, top_list = #{@top_list}"
151
151
  if @top_list.length < @max_size || last.nil? || is_better_than?(candidate, last)
152
152
  @top_list.pop if @top_list.length >= @max_size
153
153
  @top_list << candidate
154
154
  @top_list = sort_top_list
155
155
  end
156
- #puts "top_list = #{@top_list}"
157
156
  end
158
157
 
159
158
  def is_better_than?(candidate1, candidate2)
@@ -1,3 +1,3 @@
1
1
  module FeldtRuby
2
- VERSION = "0.4.10"
2
+ VERSION = "0.4.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feldtruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: