Class: NEAT::Graph::DependencyResolver

Inherits:
NeatOb
  • Object
show all
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

#controller, #name

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NeatOb

#log, log, #to_s

Constructor Details

- (DependencyResolver) initialize(outputs, &block)

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

+ (Object) [](*outs)

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

- (Object) resolve

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

- (Object) resolve!

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