Class: Legion::Extensions::Agentic::Integration::Map::Helpers::Location
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Map::Helpers::Location
- Defined in:
- lib/legion/extensions/agentic/integration/map/helpers/location.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#familiarity ⇒ Object
readonly
Returns the value of attribute familiarity.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_visited ⇒ Object
readonly
Returns the value of attribute last_visited.
-
#neighbors ⇒ Object
readonly
Returns the value of attribute neighbors.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#visit_count ⇒ Object
readonly
Returns the value of attribute visit_count.
Instance Method Summary collapse
- #add_neighbor(neighbor_id, distance: Constants::DEFAULT_DISTANCE) ⇒ Object
- #decay ⇒ Object
- #faded? ⇒ Boolean
-
#initialize(id:, domain: :general, properties: {}) ⇒ Location
constructor
A new instance of Location.
- #label ⇒ Object
- #remove_neighbor(neighbor_id) ⇒ Object
- #to_h ⇒ Object
- #visit ⇒ Object
Constructor Details
#initialize(id:, domain: :general, properties: {}) ⇒ Location
Returns a new instance of Location.
12 13 14 15 16 17 18 19 20 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 12 def initialize(id:, domain: :general, properties: {}) @id = id @domain = domain @properties = properties @familiarity = Constants::FAMILIARITY_FLOOR @visit_count = 0 @last_visited = nil @neighbors = {} # neighbor_id => distance end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 10 def domain @domain end |
#familiarity ⇒ Object (readonly)
Returns the value of attribute familiarity.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 10 def familiarity @familiarity end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 10 def id @id end |
#last_visited ⇒ Object (readonly)
Returns the value of attribute last_visited.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 10 def last_visited @last_visited end |
#neighbors ⇒ Object (readonly)
Returns the value of attribute neighbors.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 10 def neighbors @neighbors end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 10 def properties @properties end |
#visit_count ⇒ Object (readonly)
Returns the value of attribute visit_count.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 10 def visit_count @visit_count end |
Instance Method Details
#add_neighbor(neighbor_id, distance: Constants::DEFAULT_DISTANCE) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 28 def add_neighbor(neighbor_id, distance: Constants::DEFAULT_DISTANCE) distance = [distance, Constants::DISTANCE_FLOOR].max return if @neighbors.size >= Constants::MAX_EDGES_PER_LOCATION && !@neighbors.key?(neighbor_id) @neighbors[neighbor_id] = distance end |
#decay ⇒ Object
39 40 41 42 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 39 def decay new_val = @familiarity - Constants::FAMILIARITY_DECAY @familiarity = [new_val, Constants::FAMILIARITY_FLOOR].max end |
#faded? ⇒ Boolean
44 45 46 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 44 def faded? @familiarity <= Constants::FAMILIARITY_FLOOR && @visit_count.zero? end |
#label ⇒ Object
48 49 50 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 48 def label Constants.familiarity_level(@familiarity) end |
#remove_neighbor(neighbor_id) ⇒ Object
35 36 37 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 35 def remove_neighbor(neighbor_id) @neighbors.delete(neighbor_id) end |
#to_h ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 52 def to_h { id: @id, domain: @domain, properties: @properties, familiarity: @familiarity.round(4), label: label, visit_count: @visit_count, last_visited: @last_visited, neighbor_ids: @neighbors.keys, edge_count: @neighbors.size } end |
#visit ⇒ Object
22 23 24 25 26 |
# File 'lib/legion/extensions/agentic/integration/map/helpers/location.rb', line 22 def visit @visit_count += 1 @last_visited = Time.now.utc @familiarity = [@familiarity + Constants::VISIT_BOOST, 1.0].min end |