Class: Wongi::Engine::BetaMemory
Instance Attribute Summary
Attributes inherited from BetaNode
#children, #context, #parent, #rete
Instance Method Summary
collapse
Methods inherited from BetaNode
#assignment_node, #delete_token, #depth, #empty?, #filter_node, #join_node, #ncc_node, #neg_node, #network, #optional_node, #refresh, #size, #tokens
Methods included from CoreExt
included
Constructor Details
#initialize(parent) ⇒ BetaMemory
Returns a new instance of BetaMemory.
5
6
7
8
|
# File 'lib/wongi-engine/beta/beta_memory.rb', line 5
def initialize parent
super
@tokens = []
end
|
Instance Method Details
#beta_activate(token) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/wongi-engine/beta/beta_memory.rb', line 33
def beta_activate token
existing = @tokens.reject(&:deleted?).find { |et| et.duplicate? token }
return if existing
@tokens << token
children.each do |child|
child.beta_activate token
end
token
end
|
#beta_deactivate(token) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/wongi-engine/beta/beta_memory.rb', line 43
def beta_deactivate token
return nil unless tokens.find token
@tokens.delete token
token.deleted!
if token.parent
token.parent.children.delete token
end
children.each do |child|
child.beta_deactivate token
end
token
end
|
#beta_memory ⇒ Object
11
12
13
|
# File 'lib/wongi-engine/beta/beta_memory.rb', line 11
def beta_memory
self
end
|
#refresh_child(child) ⇒ Object
56
57
58
59
60
|
# File 'lib/wongi-engine/beta/beta_memory.rb', line 56
def refresh_child child
tokens.each do |token|
child.beta_activate token
end
end
|
#seed(assignments = {}) ⇒ Object
15
16
17
18
19
|
# File 'lib/wongi-engine/beta/beta_memory.rb', line 15
def seed assignments = {}
@seed = assignments
t = Token.new( self, nil, nil, assignments )
@tokens << t
end
|
#subst(valuations) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/wongi-engine/beta/beta_memory.rb', line 21
def subst valuations
@tokens.first.destroy
token = Token.new( self, nil, nil, @seed )
@tokens << token
valuations.each { |variable, value| token.subst variable, value }
self.children.each do |child|
child.beta_activate token
end
end
|