Class: Ravensat::Node
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/ravensat/ast/node.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
6
7
8
|
# File 'lib/ravensat/ast/node.rb', line 6
def initialize
@children = []
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5
6
7
|
# File 'lib/ravensat/ast/node.rb', line 5
def children
@children
end
|
Instance Method Details
#&(object) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/ravensat/ast/node.rb', line 65
def &(object)
raise TypeError.new("#{object.class} can't be coerced into Ravensat::Node") unless object.is_a? Node
return self if object.is_a? NilNode
AndNode.new(self, object)
end
|
#clauses_size ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/ravensat/ast/node.rb', line 101
def clauses_size
cnt = 0
self.each_by_descriptive do |node|
cnt+=1 if node.is_a? AndNode
end
cnt
end
|
#cnf? ⇒ Boolean
86
87
88
|
# File 'lib/ravensat/ast/node.rb', line 86
def cnf?
@children.map(&:cnf?).reduce(:&)
end
|
#each ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/ravensat/ast/node.rb', line 49
def each
return to_enum unless block_given?
node_stack = [self]
until node_stack.empty?
current_node = node_stack.shift
next unless current_node
yield current_node
node_stack = node_stack.concat(current_node.children)
end
self if block_given?
end
|
#each_by_descriptive ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/ravensat/ast/node.rb', line 10
def each_by_descriptive
node_stack = [[self, self.children.clone]]
until node_stack.empty?
current_parent, current_children = node_stack.pop
current_node = current_children.shift
and_node_obj = AndNode.new
case current_node
when AndNode
node_stack.push [current_parent, current_children.clone]
node_stack.push [current_node, current_node.children.clone]
when OrNode
node_stack.push [current_parent, current_children.clone]
node_stack.push [current_node, current_node.children.clone]
when NotNode
yield(current_node)
yield(current_node.children.first)
if current_children.empty?
yield(and_node_obj)
else
yield(current_parent)
node_stack.push [current_parent, current_children.clone]
end
when VarNode, Extension::BooleanVariable
yield(current_node)
if current_children.empty?
yield(and_node_obj)
else
yield(current_parent)
node_stack.push [current_parent, current_children.clone]
end
end
end
end
|
#eval ⇒ Object
90
91
|
# File 'lib/ravensat/ast/node.rb', line 90
def eval
end
|
#to_dimacs ⇒ Object
83
84
|
# File 'lib/ravensat/ast/node.rb', line 83
def to_dimacs
end
|
#to_s ⇒ Object
79
80
81
|
# File 'lib/ravensat/ast/node.rb', line 79
def to_s
self.class.name
end
|
#vars ⇒ Object
93
94
95
|
# File 'lib/ravensat/ast/node.rb', line 93
def vars
self.select{|node| node.is_a? VarNode}.uniq
end
|
#vars_size ⇒ Object
97
98
99
|
# File 'lib/ravensat/ast/node.rb', line 97
def vars_size
self.vars.size
end
|
#|(object) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/ravensat/ast/node.rb', line 72
def |(object)
raise TypeError.new("#{object.class} can't be coerced into Ravensat::Node") unless object.is_a? Node
return self if object.is_a? NilNode
OrNode.new(self, object)
end
|