Class: Util::Report
- Inherits:
-
Hash
- Object
- Hash
- Util::Report
- Defined in:
- ../lib/report.rb
Overview
Reporting helper class. The Report instance provides the simple interface for reporting the internal values and progression during the evolutionary algorithm’s run. This class assumes the reporting is done in steps.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) steps
readonly
The report step.
Instance Method Summary (collapse)
-
- (Object) <<(line)
Report the status (mostly textual) info for the current step.
-
- (Object) [](label)
Access the label for the current step.
-
- (Report) initialize
constructor
Prepare the empty reporter.
-
- (Object) labels
Return all labels used for reports, eg:.
-
- (Object) next
Advance to the next step of the report.
Constructor Details
- (Report) initialize
Prepare the empty reporter.
11 12 13 14 15 16 17 |
# File '../lib/report.rb', line 11 def initialize super @steps = 0 @line = '' @clear_line = true self.default = [] end |
Instance Attribute Details
- (Object) steps (readonly)
The report step. This value is incremented by the Report#next.
20 21 22 |
# File '../lib/report.rb', line 20 def steps @steps end |
Instance Method Details
- (Object) <<(line)
Report the status (mostly textual) info for the current step. For example:
r = ReportText.new
r << "this line is displayed"
r << "this line is also displayed"
r.next
27 28 29 30 31 |
# File '../lib/report.rb', line 27 def << line @line = '' if @clear_line @clear_line = false @line += ( line + "\n" ) end |
- (Object) [](label)
Access the label for the current step. For instance:
r['maxfitness'] << 42
r['diversity'] << 12
r['coolness'] << 'ok'
r.next
38 39 40 41 |
# File '../lib/report.rb', line 38 def [] label store( label, [] ) unless has_key? label fetch(label) end |
- (Object) labels
Return all labels used for reports, eg:
r['maxfitness'] << 2122
r['coolness'] << 'ok'
r.next
r['coolness'] << 'uh'
r['diversity'] << 12
r.next
r.labels # produces ['coolness', 'diversity', 'maxfitness']
62 63 64 |
# File '../lib/report.rb', line 62 def labels keys.sort {|a,b| a.to_s <=> b.to_s } end |
- (Object) next
Advance to the next step of the report.
44 45 46 47 48 49 50 51 52 |
# File '../lib/report.rb', line 44 def next @steps += 1 @clear_line = true each_value do |ary| raise "Report: cannot record twice in a single step" if ary.size > @steps ary.push nil while ary.size < @steps end end |