Class: NEAT::Graph::DependencyResolver
- Defined in:
- lib/rubyneat/graph.rb
Overview
Create an instantiation of this and pass it a list of nodes to resolve.
Instance Attribute Summary
Attributes inherited from NeatOb
Class Method Summary collapse
-
.[](*outs) ⇒ Object
Create a DependencyResolver from either an array of outputs or a parameter list of outputs.
Instance Method Summary collapse
-
#initialize(outputs, &block) ⇒ DependencyResolver
constructor
Given a list of output nodes, we shall work backwards from them to resolve their dependencies.
-
#resolve ⇒ Object
Resolve dependencies, and return [dependency_list, circular_ref_node_list] Note that circular_ref_node_list shall be nil if there are no dependencies!.
-
#resolve! ⇒ Object
Throw an exception if dependencies are found.
Methods inherited from NeatOb
Constructor Details
#initialize(outputs, &block) ⇒ DependencyResolver
Given a list of output nodes, we shall work backwards from them to resolve their dependencies.
40 41 42 43 44 |
# File 'lib/rubyneat/graph.rb', line 40 def initialize(outputs, &block) @outputs = outputs super block.(self) unless block.nil? end |
Class Method Details
.[](*outs) ⇒ Object
Create a DependencyResolver from either an array of outputs or a parameter list of outputs.
48 49 50 51 |
# File 'lib/rubyneat/graph.rb', line 48 def self.[](*outs) outs = outs.first if outs.first.kind_of? Array DependencyResolver.new outs end |
Instance Method Details
#resolve ⇒ Object
Resolve dependencies, and return [dependency_list, circular_ref_node_list] Note that circular_ref_node_list shall be nil if there are no dependencies!
56 57 58 59 60 61 62 63 64 |
# File 'lib/rubyneat/graph.rb', line 56 def resolve @resolved = [] @unresolved = [] @circular = [] @outputs.each do |onode| rdep onode end [@resolved, @circular.empty? ? nil : @circular] end |
#resolve! ⇒ Object
Throw an exception if dependencies are found. We only return the dependency list since we throw an exception on circular dependencies.
69 70 71 72 73 |
# File 'lib/rubyneat/graph.rb', line 69 def resolve! dl, cl = resolve raise GraphException("Circular Dependency Detected: %s" % cl) unless cl.nil? dl end |