Class: NEAT::NeatOb
- Inherits:
-
Object
- Object
- NEAT::NeatOb
- Extended by:
- QueueDing
- Includes:
- DeepDive
- Defined in:
- lib/rubyneat/rubyneat.rb
Overview
Basis of all NEAT objects. NeatOb has support for NEAT attributes with special support for hooks and queues.
Direct Known Subclasses
Controller, Controller::NeatSettings, Critter, Critter::Genotype, Critter::Genotype::Gene, Critter::Phenotype, Evolver::CritterOp, Graph::DependencyResolver, Neuron, Operator, Population, Trait
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Who’s your daddy?.
-
#name ⇒ Object
readonly
Designation of this particular object instance.
Class Method Summary collapse
-
.attr_neat(sym, default: nil, cloneable: nil, hooks: false, queue: false) ⇒ Object
Defaultable attributes of neat attributes.
- .log ⇒ Object
Instance Method Summary collapse
-
#initialize(controller = nil, name = nil) ⇒ NeatOb
constructor
Initializer for all NEAT objects.
- #log ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(controller = nil, name = nil) ⇒ NeatOb
Initializer for all NEAT objects. Requires that the controller object is specified for all classes with the exception of the Controller itself or the Controller’s NeatSettings.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rubyneat/rubyneat.rb', line 117 def initialize(controller = nil, name = nil) @name = unless name.nil? name.to_sym else NEAT::random_name_generator end unless controller.nil? @controller = controller else raise NeatException.new "Controller Needed!" unless self.is_a?(Controller) or self.is_a?(Controller::NeatSettings) @controller = self unless self.is_a? Controller::NeatSettings end end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Who’s your daddy?
108 109 110 |
# File 'lib/rubyneat/rubyneat.rb', line 108 def controller @controller end |
#name ⇒ Object (readonly)
Designation of this particular object instance
105 106 107 |
# File 'lib/rubyneat/rubyneat.rb', line 105 def name @name end |
Class Method Details
.attr_neat(sym, default: nil, cloneable: nil, hooks: false, queue: false) ⇒ Object
Defaultable attributes of neat attributes.
If hooks: true is given, two hook functions are created: <sym>_add() – add a hook <sym>_set() – set a hook, overwriting all other hooks set or added. <sym>_clear – clear all hooks <sym>_none? – return true if no hooks are defined. <sym>_one? – return true if exactly hook is defined. <sym>_hook() – for passing unnamed parameters to a singular hook. <sym>_np_hook() – for passing unnamed parameters to a singular hook. <sym>_hook_itself() – for getting the proc reference to the hook. <sym>_hooks() – for passing unnamed parameters. <sym>_np_hooks() – for passing a named parameter list.
For *_hook(), the function returns the single result. For *_hooks(), the hook function return an array of results from all the actual registered hooks called.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rubyneat/rubyneat.rb', line 155 def attr_neat(sym, default: nil, cloneable: nil, hooks: false, queue: false) svar = "@#{sym}" # Guess what clonable should be. # This is meant to cover "90%" of the cases. cloneable = case when default.nil? false when default.kind_of?(Numeric) false else true end if cloneable.nil? # Sanity checks raise NeatException("Both hooks and queue cannot both be set for #{sym}.") if hooks and queue raise NeatException("Defaults cannot be defined for hooks and queues for #{sym}.") if (hooks or queue) and not default.nil? if hooks default = [] cloneable = true hook_setup sym end if queue default = QDing.new cloneable = true queue_setup sym end define_method("#{sym}=") do |v| instance_variable_set(svar, v) end unless hooks or queue # TODO: Enhance this getter method for performance. define_method(sym) do instance_variable_set(svar, instance_variable_get(svar) || ((cloneable) ? default.clone : default)) end end |
.log ⇒ Object
111 |
# File 'lib/rubyneat/rubyneat.rb', line 111 def self.log ; $log; end |
Instance Method Details
#log ⇒ Object
110 |
# File 'lib/rubyneat/rubyneat.rb', line 110 def log ; $log ; end |
#to_s ⇒ Object
131 132 133 |
# File 'lib/rubyneat/rubyneat.rb', line 131 def to_s "%s<%s>" % [self.class, self.name] end |