graphos 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/graphos-0.3.0.gem +0 -0
- data/graphos.gemspec +0 -2
- data/lib/graphos/algorithm/prim.rb +16 -0
- data/lib/graphos/version.rb +1 -1
- metadata +2 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 485ba688a49044d2f348f871a9a86a5e153311d2
|
4
|
+
data.tar.gz: 7052de8250626dea8ddebe9f13b23bee4f49a257
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e5ea2654b8cd7fe0274397ae1c200d9d572002a2e4e83cb6f19c694fda020d2c9df0669286faa2131a75844d70623d20cfc90a38f845e026227248913b915b8
|
7
|
+
data.tar.gz: 89966d08f93340481181609b86d07d6e04d770b5ddbbfb392c76a0b287b6f7e567ad92e6819a1ceed56883a986d82bd4283df77a68bdc77e1448ff52e211c000
|
data/graphos-0.3.0.gem
ADDED
Binary file
|
data/graphos.gemspec
CHANGED
@@ -23,6 +23,4 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "minitest", "~> 5.4"
|
24
24
|
spec.add_development_dependency "minitest-reporters", "~> 1.0"
|
25
25
|
spec.add_development_dependency "pry", "~>0.10"
|
26
|
-
|
27
|
-
spec.add_dependency "amorim-algorithms", "~>0.6"
|
28
26
|
end
|
@@ -14,6 +14,8 @@ module Graphos
|
|
14
14
|
heap = BinaryHeap.new{|x,y| x.value <=> y.value}
|
15
15
|
heap.push(initial, 0)
|
16
16
|
|
17
|
+
visited = Array.new(graph.size, false)
|
18
|
+
|
17
19
|
update_cost = -> (idx,cost) do
|
18
20
|
costs[idx] = cost
|
19
21
|
if heap.has_key? idx
|
@@ -24,10 +26,21 @@ module Graphos
|
|
24
26
|
end
|
25
27
|
|
26
28
|
while keyval=heap.pop
|
29
|
+
# Selecione u em V-S, tal que custo[u] é mínimo
|
27
30
|
idx = keyval.key
|
31
|
+
|
32
|
+
next if visited[idx]
|
33
|
+
|
34
|
+
# Adicione u em S
|
35
|
+
visited[idx] = true
|
36
|
+
|
28
37
|
node = graph[idx]
|
38
|
+
|
39
|
+
# Selecione u em V-S, tal que custo[u] é mínimo
|
29
40
|
node.edges.each do |edge|
|
41
|
+
# Se custo[v] > w((u,v)) então
|
30
42
|
if costs[edge.to.index] > edge.weight
|
43
|
+
# custo[v] = w((u,v))
|
31
44
|
fathers[edge.to.index] = node.index
|
32
45
|
update_cost.call(edge.to.index, edge.weight)
|
33
46
|
end
|
@@ -37,6 +50,9 @@ module Graphos
|
|
37
50
|
result = Weighted::Graph.new graph.size
|
38
51
|
fathers.each_with_index do |f,c|
|
39
52
|
if f
|
53
|
+
if result.edge(f,c)
|
54
|
+
puts "Existing #{f},#{c}"
|
55
|
+
end
|
40
56
|
result.add_edge(f, c, costs[c])
|
41
57
|
end
|
42
58
|
end
|
data/lib/graphos/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernardo Amorim
|
@@ -81,20 +81,6 @@ dependencies:
|
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0.10'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: amorim-algorithms
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '0.6'
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0.6'
|
98
84
|
description: This gems implements some graph algorithms and representations.
|
99
85
|
email:
|
100
86
|
- contato@bamorim.com
|
@@ -108,6 +94,7 @@ files:
|
|
108
94
|
- LICENSE.txt
|
109
95
|
- README.md
|
110
96
|
- Rakefile
|
97
|
+
- graphos-0.3.0.gem
|
111
98
|
- graphos.gemspec
|
112
99
|
- lib/graphos.rb
|
113
100
|
- lib/graphos/algorithm/dijkstra.rb
|