active_bacon 0.0.0
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 +15 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/active_bacon.gemspec +71 -0
- data/lib/active_bacon.rb +5 -0
- data/lib/active_bacon/a.rb +9 -0
- data/lib/active_bacon/a/path.rb +9 -0
- data/lib/active_bacon/a/star.rb +94 -0
- data/lib/active_bacon/path_record.rb +5 -0
- data/spec/active_bacon_spec.rb +70 -0
- data/spec/spec_helper.rb +82 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmMyMWZhYzg5NWVhM2QyMmI5MjlhNDhkNDY1MWFkODhkOWEzNTEyMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDA1NDEwNTk0MGEzOTVlYzY2MzZhNzUyYTFkMWY5OGM3OGZjMTJkNw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDE5Y2Y2NmQ0N2Q3Y2FhMmExYmUwNWI1MjRhNmQyYjY1MjNhNTc1MzUzZDZi
|
10
|
+
N2ZkYmFjZWU3N2YwNzIyNTRjZWQ4YWY3MjE0OGRmZThiYmQ0NmZjYzM2MGE2
|
11
|
+
MDI0ODA0NmZlYjA4MDA0NTY1MjY4MTA3MWM2ODk0OTQwZGU1OGM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTAwN2RkZWJjNDQyMTA0MWMwODQ1YTk4NjNkZWE1NTczY2FkOTZkNDE2Njc0
|
14
|
+
NTEyODRlYTRjOGJkMjQ3MjY3ZDg4YWRkZWQxMjExMjI1OWMzMWM5YjA1MDI2
|
15
|
+
YWMxYjIzYWVjOTBlMTEzNjY2NDgwZTE5ZTI1NzgxYTMyYWRmODQ=
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.14.1"
|
10
|
+
gem "bundler"
|
11
|
+
gem "jeweler", "~> 1.8.7"
|
12
|
+
gem 'activerecord', '~> 3.2.15'
|
13
|
+
end
|
14
|
+
|
15
|
+
gem 'hashie'
|
16
|
+
gem 'algorithms'
|
17
|
+
gem 'pry'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.15)
|
5
|
+
activesupport (= 3.2.15)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activerecord (3.2.15)
|
8
|
+
activemodel (= 3.2.15)
|
9
|
+
activesupport (= 3.2.15)
|
10
|
+
arel (~> 3.0.2)
|
11
|
+
tzinfo (~> 0.3.29)
|
12
|
+
activesupport (3.2.15)
|
13
|
+
i18n (~> 0.6, >= 0.6.4)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
addressable (2.3.5)
|
16
|
+
algorithms (0.6.1)
|
17
|
+
arel (3.0.2)
|
18
|
+
builder (3.0.4)
|
19
|
+
coderay (1.0.9)
|
20
|
+
diff-lcs (1.2.4)
|
21
|
+
faraday (0.8.8)
|
22
|
+
multipart-post (~> 1.2.0)
|
23
|
+
git (1.2.6)
|
24
|
+
github_api (0.10.1)
|
25
|
+
addressable
|
26
|
+
faraday (~> 0.8.1)
|
27
|
+
hashie (>= 1.2)
|
28
|
+
multi_json (~> 1.4)
|
29
|
+
nokogiri (~> 1.5.2)
|
30
|
+
oauth2
|
31
|
+
hashie (2.0.5)
|
32
|
+
highline (1.6.20)
|
33
|
+
httpauth (0.2.0)
|
34
|
+
i18n (0.6.5)
|
35
|
+
jeweler (1.8.8)
|
36
|
+
builder
|
37
|
+
bundler (~> 1.0)
|
38
|
+
git (>= 1.2.5)
|
39
|
+
github_api (= 0.10.1)
|
40
|
+
highline (>= 1.6.15)
|
41
|
+
nokogiri (= 1.5.10)
|
42
|
+
rake
|
43
|
+
rdoc
|
44
|
+
json (1.8.1)
|
45
|
+
jwt (0.1.8)
|
46
|
+
multi_json (>= 1.5)
|
47
|
+
method_source (0.8.2)
|
48
|
+
multi_json (1.8.2)
|
49
|
+
multi_xml (0.5.5)
|
50
|
+
multipart-post (1.2.0)
|
51
|
+
nokogiri (1.5.10)
|
52
|
+
oauth2 (0.9.2)
|
53
|
+
faraday (~> 0.8)
|
54
|
+
httpauth (~> 0.2)
|
55
|
+
jwt (~> 0.1.4)
|
56
|
+
multi_json (~> 1.0)
|
57
|
+
multi_xml (~> 0.5)
|
58
|
+
rack (~> 1.2)
|
59
|
+
pry (0.9.12.2)
|
60
|
+
coderay (~> 1.0.5)
|
61
|
+
method_source (~> 0.8)
|
62
|
+
slop (~> 3.4)
|
63
|
+
rack (1.5.2)
|
64
|
+
rake (10.1.0)
|
65
|
+
rdoc (4.0.1)
|
66
|
+
json (~> 1.4)
|
67
|
+
rspec (2.14.1)
|
68
|
+
rspec-core (~> 2.14.0)
|
69
|
+
rspec-expectations (~> 2.14.0)
|
70
|
+
rspec-mocks (~> 2.14.0)
|
71
|
+
rspec-core (2.14.7)
|
72
|
+
rspec-expectations (2.14.3)
|
73
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
74
|
+
rspec-mocks (2.14.4)
|
75
|
+
slop (3.4.6)
|
76
|
+
tzinfo (0.3.38)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
activerecord (~> 3.2.15)
|
83
|
+
algorithms
|
84
|
+
bundler
|
85
|
+
hashie
|
86
|
+
jeweler (~> 1.8.7)
|
87
|
+
pry
|
88
|
+
rspec (~> 2.14.1)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Dan Nguyen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "active_bacon"
|
18
|
+
gem.homepage = "http://github.com/dannguyen/active_bacon"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Implementing pathfinding for Rails records}
|
21
|
+
gem.description = %Q{Implementing pathfinding for Rails records}
|
22
|
+
gem.email = "dansonguyen@gmail.com"
|
23
|
+
gem.authors = ["Dan Nguyen"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "active_bacon #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "active_bacon"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dan Nguyen"]
|
12
|
+
s.date = "2013-11-02"
|
13
|
+
s.description = "Implementing pathfinding for Rails records"
|
14
|
+
s.email = "dansonguyen@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".rspec",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"active_bacon.gemspec",
|
27
|
+
"lib/active_bacon.rb",
|
28
|
+
"lib/active_bacon/a.rb",
|
29
|
+
"lib/active_bacon/a/path.rb",
|
30
|
+
"lib/active_bacon/a/star.rb",
|
31
|
+
"lib/active_bacon/path_record.rb",
|
32
|
+
"spec/active_bacon_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/dannguyen/active_bacon"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "2.0.5"
|
39
|
+
s.summary = "Implementing pathfinding for Rails records"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 4
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<algorithms>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<pry>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.14.1"])
|
49
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
51
|
+
s.add_development_dependency(%q<activerecord>, ["~> 3.2.15"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
54
|
+
s.add_dependency(%q<algorithms>, [">= 0"])
|
55
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2.14.1"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
59
|
+
s.add_dependency(%q<activerecord>, ["~> 3.2.15"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
63
|
+
s.add_dependency(%q<algorithms>, [">= 0"])
|
64
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2.14.1"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
68
|
+
s.add_dependency(%q<activerecord>, ["~> 3.2.15"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/lib/active_bacon.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# inspired by:
|
2
|
+
# http://rubyquiz.com/quiz98.html
|
3
|
+
|
4
|
+
# require 'algorithms'
|
5
|
+
# include Containers
|
6
|
+
|
7
|
+
require 'hashie'
|
8
|
+
|
9
|
+
module ActiveBacon
|
10
|
+
module A
|
11
|
+
class Star
|
12
|
+
|
13
|
+
def initialize(adjacency_func, cost_func)
|
14
|
+
@adjacency = adjacency_func
|
15
|
+
@cost = cost_func
|
16
|
+
# no use for distance function yet
|
17
|
+
# @distance = distance_func
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_path(start, goal)
|
21
|
+
|
22
|
+
result = Hashie::Mash.new(:success? => false)
|
23
|
+
|
24
|
+
visited = {}
|
25
|
+
|
26
|
+
pqueue = PriorityQueue.new
|
27
|
+
pqueue << [1, [start,[], 0]]
|
28
|
+
|
29
|
+
until result.success? || pqueue.empty?
|
30
|
+
# e.g. start, [], 0
|
31
|
+
spot, path_so_far, cost_so_far = pqueue.next
|
32
|
+
|
33
|
+
# if already been there, then skip
|
34
|
+
next if visited[spot]
|
35
|
+
|
36
|
+
# [] + start
|
37
|
+
new_path = path_so_far + [spot]
|
38
|
+
|
39
|
+
# if goal == spot, return the result
|
40
|
+
if goal == spot
|
41
|
+
result.path = new_path
|
42
|
+
result[:success?] = true
|
43
|
+
result[:cost] = cost_so_far
|
44
|
+
else
|
45
|
+
# continue
|
46
|
+
visited[spot] = cost_so_far
|
47
|
+
|
48
|
+
@adjacency.call(spot).each do |new_spot|
|
49
|
+
# if already been there, skip it
|
50
|
+
next if visited[new_spot]
|
51
|
+
this_cost = @cost.call(spot, new_spot)
|
52
|
+
|
53
|
+
if this_cost
|
54
|
+
new_cost = cost_so_far + this_cost
|
55
|
+
# add to queue
|
56
|
+
pqueue << [ new_cost, [new_spot, new_path, new_cost]]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end # while
|
61
|
+
|
62
|
+
result[:visited] = visited
|
63
|
+
|
64
|
+
return result # success? is false
|
65
|
+
end
|
66
|
+
|
67
|
+
class PriorityQueue
|
68
|
+
def initialize
|
69
|
+
@list = []
|
70
|
+
end
|
71
|
+
|
72
|
+
def add(priority, item)
|
73
|
+
@list << [priority, @list.length, item]
|
74
|
+
@list.sort!
|
75
|
+
end
|
76
|
+
|
77
|
+
def <<(pitem)
|
78
|
+
add(*pitem)
|
79
|
+
end
|
80
|
+
|
81
|
+
def next
|
82
|
+
@list.shift[2]
|
83
|
+
end
|
84
|
+
|
85
|
+
def empty?
|
86
|
+
@list.empty?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# module Star
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ActiveBacon" do
|
4
|
+
before do
|
5
|
+
@net = SnodeNet.new
|
6
|
+
@net.add_pairs 'a', 'b', 1
|
7
|
+
@net.add_pairs 'b', 'c', 1
|
8
|
+
@net.add_pairs 'c', 'd', 1
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
describe 'snodes work, sanity test' do
|
13
|
+
it 'should have node_names' do
|
14
|
+
expect(@net.node_names).to include 'a', 'b', 'c'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have proper costs' do
|
18
|
+
expect(@net.nodes['a'].cost_to_node('b')).to eq 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
describe 'star' do
|
24
|
+
before(:each) do
|
25
|
+
@star = A::Star.new(
|
26
|
+
->(node){ node.adjacent_nodes }, #adjacency
|
27
|
+
->(a, b){ a.cost_to_node(b) } # cost
|
28
|
+
)
|
29
|
+
|
30
|
+
@result = @star.find_path(@net.nodes['a'], @net.nodes['d'])
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'results format' do
|
34
|
+
it 'should be a success' do
|
35
|
+
expect(@result).to be_success
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have :path' do
|
39
|
+
expect(@result.path).to eq ['a', 'b', 'c', 'd']
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should have :cost' do
|
43
|
+
expect(@result.cost).to eq 3
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return :visited' do
|
47
|
+
expect(@result.visited).to eq( {"a"=>0, "b"=>1, "c"=>2} )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'failure' do
|
52
|
+
before do
|
53
|
+
@net.add_pairs 'x', 'y', 1
|
54
|
+
@failure = @star.find_path(@net.nodes['a'], @net.nodes['x'])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return a result failure when no path is found' do
|
58
|
+
expect(@failure).not_to be_success
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should still return a list of visited' do
|
62
|
+
expect(@failure.visited).to eq( {"a"=>0, "b"=>1, "c"=>2, "d"=>3} )
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'pry'
|
5
|
+
require 'active_bacon'
|
6
|
+
|
7
|
+
include ActiveBacon
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
|
11
|
+
config.filter_run_excluding skip: true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus => true
|
14
|
+
|
15
|
+
config.mock_with :rspec
|
16
|
+
|
17
|
+
# Use color in STDOUT
|
18
|
+
config.color_enabled = true
|
19
|
+
|
20
|
+
# Use color not only in STDOUT but also in pagers and files
|
21
|
+
config.tty = true
|
22
|
+
|
23
|
+
# Use the specified formatter
|
24
|
+
config.formatter = :documentation # :progress, :html, :textmate
|
25
|
+
|
26
|
+
config.before(:each) do
|
27
|
+
# DatabaseCleaner.start
|
28
|
+
end
|
29
|
+
|
30
|
+
config.after(:each) do
|
31
|
+
# DatabaseCleaner.clean
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
class Snode < String
|
40
|
+
def initialize(*str)
|
41
|
+
@nodes = {}
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def attach_to(node, nodecost)
|
47
|
+
@nodes[node] = nodecost
|
48
|
+
end
|
49
|
+
|
50
|
+
def cost_to_node(node)
|
51
|
+
@nodes[node]
|
52
|
+
end
|
53
|
+
|
54
|
+
def adjacent_nodes
|
55
|
+
@nodes.keys
|
56
|
+
end
|
57
|
+
|
58
|
+
def eql?(n)
|
59
|
+
self.to_s == n.to_s
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
class SnodeNet
|
65
|
+
attr_reader :nodes
|
66
|
+
def initialize
|
67
|
+
@nodes = {}
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_pairs(n1, n2, cost)
|
71
|
+
@a = @nodes.fetch(n1){ @nodes[n1] = Snode.new(n1) }
|
72
|
+
@b = @nodes.fetch(n2){ @nodes[n2] = Snode.new(n2) }
|
73
|
+
|
74
|
+
@a.attach_to(@b, cost)
|
75
|
+
@b.attach_to(@a, cost)
|
76
|
+
end
|
77
|
+
|
78
|
+
def node_names
|
79
|
+
@nodes.keys
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_bacon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: algorithms
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.8.7
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.8.7
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.2.15
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.2.15
|
111
|
+
description: Implementing pathfinding for Rails records
|
112
|
+
email: dansonguyen@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files:
|
116
|
+
- LICENSE.txt
|
117
|
+
files:
|
118
|
+
- .document
|
119
|
+
- .rspec
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE.txt
|
123
|
+
- Rakefile
|
124
|
+
- VERSION
|
125
|
+
- active_bacon.gemspec
|
126
|
+
- lib/active_bacon.rb
|
127
|
+
- lib/active_bacon/a.rb
|
128
|
+
- lib/active_bacon/a/path.rb
|
129
|
+
- lib/active_bacon/a/star.rb
|
130
|
+
- lib/active_bacon/path_record.rb
|
131
|
+
- spec/active_bacon_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: http://github.com/dannguyen/active_bacon
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.5
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Implementing pathfinding for Rails records
|
157
|
+
test_files: []
|