agens 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: 740c18cfd45be6fd7e9531f72f3be2ac9e6a5455
4
+ data.tar.gz: 7327d202fbfce1ab50b0b9747b647477eaa53bf0
5
+ SHA512:
6
+ metadata.gz: 6fbc9aec62703e049b9d6b85d9201ae4375118f4588e78cd60689d1169155d10d3e127866680a2231bdbea3c352d337f2425c521fa5c44343cf60ce22ec4f4db
7
+ data.tar.gz: f52fe4aa072e6132098b4aecd55005182832b6767e06ff313f61b71c26efdb6223be655220b14253f04a2f2a2a14dc9d9327e12f0125cb25bc8d703e2720d1c4
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Tomas Jukin
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.
@@ -0,0 +1,23 @@
1
+ = Agens - Framework for Multi-Agent Systems in Ruby
2
+
3
+ Agents is a framework for building Multi-Agent Systems (MAS) in Ruby. With support of COPL (Concurrency-Oriented Programming Language - thx to Celluloid) and Neurals Nets (thx to ai4r).
4
+
5
+ We have built Agens in order to design Multi-Agent System (MAS) to drive our #Probee Open Hardware robot. We wanted to build this MAS in Ruby - our beloved language.
6
+
7
+ Build with love in Prague.
8
+
9
+ == Contributing to Agens
10
+
11
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
12
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
13
+ * Fork the project.
14
+ * Start a feature/bugfix branch.
15
+ * Commit and push until you are happy with your contribution.
16
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2016 Tomas Jukin. See LICENSE.txt for
22
+ further details.
23
+
@@ -0,0 +1,5 @@
1
+ require 'agens/agent'
2
+ require 'agens/mas'
3
+ require 'agens/world'
4
+ require 'agens/sensor'
5
+ require 'agens/actuator'
@@ -0,0 +1,7 @@
1
+ require 'celluloid/current'
2
+
3
+ class Actuator
4
+ include Celluloid
5
+
6
+
7
+ end
@@ -0,0 +1,75 @@
1
+ require 'celluloid/current'
2
+
3
+ class Agent
4
+ include Celluloid
5
+ include Celluloid::Internals::Logger
6
+
7
+ class NotImplementedError < StandardError; end
8
+
9
+ def initialize
10
+ @sensor_classes = {}
11
+ @actuator_classes = {}
12
+ @sensors = {}
13
+ @actuators = {}
14
+
15
+ setup
16
+
17
+ @sensor_classes.each do |name, sensor_clazz|
18
+ sensor = sensor_clazz.new_link
19
+ @sensors[name] = sensor
20
+ end
21
+
22
+ @actuator_classes.each do |name, actuator_clazz|
23
+ actuator = actuator_clazz.new_link
24
+ @actuators[name] = actuator
25
+ end
26
+
27
+ self.async.think_loop
28
+ end
29
+
30
+ def to_s
31
+ s = "Agent #{self.class.name}:\n"
32
+ s << " Sensors:\n"
33
+ @sensor_classes.each {|n, _| s << " <- #{n}\n"}
34
+ s << " Actuators:\n"
35
+ @actuator_classes.each {|n, _| s << " -> #{n}\n"}
36
+
37
+ s
38
+ end
39
+
40
+ private
41
+ def think_loop
42
+ while true
43
+ perform_reasoning
44
+
45
+ sleep(1)
46
+ end
47
+ end
48
+
49
+ def idle
50
+ info "[#{self.class.name}] Idling..."
51
+ end
52
+
53
+ protected
54
+ def setup
55
+ warn "[#{self.class.name}] I do not have any setup...(give me some sensors and actuators please)"
56
+ end
57
+
58
+ def perform_reasoning
59
+ raise NotImplementedError, "[#{self.class.name}] My reasoning is not implemented yet..."
60
+ end
61
+
62
+ #region DSL
63
+ def sensor(sensor_clazz, name = nil)
64
+ name = sensor_clazz.name.to_sym if name == nil
65
+
66
+ @sensor_classes[name] = sensor_clazz
67
+ end
68
+
69
+ def actuator(actuator_clazz, name = nil)
70
+ name = actuator_clazz.name.to_sym if name == nil
71
+
72
+ @actuator_classes[name] = actuator_clazz
73
+ end
74
+ #endregion DSL
75
+ end
@@ -0,0 +1,111 @@
1
+ require 'celluloid/current'
2
+ require 'celluloid/supervision'
3
+
4
+ class AgentConfigRecipe
5
+ attr_reader :type, :name, :args
6
+
7
+ def initialize(type, name, args = [])
8
+ @type = type
9
+ @name = name
10
+ @args = args
11
+ end
12
+ end
13
+
14
+ class MAS
15
+ @@counters = {}
16
+ @@recipes = []
17
+
18
+ def initialize
19
+ @config = Celluloid::Supervision::Configuration.new
20
+ @names = []
21
+
22
+ @@recipes.each do |agent_recipe|
23
+ if !agent_recipe.args.nil? && agent_recipe.args.any?
24
+ @config.define(type: agent_recipe.type, as: agent_recipe.name, args: agent_recipe.args)
25
+ else
26
+ @config.define(type: agent_recipe.type, as: agent_recipe.name)
27
+ end
28
+
29
+ @names << agent_recipe.name
30
+ end
31
+ end
32
+
33
+ def run
34
+ puts "Running MAS #{self.class.name}..."
35
+ @config.deploy
36
+ end
37
+
38
+ def shutdown
39
+ puts "Stoping MAS #{self.class.name}..."
40
+ @config.shutdown
41
+ end
42
+
43
+ def world
44
+ World.new(@names)
45
+ end
46
+
47
+ def add_agent(agent, options = {})
48
+ recipe << self.generate_recipe(agent, options)
49
+
50
+ if !recipe.args.nil? && recipe.args.any?
51
+ @config.add(type: recipe.type, as: recipe.name, args: recipe.args)
52
+ else
53
+ @config.add(type: recipe.type, as: recipe.name)
54
+ end
55
+
56
+ self
57
+ end
58
+
59
+ #region DSL
60
+ # agent MyAgent
61
+ # agent MyAgent, as: :james_bond
62
+ # agent MyAgent, as: :james_bond, args: [1, 2]
63
+ def self.agent(agent, options = {})
64
+ @@recipes << self.generate_recipe(agent, options)
65
+ end
66
+
67
+ # agents MyAgent
68
+ # agents MyAgent, as: :james_bonds
69
+ # agents MyAgent, count: 10
70
+ # agents MyAgent, as: :james_bonds, count: 10
71
+ # agents MyAgent, as: :james_bonds, count: 10, args: [1, 2]
72
+ def self.agents(agent, options = {})
73
+ mas_name = self.name.to_sym
74
+ pool_name = "#{agent.class.name.to_sym}_pool"
75
+ @@counters[pool_name] ||= 0
76
+ @@counters[pool_name] += 1
77
+
78
+ name = options.key?(:as) ? options[:as] : "#{mas_name}_#{pool_name}_#{@@counters[pool_name]}"
79
+ count = options.key?(:count) ? options[:count] : nil
80
+
81
+ count = 2 if count == nil
82
+
83
+ count.times do
84
+ self.agent(agent, args: options[:args])
85
+ end
86
+
87
+ # TODO add support for new celluloid supervision pools (when they will be documented, see https://github.com/celluloid/celluloid-supervision)
88
+ # if count == nil
89
+ # pool agent, as: name
90
+ # else
91
+ # pool agent, as: name, size: count
92
+ # end
93
+ end
94
+ #endregion DSL
95
+
96
+ def self.generate_recipe(agent, options = {})
97
+ name = nil
98
+ if options.key?(:as)
99
+ name = options[:as]
100
+ else
101
+ mas_name = self.name.to_sym
102
+ agent_name = agent.name.to_sym
103
+ @@counters[agent_name] ||= 0
104
+ @@counters[agent_name] += 1
105
+
106
+ name = "#{mas_name}_#{agent_name}_#{@@counters[agent_name]}"
107
+ end
108
+
109
+ AgentConfigRecipe.new(agent, name, options[:args])
110
+ end
111
+ end
@@ -0,0 +1,7 @@
1
+ require 'celluloid/current'
2
+
3
+ class Sensor
4
+ include Celluloid
5
+
6
+
7
+ end
@@ -0,0 +1,27 @@
1
+ require 'celluloid/current'
2
+
3
+ class World
4
+ include Enumerable
5
+
6
+ def initialize(names)
7
+ @names = names
8
+ end
9
+
10
+ def [](agent)
11
+ Celluloid::Actor[agent]
12
+ end
13
+
14
+ def each
15
+ @names.each do |agent|
16
+ yield self[agent]
17
+ end
18
+ end
19
+
20
+ def dump
21
+ puts 'World contains:'
22
+
23
+ self.each do |agent|
24
+ puts agent.to_s
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: agens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Jukin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: celluloid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.17.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.17.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: celluloid-supervision
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.20.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.20.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: ai4r
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda
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
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: juwelier
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: |-
126
+ Agents is a framework for building Multi-Agent Systems (MAS) in Ruby. With support of COPL (Concurrency-Oriented Programming Language - thx to Celluloid) and Neural Nets (thx to ai4r).
127
+
128
+ We have built Agens in order to design Multi-Agent System (MAS) to drive our Probee Open Hardware robot. We wanted to build this MAS in Ruby.
129
+
130
+ Build with love in Prague.
131
+ email: tomas.jukin@juicymo.cz
132
+ executables: []
133
+ extensions: []
134
+ extra_rdoc_files:
135
+ - LICENSE.txt
136
+ - README.rdoc
137
+ files:
138
+ - LICENSE.txt
139
+ - README.rdoc
140
+ - lib/agens.rb
141
+ - lib/agens/actuator.rb
142
+ - lib/agens/agent.rb
143
+ - lib/agens/mas.rb
144
+ - lib/agens/sensor.rb
145
+ - lib/agens/world.rb
146
+ homepage: http://github.com/Inza/agens
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.6.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Framework for Multi-Agent Systems in Ruby
170
+ test_files: []