Class: Myaso::PiTable

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/myaso/pi_table.rb

Overview

A simple implementation of a dynamic programming table in the following form: $pi(i, u, v)$. where $i$ is an index and $u, v$ are elements of a finite set of tags.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default = nil) ⇒ PiTable

An instance of a dynamic programming table can consider the specified default value.


17
18
19
20
21
22
# File 'lib/myaso/pi_table.rb', line 17

def initialize(default = nil)
  @default = default
  @table = Hash.new do |h, k|
    h[k] = Hash.new { |h, k| h[k] = Hash.new(default) }
  end
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default


11
12
13
# File 'lib/myaso/pi_table.rb', line 11

def default
  @default
end

#tableObject (readonly)

Returns the value of attribute table


11
12
13
# File 'lib/myaso/pi_table.rb', line 11

def table
  @table
end

Instance Method Details

#[](i, u, v) ⇒ Object

Obtain the value of $pi(i, u, v)$ or return the default value if it is nil.


27
28
29
# File 'lib/myaso/pi_table.rb', line 27

def [] i, u, v
  table[i][u][v]
end

#[]=(i, u, v, value) ⇒ Object

Set a value of $pi(i, u, v)$.


33
34
35
# File 'lib/myaso/pi_table.rb', line 33

def []= i, u, v, value
  table[i][u][v] = value
end