Class: Toaster::StateNode
- Inherits:
-
Object
- Object
- Toaster::StateNode
show all
- Defined in:
- lib/toaster/state/state_node.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(properties = {}) ⇒ StateNode
Returns a new instance of StateNode.
18
19
20
21
22
23
24
25
|
# File 'lib/toaster/state/state_node.rb', line 18
def initialize(properties = {})
@properties = properties
@incoming = Set.new
@outgoing = Set.new
@preceding_task = nil
@succeeding_task = nil
@reachable_nodes = nil
end
|
Instance Attribute Details
#incoming ⇒ Object
Returns the value of attribute incoming.
15
16
17
|
# File 'lib/toaster/state/state_node.rb', line 15
def incoming
@incoming
end
|
#outgoing ⇒ Object
Returns the value of attribute outgoing.
15
16
17
|
# File 'lib/toaster/state/state_node.rb', line 15
def outgoing
@outgoing
end
|
#preceding_task ⇒ Object
Returns the value of attribute preceding_task.
16
17
18
|
# File 'lib/toaster/state/state_node.rb', line 16
def preceding_task
@preceding_task
end
|
#properties ⇒ Object
Returns the value of attribute properties.
15
16
17
|
# File 'lib/toaster/state/state_node.rb', line 15
def properties
@properties
end
|
#succeeding_task ⇒ Object
Returns the value of attribute succeeding_task.
16
17
18
|
# File 'lib/toaster/state/state_node.rb', line 16
def succeeding_task
@succeeding_task
end
|
Class Method Details
.state_merge(old_node, additional_new_state) ⇒ Object
64
65
66
|
# File 'lib/toaster/state/state_node.rb', line 64
def self.state_merge(old_node, additional_new_state)
return old_node.state_merge(additional_new_state)
end
|
Instance Method Details
#conflicts_with?(node, ignore_properties = []) ⇒ Boolean
46
47
48
49
|
# File 'lib/toaster/state/state_node.rb', line 46
def conflicts_with?(node, ignore_properties=[])
return !subset_of?(node.properties, ignore_properties) &&
!node.subset_of?(properties, ignore_properties)
end
|
#get_reachable_nodes(nodes_so_far = Set.new) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/toaster/state/state_node.rb', line 82
def get_reachable_nodes(nodes_so_far=Set.new)
stack = [self]
while !stack.empty?
node = stack.delete_at(0)
if !nodes_so_far.include?(node)
nodes_so_far << node
node.outgoing.each do |edge|
next_node = edge.node_to
stack << next_node
end
end
end
return nodes_so_far
end
|
#node_reachable?(node, check_cycles = true, nodes_visited = Set.new) ⇒ Boolean
72
73
74
|
# File 'lib/toaster/state/state_node.rb', line 72
def node_reachable?(node, check_cycles=true, nodes_visited=Set.new)
return reachable_nodes().include?(node)
end
|
#reachable?(node, check_cycles = true) ⇒ Boolean
68
69
70
|
# File 'lib/toaster/state/state_node.rb', line 68
def reachable?(node, check_cycles=true)
return node_reachable?(node, check_cycles)
end
|
#reachable_nodes ⇒ Object
76
77
78
79
80
|
# File 'lib/toaster/state/state_node.rb', line 76
def reachable_nodes()
return @reachable_nodes if @reachable_nodes
@reachable_nodes = get_reachable_nodes()
return @reachable_nodes
end
|
#satisfies_poststate(post) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/toaster/state/state_node.rb', line 55
def satisfies_poststate(post)
post.each do |key,value|
if @properties[key] != value
return false
end
end
return true
end
|
#state_merge(additional_new_state) ⇒ Object
51
52
53
|
# File 'lib/toaster/state/state_node.rb', line 51
def state_merge(additional_new_state)
@properties.merge(additional_new_state)
end
|
#subset_of?(state, ignore_properties = []) ⇒ Boolean
determine whether the state properties of this node are a subset of (or equal to) the properties of the given state
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/toaster/state/state_node.rb', line 29
def subset_of?(state, ignore_properties=[])
@properties.each do |prop,val|
if !ignore_properties.include?(prop)
val1 = MarkupUtil.get_value_by_path(state, prop, true)
contained = (val1 == val || val1.eql?(val))
if !contained
else
end
return false if !contained
end
end
return true
end
|