Class: Ibex::Runtime::RepairPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/runtime/repair.rb

Overview

Explicit bounded cost and search policy for automatic token repair.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(insert_cost: 1, delete_cost: 1, replace_cost: 2, max_cost: 3, max_configurations: 5_000, max_lookahead: 8, success_shifts: 3, max_stack: 256) ⇒ RepairPolicy

Returns a new instance of RepairPolicy.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ibex/runtime/repair.rb', line 20

def initialize(insert_cost: 1, delete_cost: 1, replace_cost: 2, max_cost: 3, max_configurations: 5_000,
               max_lookahead: 8, success_shifts: 3, max_stack: 256)
  values = {
    insert_cost: insert_cost,
    delete_cost: delete_cost,
    replace_cost: replace_cost,
    max_cost: max_cost,
    max_configurations: max_configurations,
    max_lookahead: max_lookahead,
    success_shifts: success_shifts,
    max_stack: max_stack
  }
  invalid = values.find { |_name, value| !value.is_a?(Integer) || !value.positive? }
  raise ArgumentError, "#{invalid.first} must be a positive integer" if invalid
  raise ArgumentError, "success_shifts must not exceed max_lookahead" if success_shifts > max_lookahead

  values.each { |name, value| instance_variable_set(:"@#{name}", value) }
  freeze
end

Instance Attribute Details

#delete_costObject (readonly)

: Integer



9
10
11
# File 'lib/ibex/runtime/repair.rb', line 9

def delete_cost
  @delete_cost
end

#insert_costObject (readonly)

: Integer



8
9
10
# File 'lib/ibex/runtime/repair.rb', line 8

def insert_cost
  @insert_cost
end

#max_configurationsObject (readonly)

: Integer



12
13
14
# File 'lib/ibex/runtime/repair.rb', line 12

def max_configurations
  @max_configurations
end

#max_costObject (readonly)

: Integer



11
12
13
# File 'lib/ibex/runtime/repair.rb', line 11

def max_cost
  @max_cost
end

#max_lookaheadObject (readonly)

: Integer



13
14
15
# File 'lib/ibex/runtime/repair.rb', line 13

def max_lookahead
  @max_lookahead
end

#max_stackObject (readonly)

: Integer



15
16
17
# File 'lib/ibex/runtime/repair.rb', line 15

def max_stack
  @max_stack
end

#replace_costObject (readonly)

: Integer



10
11
12
# File 'lib/ibex/runtime/repair.rb', line 10

def replace_cost
  @replace_cost
end

#success_shiftsObject (readonly)

: Integer



14
15
16
# File 'lib/ibex/runtime/repair.rb', line 14

def success_shifts
  @success_shifts
end