graphos 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14d4c0ca86eff6a4e8787e26744bbe20fcf26646
4
- data.tar.gz: 96d69c71586846335829e530ee9ad82c6f64a2f8
3
+ metadata.gz: 485ba688a49044d2f348f871a9a86a5e153311d2
4
+ data.tar.gz: 7052de8250626dea8ddebe9f13b23bee4f49a257
5
5
  SHA512:
6
- metadata.gz: f1dcc65d651e204dd016dc2d35bed53595fdfd0a4ccead3b3f8456fd0638152fa32483a4ef6419449bd21bc8acff6d3077c0c8383cb84e57db973392e7b743cd
7
- data.tar.gz: 50120e8b5d17ff5c0982a586f44f89ca63c36b9d8ddcad50d005e0ee5b5c484cc18f9abc8eef4f09f56d16d3e978cb19a387b03d3253689013d06d1714faf22f
6
+ metadata.gz: 7e5ea2654b8cd7fe0274397ae1c200d9d572002a2e4e83cb6f19c694fda020d2c9df0669286faa2131a75844d70623d20cfc90a38f845e026227248913b915b8
7
+ data.tar.gz: 89966d08f93340481181609b86d07d6e04d770b5ddbbfb392c76a0b287b6f7e567ad92e6819a1ceed56883a986d82bd4283df77a68bdc77e1448ff52e211c000
Binary file
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Graphos
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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