Class: Lernen::Algorithm::Procedural::ReturnIndicesAcex

Inherits:
CexProcessor::Acex show all
Defined in:
lib/lernen/algorithm/procedural/return_indices_acex.rb

Overview

ReturnIndicesAcex is an acex implementation for finding the return index in procedural learning.

Instance Method Summary collapse

Methods inherited from CexProcessor::Acex

#effect, #size

Constructor Details

#initialize(cex, return_indices, query, manager) ⇒ ReturnIndicesAcex

: (

  Array[In | Call | Return] cex,
  Array[Integer] return_indices,
  ^(Array[In | Call | Return]) -> bool query,
  ATRManager[In, Call, Return] manager
) -> void


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lernen/algorithm/procedural/return_indices_acex.rb', line 24

def initialize(cex, return_indices, query, manager)
  super(return_indices.size + 1)

  @cex = cex
  @return_indices = return_indices
  @query = query
  @manager = manager

  @cache[0] = false
  @cache[return_indices.size] = true
end

Instance Method Details

#compute_effect(idx) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lernen/algorithm/procedural/return_indices_acex.rb', line 37

def compute_effect(idx)
  word_stack = []
  index = @return_indices[idx]

  while index > 0
    call_index = @manager.find_call_index(@cex, index)
    proc = @cex[call_index]
    normalized_word = @manager.expand(@manager.project(@cex[call_index + 1...index])) # steep:ignore
    word_stack << [proc, *normalized_word]
    index = call_index
  end

  word = []
  word_stack.reverse_each { word.concat(_1) }
  word.concat(@cex[@return_indices[idx]...]) # steep:ignore

  @query.call(word)
end