class ChaosDetector::GraphTheory::Edge
Constants
- EDGE_TYPES
Attributes
dep_node[RW]
edge_type[RW]
graph_props[W]
reduction[RW]
src_node[RW]
Public Class Methods
new(src_node, dep_node, edge_type: :default, reduction: nil)
click to toggle source
# File lib/chaos_detector/graph_theory/edge.rb, line 17 def initialize(src_node, dep_node, edge_type: :default, reduction: nil) raise ArgumentError, 'src_node is required ' unless src_node raise ArgumentError, 'dep_node is required ' unless dep_node @src_node = src_node @dep_node = dep_node @reduction = reduction @edge_type = edge_type @graph_props = {} end
Public Instance Methods
==(other)
click to toggle source
# File lib/chaos_detector/graph_theory/edge.rb, line 51 def ==(other) # puts "Checking src and dep" src_node == other.src_node && dep_node == other.dep_node end
edge_rank()
click to toggle source
# File lib/chaos_detector/graph_theory/edge.rb, line 28 def edge_rank EDGE_TYPES.fetch(@edge_type, 0) end
eql?(other)
click to toggle source
# File lib/chaos_detector/graph_theory/edge.rb, line 40 def eql?(other) self == other end
graph_props()
click to toggle source
Default behavior is accessor for @graph_props
# File lib/chaos_detector/graph_theory/edge.rb, line 45 def graph_props @graph_props end
hash()
click to toggle source
# File lib/chaos_detector/graph_theory/edge.rb, line 36 def hash [@src_node, @dep_node].hash end
merge!(other)
click to toggle source
Mutate this Edge
; combining attributes from other:
# File lib/chaos_detector/graph_theory/edge.rb, line 63 def merge!(other) raise ArgumentError, ('Argument other should be Edge object (was %s)' % other.class) unless other.is_a?(Edge) if EDGE_TYPES.dig(other.edge_type) > EDGE_TYPES.dig(edge_type) @edge_type = other.edge_type end # puts("EDGE REDUCTION: #{@reduction.class} -- #{other.class} // #{other.reduction.class}") @reduction = ChaosDetector::GraphTheory::Reduction.combine(@reduction, other.reduction) self end
to_s()
click to toggle source
# File lib/chaos_detector/graph_theory/edge.rb, line 56 def to_s s = format('[%s] -> [%s]', src_node.title, dep_node.title) s << "(#{reduction.reduction_sum})" if reduction&.reduction_sum.to_i > 1 s end
weight()
click to toggle source
# File lib/chaos_detector/graph_theory/edge.rb, line 32 def weight @reduction&.reduction_sum || 1 end