Class: Legion::Extensions::Agentic::Integration::Tessellation::Helpers::TessellationEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Tessellation::Helpers::TessellationEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb
Constant Summary
Constants included
from Constants
Constants::COVERAGE_DECAY, Constants::COVERAGE_GROWTH, Constants::COVERAGE_LABELS, Constants::DEFAULT_COVERAGE, Constants::DENSITY_LABELS, Constants::DOMAINS, Constants::FIT_LABELS, Constants::FIT_TOLERANCE, Constants::FULL_COVERAGE_THRESHOLD, Constants::GAP_THRESHOLD, Constants::MAX_MOSAICS, Constants::MAX_TILES, Constants::OVERLAP_PENALTY, Constants::OVERLAP_THRESHOLD, Constants::TILE_SHAPES, Constants::TILE_TYPES
Instance Method Summary
collapse
Methods included from Constants
label_for
Constructor Details
Returns a new instance of TessellationEngine.
12
13
14
15
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 12
def initialize
@tiles = {}
@mosaics = {}
end
|
Instance Method Details
#connect_tiles(tile_a_id:, tile_b_id:) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 39
def connect_tiles(tile_a_id:, tile_b_id:)
a = @tiles[tile_a_id]
b = @tiles[tile_b_id]
return nil unless a && b
a.connect!(b.id)
b.connect!(a.id)
{ connected: true, tile_a: a.id, tile_b: b.id }
end
|
#create_tile(tile_type:, shape:, domain:, coverage: nil, fit_score: nil) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 17
def create_tile(tile_type:, shape:, domain:, coverage: nil, fit_score: nil)
tile = Tile.new(tile_type: tile_type, shape: shape, domain: domain,
coverage: coverage, fit_score: fit_score)
@tiles[tile.id] = tile
mosaic = find_or_create_mosaic(domain: domain)
mosaic.add_tile(tile)
prune_tiles
tile
end
|
#domain_coverage ⇒ Object
75
76
77
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 75
def domain_coverage
@mosaics.transform_values(&:total_coverage)
end
|
#expand_tile(tile_id:, amount: COVERAGE_GROWTH) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 27
def expand_tile(tile_id:, amount: COVERAGE_GROWTH)
tile = @tiles[tile_id]
return nil unless tile
tile.expand!(amount)
tile
end
|
#full_coverage_tiles ⇒ Object
55
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 55
def full_coverage_tiles = @tiles.values.select(&:full_coverage?)
|
#gap_density ⇒ Object
79
80
81
82
83
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 79
def gap_density
return 0.0 if @tiles.empty?
(gapped_tiles.size.to_f / @tiles.size).round(10)
end
|
#gapped_tiles ⇒ Object
52
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 52
def gapped_tiles = @tiles.values.select(&:gapped?)
|
#isolated_tiles ⇒ Object
54
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 54
def isolated_tiles = @tiles.values.select(&:isolated?)
|
#least_covered(limit: 5) ⇒ Object
89
90
91
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 89
def least_covered(limit: 5)
@tiles.values.sort_by(&:effective_coverage).first(limit)
end
|
#most_covered(limit: 5) ⇒ Object
85
86
87
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 85
def most_covered(limit: 5)
@tiles.values.sort_by { |t| -t.effective_coverage }.first(limit)
end
|
#overall_coherence ⇒ Object
69
70
71
72
73
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 69
def overall_coherence
return 0.0 if @mosaics.empty?
(@mosaics.values.sum(&:coherence) / @mosaics.size).round(10)
end
|
#overall_coverage ⇒ Object
57
58
59
60
61
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 57
def overall_coverage
return 0.0 if @mosaics.empty?
(@mosaics.values.sum(&:total_coverage) / @mosaics.size).round(10)
end
|
#overall_fit ⇒ Object
63
64
65
66
67
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 63
def overall_fit
return 0.0 if @tiles.empty?
(@tiles.values.sum(&:fit_score) / @tiles.size).round(10)
end
|
#seamless_tiles ⇒ Object
53
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 53
def seamless_tiles = @tiles.values.select(&:seamless?)
|
#shrink_all! ⇒ Object
35
36
37
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 35
def shrink_all!
@tiles.each_value { |t| t.shrink!(COVERAGE_DECAY) }
end
|
#tessellation_report ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 93
def tessellation_report
{
total_tiles: @tiles.size,
total_mosaics: @mosaics.size,
overall_coverage: overall_coverage,
coverage_label: Constants.label_for(COVERAGE_LABELS, overall_coverage),
overall_fit: overall_fit,
fit_label: Constants.label_for(FIT_LABELS, overall_fit),
overall_coherence: overall_coherence,
gap_density: gap_density,
gapped_count: gapped_tiles.size,
seamless_count: seamless_tiles.size,
isolated_count: isolated_tiles.size,
domain_coverage: domain_coverage,
mosaics: @mosaics.values.map(&:to_h)
}
end
|
#tiles_by_domain(domain:) ⇒ Object
49
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 49
def tiles_by_domain(domain:) = @tiles.values.select { |t| t.domain == domain.to_sym }
|
#tiles_by_shape(shape:) ⇒ Object
51
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 51
def tiles_by_shape(shape:) = @tiles.values.select { |t| t.shape == shape.to_sym }
|
#tiles_by_type(tile_type:) ⇒ Object
50
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 50
def tiles_by_type(tile_type:) = @tiles.values.select { |t| t.tile_type == tile_type.to_sym }
|
#to_h ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb', line 111
def to_h
{
total_tiles: @tiles.size,
total_mosaics: @mosaics.size,
coverage: overall_coverage,
fit: overall_fit,
coherence: overall_coherence
}
end
|