class NEAT::Graph::DependencyResolver
Create an instantiation of this and pass it a list of nodes to resolve.
Public Class Methods
[](*outs)
click to toggle source
Create a DependencyResolver from either an array of outputs or a parameter list of outputs.
# File lib/rubyneat/graph.rb, line 48 def self.[](*outs) outs = outs.first if outs.first.kind_of? Array DependencyResolver.new outs end
new(outputs, &block)
click to toggle source
Given a list of output nodes, we shall work backwards from them to resolve their dependencies.
Calls superclass method
# File lib/rubyneat/graph.rb, line 40 def initialize(outputs, &block) @outputs = outputs super block.(self) unless block.nil? end
Public Instance Methods
resolve()
click to toggle source
Resolve dependencies, and return [dependency_list, circular_ref_node_list] Note that circular_ref_node_list shall be nil if there are no dependencies!
# 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!()
click to toggle source
Throw an exception if dependencies are found. We only return the dependency list since we throw an exception on circular dependencies.
# File lib/rubyneat/graph.rb, line 69 def resolve! dl, cl = resolve raise GraphException("Circular Dependency Detected: %s" % cl) unless cl.nil? dl end