Class: TruthTableObject

Inherits:
Object
  • Object
show all
Defined in:
lib/truthtable/truth_table_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTruthTableObject

Returns a new instance of TruthTableObject.



2
3
4
5
6
7
# File 'lib/truthtable/truth_table_object.rb', line 2

def initialize
  @checked = {}
  @plan = {}
  @order = []
  @queue = []
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



8
9
10
# File 'lib/truthtable/truth_table_object.rb', line 8

def order
  @order
end

#planObject (readonly)

Returns the value of attribute plan.



8
9
10
# File 'lib/truthtable/truth_table_object.rb', line 8

def plan
  @plan
end

Instance Method Details

#[](index) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/truthtable/truth_table_object.rb', line 16

def [](index)
  s = "v[#{index}]"
  if @plan.has_key?(s)
    v = @plan[s]
  else
    fplan = @plan.dup
    fplan[s] = false
    fkey = fplan.keys.sort.map {|k| "#{k}=#{fplan[k]}" }.join(' ')
    @order += [s]
    @plan = fplan
    v = false
    if !@checked[fkey]
      tplan = @plan.dup
      tplan[s] = true
      tkey = tplan.keys.sort.map {|k| "#{k}=#{tplan[k]}" }.join(' ')
      torder = @order.dup
      torder[-1] = s
      @queue.unshift [tplan, torder]
      @checked[tkey] = true
      @checked[fkey] = true
    end
  end
  v
end

#next_planObject



10
11
12
13
14
# File 'lib/truthtable/truth_table_object.rb', line 10

def next_plan
  @log = {}
  @plan, @order = @queue.shift
  @plan
end