Class: LogicTools::NodeNot
- Defined in:
- lib/logic_tools/logictree.rb
Overview
Represents a NOT node.
Instance Attribute Summary
Attributes inherited from NodeUnary
Instance Method Summary collapse
-
#dup ⇒ Object
Duplicates the node.
-
#eval ⇒ Object
Computes the value of the node.
-
#flatten ⇒ Object
Creates a new tree where the and, or or not operator of the current node is flattened.
-
#flatten_deep ⇒ Object
Creates a new tree where all the and, or and not operators from the current node are flattened.
-
#initialize(child) ⇒ NodeNot
constructor
Creates a NOT node with a
child. -
#to_s ⇒ Object
Converts to a string.
-
#to_sum_product(flattened = false) ⇒ Object
Creates a sum fo product from the tree rooted by current node.
Methods inherited from NodeUnary
#==, #each, #getVariablesRecurse, #size, #to_sym
Methods inherited from Node
#distribute, #each, #each_line, #each_maxterm, #each_minterm, #eql?, #getVariables, #hash, #inspect, #op, #simplify, #size, #to_std_conjunctive, #to_std_disjunctive, #to_sym
Constructor Details
#initialize(child) ⇒ NodeNot
Creates a NOT node with a child.
750 751 752 |
# File 'lib/logic_tools/logictree.rb', line 750 def initialize(child) super(:not,child) end |
Instance Method Details
#dup ⇒ Object
Duplicates the node.
755 756 757 |
# File 'lib/logic_tools/logictree.rb', line 755 def dup # :nodoc: return NodeNot.new(@child.dup) end |
#eval ⇒ Object
Computes the value of the node.
760 761 762 |
# File 'lib/logic_tools/logictree.rb', line 760 def eval # :nodoc: return !child.eval end |
#flatten ⇒ Object
Creates a new tree where the and, or or not operator of
the current node is flattened.
Default: simply duplicates the node.
768 769 770 771 772 773 774 775 |
# File 'lib/logic_tools/logictree.rb', line 768 def flatten # :nodoc: nchild = @child.flatten if nchild.op == :not then return nchild.child else return NodeNot.new(nchild) end end |
#flatten_deep ⇒ Object
Creates a new tree where all the and, or and not operators
from the current node are flattened.
Default: simply duplicate.
781 782 783 784 785 786 787 788 |
# File 'lib/logic_tools/logictree.rb', line 781 def flatten_deep # :nodoc: nchild = @child.flatten_deep if nchild.op == :not then return nchild.child else return NodeNot.new(child) end end |
#to_s ⇒ Object
Converts to a string.
798 799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/logic_tools/logictree.rb', line 798 def to_s # :nodoc: return @str if @str # Is the child a binary node? if child.op == :or || child.op == :and then # Yes must put parenthesis @str = "~(" + child.to_s + ")" else # No @str = "~" + child.to_s end return @str end |
#to_sum_product(flattened = false) ⇒ Object
Creates a sum fo product from the tree rooted by current node.
Argument +flattened+ tells if the tree is already flattend
793 794 795 |
# File 'lib/logic_tools/logictree.rb', line 793 def to_sum_product(flattened = false) # :nodoc: return NodeNot.new(@child.to_sum_product(flatten)) end |