rbbt-dm 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/network/paths.rb +63 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d622e348e2b667b9a7a50d72b838b052a901ee1
|
4
|
+
data.tar.gz: 52aa969ad1244db73caa9869c7aac95ba676d8ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffc9db25cf186b73e846075f71704c48e2cd0287543d85c949a7ebaeef272351bdd064ed110dcdab6acbccf1e2819133e7a0a7ee74c3a65e7cfc2a42d9c3e070
|
7
|
+
data.tar.gz: a17ba0299410b15b3ca4baedae8b2b85821782f3217809a99f7353f09249a90b86bd4005b30413d8612700cb05d15f4d38f5521976d7de2704bc52c2c2a1fca8
|
data/lib/rbbt/network/paths.rb
CHANGED
@@ -61,9 +61,9 @@ module Paths
|
|
61
61
|
distances[u] = distance
|
62
62
|
path = extract_path(parents, start_node, u)
|
63
63
|
next if path.length > max_steps if max_steps
|
64
|
-
next if not adjacency.include?(u) or adjacency[u].nil? or adjacency[u].empty?
|
64
|
+
next if not adjacency.include?(u) or (adjacency[u].nil? or adjacency[u].empty? )
|
65
65
|
Misc.zip_fields(adjacency[u]).each do |v,node_dist|
|
66
|
-
next if threshold and node_dist > threshold
|
66
|
+
next if node_dist.nil? or (threshold and node_dist > threshold)
|
67
67
|
d = distance + node_dist
|
68
68
|
next unless d < distances[v] and d < best # we can't relax this one
|
69
69
|
active[v] << d
|
@@ -102,6 +102,7 @@ module Paths
|
|
102
102
|
distances[u] = distance
|
103
103
|
next if not adjacency.include?(u) or adjacency[u].nil? or adjacency[u].empty?
|
104
104
|
Misc.zip_fields(adjacency[u]).each do |v,node_dist|
|
105
|
+
next if node_dist.nil?
|
105
106
|
d = distance + (node_dist * (l + rand))
|
106
107
|
next unless d < distances[v] and d < best # we can't relax this one
|
107
108
|
active[v] << distances[v] = d
|
@@ -152,3 +153,63 @@ module Entity
|
|
152
153
|
end
|
153
154
|
end
|
154
155
|
end
|
156
|
+
|
157
|
+
module AssociationItem
|
158
|
+
|
159
|
+
def self.dijkstra(matches, start_node, end_node = nil, threshold = nil, max_steps = nil, &block)
|
160
|
+
adjacency = {}
|
161
|
+
|
162
|
+
matches.each do |m|
|
163
|
+
s, t, undirected = m.split "~"
|
164
|
+
next m if s.nil? or t.nil? or s.strip.empty? or t.strip.empty?
|
165
|
+
adjacency[s] ||= Set.new
|
166
|
+
adjacency[s] << t
|
167
|
+
next unless m.undirected
|
168
|
+
adjacency[t] ||= Set.new
|
169
|
+
adjacency[t] << s
|
170
|
+
end
|
171
|
+
|
172
|
+
return nil unless adjacency.include? start_node
|
173
|
+
|
174
|
+
active = PriorityQueue.new
|
175
|
+
distances = Hash.new { 1.0 / 0.0 }
|
176
|
+
parents = Hash.new
|
177
|
+
|
178
|
+
active[start_node] << 0
|
179
|
+
best = 1.0 / 0.0
|
180
|
+
found = false
|
181
|
+
node_dist_cache = {}
|
182
|
+
|
183
|
+
until active.empty?
|
184
|
+
u = active.priorities.first
|
185
|
+
distance = active.shift
|
186
|
+
distances[u] = distance
|
187
|
+
path = Paths.extract_path(parents, start_node, u)
|
188
|
+
next if path.length > max_steps if max_steps
|
189
|
+
next if not adjacency.include?(u) or (adjacency[u].nil? or adjacency[u].empty? )
|
190
|
+
adjacency[u].each do |v|
|
191
|
+
node_dist = node_dist_cache[[u,v]] ||= (block_given? ? block.call(u,v) : 1)
|
192
|
+
next if node_dist.nil? or (threshold and node_dist > threshold)
|
193
|
+
d = distance + node_dist
|
194
|
+
next unless d < distances[v] and d < best # we can't relax this one
|
195
|
+
active[v] << d
|
196
|
+
distances[v] = d
|
197
|
+
parents[v] = u
|
198
|
+
if (String === end_node ? end_node == v : end_node.include?(v))
|
199
|
+
best = d
|
200
|
+
found = true
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
return nil unless found
|
206
|
+
|
207
|
+
if end_node
|
208
|
+
end_node = (end_node & parents.keys).first unless String === end_node
|
209
|
+
return nil if not parents.include? end_node
|
210
|
+
Paths.extract_path(parents, start_node, end_node)
|
211
|
+
else
|
212
|
+
parents
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-dm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbbt-util
|