Class: DecisionAgent::Dmn::TreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/dmn/decision_tree.rb

Overview

Represents a node in a decision tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, label: nil, condition: nil, decision: nil) ⇒ TreeNode

Returns a new instance of TreeNode.



13
14
15
16
17
18
19
20
# File 'lib/decision_agent/dmn/decision_tree.rb', line 13

def initialize(id:, label: nil, condition: nil, decision: nil)
  @id = id
  @label = label
  @condition = condition # FEEL expression to evaluate
  @decision = decision   # Output decision if this is a leaf node
  @children = []
  @parent = nil
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10

def children
  @children
end

#conditionObject (readonly)

Returns the value of attribute condition.



10
11
12
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10

def condition
  @condition
end

#decisionObject (readonly)

Returns the value of attribute decision.



10
11
12
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10

def decision
  @decision
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



10
11
12
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10

def label
  @label
end

#parentObject

Returns the value of attribute parent.



11
12
13
# File 'lib/decision_agent/dmn/decision_tree.rb', line 11

def parent
  @parent
end

Instance Method Details

#add_child(node) ⇒ Object



22
23
24
25
# File 'lib/decision_agent/dmn/decision_tree.rb', line 22

def add_child(node)
  node.parent = self
  @children << node
end

#leaf?Boolean

Returns:



27
28
29
# File 'lib/decision_agent/dmn/decision_tree.rb', line 27

def leaf?
  @children.empty?
end

#to_hObject



31
32
33
34
35
36
37
38
39
# File 'lib/decision_agent/dmn/decision_tree.rb', line 31

def to_h
  {
    id: @id,
    label: @label,
    condition: @condition,
    decision: @decision,
    children: @children.map(&:to_h)
  }
end