Class: Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Reaction
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::Catalyst::Helpers::Reaction
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb
Constant Summary
Constants included from Constants
Constants::ACTIVATION_ENERGY, Constants::CATALYST_REDUCTION, Constants::CATALYST_TYPES, Constants::MAX_CATALYSTS, Constants::MAX_REACTIONS, Constants::POTENCY_DECAY, Constants::POTENCY_LABELS, Constants::REACTION_TYPES, Constants::SPECIFICITY_BONUS, Constants::YIELD_LABELS
Instance Attribute Summary collapse
-
#activation_energy ⇒ Object
readonly
Returns the value of attribute activation_energy.
-
#catalyst_id ⇒ Object
readonly
Returns the value of attribute catalyst_id.
-
#catalyzed ⇒ Object
readonly
Returns the value of attribute catalyzed.
-
#completed ⇒ Object
readonly
Returns the value of attribute completed.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#reactants ⇒ Object
readonly
Returns the value of attribute reactants.
-
#reaction_type ⇒ Object
readonly
Returns the value of attribute reaction_type.
-
#yield_value ⇒ Object
readonly
Returns the value of attribute yield_value.
Instance Method Summary collapse
-
#apply_catalyst!(catalyst) ⇒ Object
Apply a catalyst to lower the activation energy threshold.
-
#attempt!(energy_input) ⇒ Object
Attempt to complete the reaction with given energy input Completes if energy_input >= activation_energy; yield based on energy surplus.
- #catalyzed? ⇒ Boolean
- #complete? ⇒ Boolean
-
#initialize(reaction_type:, reactants:, activation_energy: ACTIVATION_ENERGY) ⇒ Reaction
constructor
A new instance of Reaction.
-
#spontaneous? ⇒ Boolean
Completed spontaneously — without a catalyst.
- #to_h ⇒ Object
- #yield_label ⇒ Object
Constructor Details
#initialize(reaction_type:, reactants:, activation_energy: ACTIVATION_ENERGY) ⇒ Reaction
Returns a new instance of Reaction.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 17 def initialize(reaction_type:, reactants:, activation_energy: ACTIVATION_ENERGY) @id = SecureRandom.uuid @reaction_type = reaction_type @reactants = Array(reactants) @activation_energy = activation_energy.clamp(0.0, 1.0) @yield_value = 0.0 @catalyzed = false @catalyst_id = nil @completed = false @created_at = Time.now.utc end |
Instance Attribute Details
#activation_energy ⇒ Object (readonly)
Returns the value of attribute activation_energy.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def activation_energy @activation_energy end |
#catalyst_id ⇒ Object (readonly)
Returns the value of attribute catalyst_id.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def catalyst_id @catalyst_id end |
#catalyzed ⇒ Object (readonly)
Returns the value of attribute catalyzed.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def catalyzed @catalyzed end |
#completed ⇒ Object (readonly)
Returns the value of attribute completed.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def completed @completed end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def id @id end |
#reactants ⇒ Object (readonly)
Returns the value of attribute reactants.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def reactants @reactants end |
#reaction_type ⇒ Object (readonly)
Returns the value of attribute reaction_type.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def reaction_type @reaction_type end |
#yield_value ⇒ Object (readonly)
Returns the value of attribute yield_value.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 14 def yield_value @yield_value end |
Instance Method Details
#apply_catalyst!(catalyst) ⇒ Object
Apply a catalyst to lower the activation energy threshold
30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 30 def apply_catalyst!(catalyst) reduction = catalyst.catalyze!(@reaction_type) @activation_energy = (@activation_energy - reduction).clamp(0.0, 1.0).round(10) @catalyzed = true @catalyst_id = catalyst.id end |
#attempt!(energy_input) ⇒ Object
Attempt to complete the reaction with given energy input Completes if energy_input >= activation_energy; yield based on energy surplus
39 40 41 42 43 44 45 46 47 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 39 def attempt!(energy_input) return false if @completed return false if energy_input < @activation_energy @completed = true surplus = (energy_input - @activation_energy).clamp(0.0, 1.0) @yield_value = (0.5 + (surplus * 0.5)).clamp(0.0, 1.0).round(10) true end |
#catalyzed? ⇒ Boolean
53 54 55 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 53 def catalyzed? @catalyzed end |
#complete? ⇒ Boolean
49 50 51 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 49 def complete? @completed end |
#spontaneous? ⇒ Boolean
Completed spontaneously — without a catalyst
58 59 60 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 58 def spontaneous? @completed && !@catalyzed end |
#to_h ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 66 def to_h { id: @id, reaction_type: @reaction_type, reactants: @reactants, activation_energy: @activation_energy, yield_value: @yield_value, yield_label: yield_label, catalyzed: @catalyzed, catalyst_id: @catalyst_id, completed: @completed, spontaneous: spontaneous?, created_at: @created_at } end |
#yield_label ⇒ Object
62 63 64 |
# File 'lib/legion/extensions/agentic/learning/catalyst/helpers/reaction.rb', line 62 def yield_label YIELD_LABELS.find { |range, _| range.cover?(@yield_value) }&.last || :negligible end |