Class: Wongi::Engine::AlphaMemory
- Inherits:
-
Object
- Object
- Wongi::Engine::AlphaMemory
- Defined in:
- lib/wongi-engine/alpha_memory.rb
Instance Attribute Summary collapse
-
#betas ⇒ Object
readonly
Returns the value of attribute betas.
-
#rete ⇒ Object
readonly
Returns the value of attribute rete.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #activate(wme) ⇒ Object
- #deactivate(wme) ⇒ Object
-
#initialize(template, rete = nil) ⇒ AlphaMemory
constructor
A new instance of AlphaMemory.
- #inspect ⇒ Object
- #size ⇒ Object
- #snapshot!(alpha) ⇒ Object
- #to_s ⇒ Object
- #wmes ⇒ Object
Constructor Details
#initialize(template, rete = nil) ⇒ AlphaMemory
Returns a new instance of AlphaMemory.
7 8 9 10 11 12 13 |
# File 'lib/wongi-engine/alpha_memory.rb', line 7 def initialize template, rete = nil @template = template @rete = rete @betas = [] @wmes = [] @frozen = false end |
Instance Attribute Details
#betas ⇒ Object (readonly)
Returns the value of attribute betas.
5 6 7 |
# File 'lib/wongi-engine/alpha_memory.rb', line 5 def betas @betas end |
#rete ⇒ Object (readonly)
Returns the value of attribute rete.
5 6 7 |
# File 'lib/wongi-engine/alpha_memory.rb', line 5 def rete @rete end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/wongi-engine/alpha_memory.rb', line 5 def template @template end |
Instance Method Details
#activate(wme) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/wongi-engine/alpha_memory.rb', line 15 def activate wme wme..add_wme(wme, self) # TODO: it used to activate before adding to the list. mandated by the original thesis. investigate. it appears to create duplicate tokens - needs a remedy in collecting nodes betas.each do |beta| beta.alpha_activate wme end end |
#deactivate(wme) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/wongi-engine/alpha_memory.rb', line 23 def deactivate wme wme..remove_wme(wme, self) betas.each do |beta| beta.alpha_deactivate wme end end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/wongi-engine/alpha_memory.rb', line 36 def inspect "<Alpha #{__id__} template=#{template}>" end |
#size ⇒ Object
44 45 46 |
# File 'lib/wongi-engine/alpha_memory.rb', line 44 def size wmes.count end |
#snapshot!(alpha) ⇒ Object
30 31 32 33 34 |
# File 'lib/wongi-engine/alpha_memory.rb', line 30 def snapshot! alpha alpha.wmes.map( &:dup ).each do |wme| activate wme end end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/wongi-engine/alpha_memory.rb', line 40 def to_s inspect end |
#wmes ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/wongi-engine/alpha_memory.rb', line 48 def wmes Enumerator.new do |y| rete..each do || .raw_wmes(self).dup.each do |wme| y << wme end end end end |