ruby_ai 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a7c76464b2bf7f1d97d6c02c4190d8386321caf
4
+ data.tar.gz: e4afa36c2eabe9d1fc605997d034893c2aaa328b
5
+ SHA512:
6
+ metadata.gz: 9569b7b17fc23005f80b06694340dec6b87fda5843c8d1fa63b3019124fe305e010bfa8e539dae957f18c49769e2e1076c84fb40446c5241131af1c3592008b4
7
+ data.tar.gz: b48b78a96778258738077b286225bc5477c6aa66b8ec5dbbbeb059c89bdfcec727f4749589f8fb19a82f7bcd713569994d7a56d1c87270f01867310946a295e6
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_ai.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 igavriil
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ [![Build Status](https://travis-ci.org/igavriil/ruby_ai.svg)](https://travis-ci.org/igavriil/ruby_ai)
2
+
3
+ # RubyAi
4
+
5
+ Implementation of algorithms described in 'Artificial Intelligence: A modern approach' in ruby.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruby_ai'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruby_ai
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_ai. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_ai"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require "ruby_ai/version"
2
+ require "ruby_ai/search/core/frontier"
3
+ require "ruby_ai/search/core/problem"
4
+ require "ruby_ai/search/graph"
5
+ require "ruby_ai/search/edge"
6
+ require "ruby_ai/search/vertex"
7
+
8
+ module RubyAi
9
+
10
+ end
@@ -0,0 +1,102 @@
1
+ module RubyAi
2
+ module Search
3
+ module Core
4
+ class Frontier
5
+
6
+ attr_reader :store
7
+
8
+ def initialize
9
+ @store = []
10
+ end
11
+
12
+ def append(element:)
13
+ raise NotImplementedError
14
+ end
15
+
16
+ def pop
17
+ raise NotImplementedError
18
+ end
19
+
20
+ def size
21
+ @store.size
22
+ end
23
+
24
+ def empty?
25
+ @store.empty?
26
+ end
27
+
28
+ def include?(element:)
29
+ @store.include?(element)
30
+ end
31
+ end
32
+
33
+ class Queue < Frontier
34
+
35
+ def append(element:)
36
+ @store.unshift(element)
37
+ self
38
+ end
39
+
40
+ def pop
41
+ @store.pop
42
+ end
43
+ end
44
+
45
+ class Stack < Frontier
46
+
47
+ def append(element:)
48
+ @store.push(element)
49
+ self
50
+ end
51
+
52
+ def pop
53
+ @store.pop
54
+ end
55
+ end
56
+
57
+ class PriorityQueue < Frontier
58
+
59
+ def initialize(order: nil)
60
+ @order = Proc.new { |priorities| priorities.min }
61
+ @store = Hash.new { |hash, key| hash[key] = [] }
62
+ end
63
+
64
+ def append(element:, priority:)
65
+ @store[priority].push(element)
66
+ self
67
+ end
68
+
69
+ def pop
70
+ clean_store && @store[max_priority].pop
71
+ end
72
+
73
+ def empty?
74
+ clean_store && super
75
+ end
76
+
77
+ def size
78
+ @store.values.flatten.size
79
+ end
80
+
81
+ def include?(element:)
82
+ @store.values.flatten.include?(element)
83
+ end
84
+
85
+ def store
86
+ clean_store
87
+ super
88
+ end
89
+
90
+ private
91
+
92
+ def max_priority
93
+ @order.call(@store.keys)
94
+ end
95
+
96
+ def clean_store
97
+ @store.delete_if { |priority, elements| elements.empty? }
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,24 @@
1
+ module RubyAi
2
+ module Search
3
+ class Edge
4
+ attr_reader :start_vertex, :end_vertex, :cost
5
+
6
+ def initialize(start_vertex:, end_vertex:, cost:)
7
+ @start_vertex = start_vertex
8
+ @end_vertex = end_vertex
9
+ @cost = cost
10
+ end
11
+
12
+ def ==(other)
13
+ self.class == other.class &&
14
+ @start_vertex == other.start_vertex &&
15
+ @end_vertex == other.end_vertex &&
16
+ @cost == other.cost
17
+ end
18
+
19
+ def to_s
20
+ "edge: #{@start_vertex} (#{@cost}) #{@end_vertex}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,65 @@
1
+ require 'ruby_ai/search/vertex'
2
+ require 'ruby_ai/search/edge'
3
+
4
+ module RubyAi
5
+ module Search
6
+ class Graph
7
+ class << self
8
+ def undirected(&block)
9
+ new(directed: false, &block)
10
+ end
11
+
12
+ def directed(&block)
13
+ new(directed: true, &block)
14
+ end
15
+
16
+ private :new
17
+ end
18
+
19
+ attr_reader :vertices, :edges
20
+
21
+ def initialize(directed:, &block)
22
+ @vertices = []
23
+ @edges = []
24
+ @directed = directed
25
+ instance_eval(&block) if block_given?
26
+ end
27
+
28
+ def method_missing(method, *args, **kwargs, &block)
29
+ send(method, *args, **kwargs, &block)
30
+ end
31
+
32
+ def vertex(name)
33
+ @vertices.push(Vertex.new(name: name))
34
+ self
35
+ end
36
+
37
+ def edge(from:, to:, cost: 1)
38
+ start_vertex = find_or_create_vertex(name: from)
39
+ end_vertex = find_or_create_vertex(name: to)
40
+
41
+ create_forward_edge(start_vertex: start_vertex, end_vertex: end_vertex, cost: cost)
42
+ create_reverse_edge(start_vertex: start_vertex, end_vertex: end_vertex, cost: cost) unless @directed
43
+ self
44
+ end
45
+
46
+ private
47
+
48
+ def find_or_create_vertex(name:)
49
+ unless @vertices.find { |vertex| vertex.name == name }
50
+ vertex = Vertex.new(name: name)
51
+ @vertices.push(vertex)
52
+ end
53
+ @vertices.find { |vertex| vertex.name == name }
54
+ end
55
+
56
+ def create_forward_edge(start_vertex:, end_vertex:, cost:)
57
+ @edges.push(Edge.new(start_vertex: start_vertex, end_vertex: end_vertex, cost: cost))
58
+ end
59
+
60
+ def create_reverse_edge(start_vertex:, end_vertex:, cost:)
61
+ @edges.push(Edge.new(start_vertex: end_vertex, end_vertex: start_vertex, cost: cost))
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ module RubyAi
2
+ module Search
3
+ class Vertex
4
+ attr_reader :name
5
+
6
+ def initialize(name:)
7
+ @name = name
8
+ end
9
+
10
+ def ==(other)
11
+ self.class == other.class &&
12
+ @name == other.name
13
+ end
14
+
15
+ def to_s
16
+ "vertex: #{name}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module RubyAi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_ai/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_ai"
8
+ spec.version = RubyAi::VERSION
9
+ spec.authors = ["igavriil"]
10
+ spec.email = ["iasongavriil@gmail.com"]
11
+
12
+ spec.summary = %q{Artificial Intelligence library for ruby}
13
+ spec.description = %q{Implementation of algorithms described in 'Artificial Intelligence: A modern approach'}
14
+ spec.homepage = "http://github.com/igavriil/ruby_ai"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.3.0"
25
+ spec.add_development_dependency "coveralls"
26
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_ai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - igavriil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'Implementation of algorithms described in ''Artificial Intelligence:
70
+ A modern approach'''
71
+ email:
72
+ - iasongavriil@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".coveralls.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/ruby_ai.rb
89
+ - lib/ruby_ai/search/core/frontier.rb
90
+ - lib/ruby_ai/search/edge.rb
91
+ - lib/ruby_ai/search/graph.rb
92
+ - lib/ruby_ai/search/vertex.rb
93
+ - lib/ruby_ai/version.rb
94
+ - ruby_ai.gemspec
95
+ homepage: http://github.com/igavriil/ruby_ai
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Artificial Intelligence library for ruby
119
+ test_files: []