Class: Ibex::Runtime::RepairPolicy

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

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.

RBS:

  • (?insert_cost: Integer, ?delete_cost: Integer, ?replace_cost: Integer, ?max_cost: Integer, ?max_configurations: Integer, ?max_lookahead: Integer, ?success_shifts: Integer, ?max_stack: Integer) -> void

Parameters:

  • insert_cost: (Integer) (defaults to: 1)
  • delete_cost: (Integer) (defaults to: 1)
  • replace_cost: (Integer) (defaults to: 2)
  • max_cost: (Integer) (defaults to: 3)
  • max_configurations: (Integer) (defaults to: 5_000)
  • max_lookahead: (Integer) (defaults to: 8)
  • success_shifts: (Integer) (defaults to: 3)
  • max_stack: (Integer) (defaults to: 256)


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_costInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def delete_cost
  @delete_cost
end

#insert_costInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def insert_cost
  @insert_cost
end

#max_configurationsInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def max_configurations
  @max_configurations
end

#max_costInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def max_cost
  @max_cost
end

#max_lookaheadInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def max_lookahead
  @max_lookahead
end

#max_stackInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def max_stack
  @max_stack
end

#replace_costInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def replace_cost
  @replace_cost
end

#success_shiftsInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def success_shifts
  @success_shifts
end