Class: Lrama::Counterexamples
- Inherits:
-
Object
- Object
- Lrama::Counterexamples
- Defined in:
- lib/lrama/counterexamples.rb,
lib/lrama/counterexamples/node.rb,
lib/lrama/counterexamples/path.rb,
lib/lrama/counterexamples/triple.rb,
lib/lrama/counterexamples/example.rb,
lib/lrama/counterexamples/derivation.rb,
lib/lrama/counterexamples/state_item.rb
Overview
See: https://www.cs.cornell.edu/andru/papers/cupex/cupex.pdf 4. Constructing Nonunifying Counterexamples
Defined Under Namespace
Classes: Derivation, Example, Node, Path, StateItem, Triple
Constant Summary collapse
- PathSearchTimeLimit =
10 sec
10- CumulativeTimeLimit =
120 sec
120
Instance Attribute Summary collapse
-
#productions ⇒ Object
readonly
: Hash[StateItem, Set[StateItem]].
-
#transitions ⇒ Object
readonly
@rbs! @states: States @iterate_count: Integer @total_duration: Float @exceed_cumulative_time_limit: bool @state_items: Hash[[State, State::Item], StateItem] @triples: Hash[Integer, Triple] @transitions: Hash[[StateItem, Grammar::Symbol], StateItem] @reverse_transitions: Hash[[StateItem, Grammar::Symbol], Set[StateItem]] @productions: Hash[StateItem, Set[StateItem]] @reverse_productions: Hash[[State, Grammar::Symbol], Set[StateItem]] # Grammar::Symbol is nterm @state_item_shift: Integer.
Instance Method Summary collapse
- #compute(conflict_state) ⇒ Object
-
#initialize(states) ⇒ Counterexamples
constructor
A new instance of Counterexamples.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(states) ⇒ Counterexamples
Returns a new instance of Counterexamples.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lrama/counterexamples.rb', line 38 def initialize(states) @states = states @iterate_count = 0 @total_duration = 0 @exceed_cumulative_time_limit = false @triples = {} setup_state_items setup_transitions setup_productions end |
Instance Attribute Details
#productions ⇒ Object (readonly)
: Hash[StateItem, Set[StateItem]]
35 36 37 |
# File 'lib/lrama/counterexamples.rb', line 35 def productions @productions end |
#transitions ⇒ Object (readonly)
@rbs! @states: States @iterate_count: Integer @total_duration: Float @exceed_cumulative_time_limit: bool @state_items: Hash[[State, State::Item], StateItem] @triples: Hash[Integer, Triple] @transitions: Hash[[StateItem, Grammar::Symbol], StateItem] @reverse_transitions: Hash[[StateItem, Grammar::Symbol], Set[StateItem]] @productions: Hash[StateItem, Set[StateItem]] @reverse_productions: Hash[[State, Grammar::Symbol], Set[StateItem]] # Grammar::Symbol is nterm @state_item_shift: Integer
34 35 36 |
# File 'lib/lrama/counterexamples.rb', line 34 def transitions @transitions end |
Instance Method Details
#compute(conflict_state) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lrama/counterexamples.rb', line 56 def compute(conflict_state) conflict_state.conflicts.flat_map do |conflict| # Check cumulative time limit for not each path search method call but each conflict # to avoid one of example's path to be nil. next if @exceed_cumulative_time_limit case conflict.type when :shift_reduce # @type var conflict: State::ShiftReduceConflict shift_reduce_example(conflict_state, conflict) when :reduce_reduce # @type var conflict: State::ReduceReduceConflict reduce_reduce_examples(conflict_state, conflict) end rescue Timeout::Error => e STDERR.puts "Counterexamples calculation for state #{conflict_state.id} #{e.} with #{@iterate_count} iteration" increment_total_duration(PathSearchTimeLimit) nil end.compact end |
#to_s ⇒ Object Also known as: inspect
50 51 52 |
# File 'lib/lrama/counterexamples.rb', line 50 def to_s "#<Counterexamples>" end |