Module: Entity::Adjacent
- Defined in:
- lib/scout/network/entity.rb
Instance Method Summary collapse
-
#neighborhood(adjacency, k) ⇒ Object
list of neighbours up to a given radius using unweighted adjacency adjacency: Hash[String => Array] or TSV(:flat) treated as adjacency k: maximum number of steps Returns an Array of Arrays (one per entity when self is an array), each containing the reachable entities (as plain values) within k steps.
- #path_to(adjacency, entities, threshold = nil, max_steps = nil) ⇒ Object
- #random_paths_to(adjacency, l, times, entities) ⇒ Object
Instance Method Details
#neighborhood(adjacency, k) ⇒ Object
list of neighbours up to a given radius using unweighted adjacency adjacency: Hash[String => Array] or TSV(:flat) treated as adjacency k: maximum number of steps Returns an Array of Arrays (one per entity when self is an array), each containing the reachable entities (as plain values) within k steps
35 36 37 38 39 40 41 42 |
# File 'lib/scout/network/entity.rb', line 35 def neighborhood(adjacency, k) if Array === self self.collect{|entity| entity.neighborhood(adjacency, k)} else adj_hash = adjacency.respond_to?(:include?) ? adjacency : adjacency.to_hash Paths.neighborhood(adj_hash, self, k) end end |
#path_to(adjacency, entities, threshold = nil, max_steps = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/scout/network/entity.rb', line 5 def path_to(adjacency, entities, threshold = nil, max_steps = nil) if Array === self self.collect{|entity| entity.path_to(adjacency, entities, threshold, max_steps)} else if adjacency.type == :flat max_steps ||= threshold Paths.dijkstra(adjacency, self, entities, max_steps) else Paths.weighted_dijkstra(adjacency, self, entities, threshold, max_steps) end end end |
#random_paths_to(adjacency, l, times, entities) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/scout/network/entity.rb', line 18 def random_paths_to(adjacency, l, times, entities) if Array === self self.inject([]){|acc,entity| acc += entity.random_paths_to(adjacency, l, times, entities)} else paths = [] times.times do paths << Paths.random_weighted_dijkstra(adjacency, l, self, entities) end paths end end |