Class: Wongi::Engine::AlphaMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/wongi-engine/alpha_memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#betasObject (readonly)

Returns the value of attribute betas.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def betas
  @betas
end

#reteObject (readonly)

Returns the value of attribute rete.



5
6
7
# File 'lib/wongi-engine/alpha_memory.rb', line 5

def rete
  @rete
end

#templateObject (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
22
# File 'lib/wongi-engine/alpha_memory.rb', line 15

def activate wme
  @wmes << wme
  wme.alphas << 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



24
25
26
27
28
29
# File 'lib/wongi-engine/alpha_memory.rb', line 24

def deactivate wme
  @wmes.delete wme
  betas.each do |beta|
    beta.alpha_deactivate wme
  end
end

#inspectObject



37
38
39
# File 'lib/wongi-engine/alpha_memory.rb', line 37

def inspect
  "<Alpha #{__id__} template=#{template} wmes=#{@wmes}>"
end

#snapshot!(alpha) ⇒ Object



31
32
33
34
35
# File 'lib/wongi-engine/alpha_memory.rb', line 31

def snapshot! alpha
  alpha.wmes.map( &:dup ).each do |wme|
    activate wme
  end
end

#to_sObject



41
42
43
# File 'lib/wongi-engine/alpha_memory.rb', line 41

def to_s
  inspect
end

#wmesObject



45
46
47
48
49
50
51
# File 'lib/wongi-engine/alpha_memory.rb', line 45

def wmes
  Enumerator.new do |y|
    @wmes.dup.each do |wme|
      y << wme unless wme.deleted?
    end
  end
end