y_nelson 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,3 +34,4 @@ structure aspect is still under development.
34
34
  3. Commit your changes (`git commit -am 'Add some feature'`)
35
35
  4. Push to the branch (`git push origin my-new-feature`)
36
36
  5. Create new Pull Request
37
+
data/Rakefile CHANGED
@@ -1 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
+
@@ -16,8 +16,14 @@
16
16
  class YNelson::Agent
17
17
  attr_reader :world
18
18
 
19
- include YPetri::Agent::PetriNetRelated
20
- include YPetri::Agent::SimulationRelated
19
+ YPetri::Agent::PetriNetAspect
20
+ YPetri::Agent::SimulationAspect
21
+
22
+ # Future module YNelson::Agent::SimulationRelated
23
+
24
+ # Calls #finalize before invoking YPetri::Agent#new_simulation.
25
+ #
26
+ def new_simulation *args; finalize; super end
21
27
 
22
28
  # Initialization of a YNelson::Agent instance. For YNelson manipulators, the
23
29
  # world is always YNelson itself.
@@ -37,6 +43,7 @@ class YNelson::Agent
37
43
  YNelson::DimensionPoint.new YNelson.Dimension( :row )
38
44
  @secondary_dimension_point =
39
45
  YNelson::DimensionPoint.new YNelson.Dimension( :column )
46
+ @todo = [] # array of blocks
40
47
  end
41
48
 
42
49
  # Now the part related to the zz structure itself, like in
@@ -48,20 +55,9 @@ class YNelson::Agent
48
55
  attr_reader :sheets
49
56
 
50
57
  # Dimension convenience constructor from
51
- delegate( :Dimension,
52
- to: :world )
58
+ delegate :Dimension,
59
+ to: :world
53
60
 
54
- # Creation of a single-output formula known well from spreadseets. Given a
55
- # place, it creates a new assignment transition.
56
- #
57
- def ϝ &block
58
- new_place = YNelson::Place.new
59
- new_transition = YNelson::Transition.new assignment: true,
60
- codomain: new_place,
61
- action: block
62
- return new_place, new_transition
63
- end
64
-
65
61
  # Now let's look into the graph visualization.
66
62
 
67
63
  def default_dimension
@@ -151,6 +147,52 @@ class YNelson::Agent
151
147
 
152
148
  # graphviz [:domain, 0 ], [:codomain, 0]
153
149
 
150
+
151
+ # Creation of a place governed by a single assignment transition. In other
152
+ # words, creation of a place with a unary-output formula known well from
153
+ # spreadsheets. The transition is named automatically by adding "_ϝ"
154
+ # (digamma, resembles mathematical f used to denote functions) suffix to
155
+ # the place's name, as soon as the place is named. For example,
156
+ #
157
+ # Fred = PAT Joe do |joe| joe * 2 end
158
+ #
159
+ # creates a place named "Fred" and an assignment transition named "Fred_ϝ"
160
+ # that keeps Fred equal to 2 times Joe.
161
+ #
162
+ def PAT *domain, **named_args, &block
163
+ Place().tap do |p| # place can be instantiated right away
164
+ p.name = named_args.delete :name if named_args.has? :name, syn!: :ɴ
165
+ @todo << -> {
166
+ t = AT p, domain: domain, &block
167
+ if p.name then t.name = "#{p.name}_ϝ" else
168
+ # Rig the hook to name the transition as soon as the place is named.
169
+ p.name_set_hook do |name| transition.name = "#{name}_ϝ" end
170
+ end
171
+ # Monkey-patch the place with default marking closure.
172
+ p.define_singleton_method :default_marking do
173
+ if has_default_marking? then local_variable_get :@default_marking else
174
+ t.action_closure.( *t.domain.map( &:default_marking ) )
175
+ end
176
+ end
177
+ }
178
+ end
179
+ end
180
+ alias ϝ PAT
181
+
182
+ # Executes all @todo closures.
183
+ #
184
+ def finalize
185
+ while not @todo.empty?
186
+ @todo[-1].call # May raise errors in which case we don't want to pop.
187
+ @todo.pop # That's why not @todo.pop.call while not @todo.empty?
188
+ end
189
+ end
190
+
191
+ # ============================================================================
192
+ # === THE METHODS BELOW ARE NOT REVIEWED FOR THE NEW VERSION AND NOT ===
193
+ # === EXPOSED IN THE DSL YET ===
194
+ # ============================================================================
195
+
154
196
  # Cell side referencers with r. to primary and secondary point
155
197
  def ξ_posward_side dim=nil; ::YTed::POINT.posward_side dim end
156
198
  alias :ξp :ξ_posward_side
@@ -273,106 +315,4 @@ class YNelson::Agent
273
315
  .define_singleton_method name.to_sym do ::YTed::SHEETS[name] end
274
316
  return ::YTed::SHEETS[name]
275
317
  end
276
-
277
- def make_transitions
278
- # require 'debug'
279
- # LATER: When walking around the sheets, currently, there is no
280
- # protection against references to empty cells
281
- @transitions_to_make.map { |prescription|
282
- sheet = prescription[:sheet]
283
- type = prescription[:type]
284
- place = prescription[:place]
285
- block = prescription[:assignment_closure]
286
-
287
- case type
288
- when :unary_codomain_w_magic_block
289
- # PARAMETER MAGIC:
290
- # Blocks with specially named input arguments
291
- domain = block.parameters.map{ |e| e[1].to_s }.map{ |param|
292
- point = ZzPoint.new( place )
293
- if SHEETS.keys.include? sheet_name = param.split('_')[0] then
294
- # if the name consists of a sheet and parameter name, then ok
295
- rest = param[sheet_name.size + 1..-1]
296
- point = ZzPoint.new( SHEETS[sheet_name][0][0] )
297
- col = [*('a'..'z')].index rest[0]
298
- point.rewind_negward! :x
299
- if rest.size > 1 then # also change row, asssuming "a0" style
300
- point.rewind_negward! :y
301
- row = rest[1..-1].to_i
302
- row.times { point.step_posward :y }
303
- end
304
- col.times { point.step_posward :x }
305
- point.cell
306
- elsif [*('a'..'z')].include? param[0] then
307
- # if the name consists of an alphabetic letter...
308
- col = [*('a'..'z')].index param[0]
309
- point.rewind_negward! :x
310
- if param.size > 1 then # also change row, assuming "a0" style
311
- point.rewind_negward! :y
312
- row = param[1..-1].to_i
313
- row.times { point.step_posward :y }
314
- end
315
- col.times { point.step_posward :x }
316
- point.cell
317
- elsif param[0] = '_' then
318
- # Params named '_1', '_2', ... refer to different rows, same :col,
319
- # param named '__' refers to same cell
320
- if param == '__' then cell else
321
- i = param[1..-1].to_i
322
- point.rewind_negward! :y
323
- i.times { point.step_posward :x }
324
- point.cell
325
- end
326
- else
327
- raise TypeError, "unrecognized magic block parameter: #{param}"
328
- end
329
- } # block.parameters.map
330
-
331
- # Instantiate the new transition (do not fire it yet):
332
- Transition( domain: domain,
333
- codomain: [ place ],
334
- action_closure: block,
335
- assignment_action: true )
336
- when :downstream_copy
337
- # DOWNSTREAM COPY
338
- # A single transition assigning upstream value to the downstream cell
339
- Transition( domain: prescription[:domain],
340
- codomain: [ place ],
341
- action_closure: λ {|v| v },
342
- assignment_action: true )
343
- else raise "Unknown transition prescription type: #{prescription[:type]}"
344
- end
345
- } # @transitions_to_make.map
346
- end
347
-
348
- # Places an order for a spreadsheet-like assignment transition. The order
349
- # will be fullfilled later when #make_transitions method is called.
350
- #
351
- def new_downstream_cell &block
352
- # The place can be instatiated right away
353
- place = ZzCell( nil )
354
-
355
- # Transition making requests get remembered in @transitions_to_make:
356
- ( @transitions_to_make ||= [] ) <<
357
- { place: place,
358
- sheet: @current_sheet_name,
359
- assignment_closure: block,
360
- type: :unary_codomain_w_magic_block }
361
- return place
362
- end
363
- alias :ϝ :new_downstream_cell
364
-
365
- # Places an order for a spreadsheet-lie pure reference to another cell.
366
- #
367
- def new_downstream_copy( cell )
368
- # Again, the place can be instantiated immediately
369
- p = ZzCell( nil )
370
-
371
- # And put the transition making request to @transitions_to_make:
372
- ( @transitions_to_make ||= [] ) <<
373
- { place: p, sheet: @current_sheet_name, domain: cell,
374
- type: :downstream_copy }
375
- return p
376
- end
377
- alias :↱ :new_downstream_copy
378
318
  end
data/lib/y_nelson/dsl.rb CHANGED
@@ -67,10 +67,9 @@ module YNelson
67
67
  :plot_delta,
68
68
  to: :y_nelson_agent )
69
69
 
70
-
71
70
  # Zz aspect.
72
71
  delegate( :Dimension,
73
- :ϝ,
72
+ :sheets,
74
73
  :default_dimension,
75
74
  :primary_point, :p1,
76
75
  :secondary_point, :p2,
@@ -78,5 +77,7 @@ module YNelson
78
77
  :secondary_dimension_point, :d2,
79
78
  :visualize,
80
79
  :graphviz,
80
+ :PAT, :ϝ,
81
+ :finalize,
81
82
  to: :y_nelson_agent )
82
83
  end # module YNelson
@@ -1,4 +1,3 @@
1
-
2
1
  # YNelson::Place is analogical to a spreadsheet cell. It is based on
3
2
  # YPetri::Place and offers simlar interace.
4
3
  #
@@ -1,4 +1,4 @@
1
1
  module YNelson
2
2
  DEBUG = false
3
- VERSION = "2.1.0"
3
+ VERSION = "2.3.0"
4
4
  end
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # coding: utf-8
2
2
 
3
3
  # A pointer to a Zz object. A glorified variable, basically.
4
4
  #
data/lib/y_nelson.rb CHANGED
@@ -61,8 +61,8 @@ module YNelson
61
61
  attr_reader :dimensions
62
62
 
63
63
  # Including instance methods of YPetri::World:
64
- include YPetri::World::PetriNetRelated
65
- include YPetri::World::SimulationRelated
64
+ include YPetri::World::PetriNetAspect
65
+ include YPetri::World::SimulationAspect
66
66
 
67
67
  # Allows summoning YNelson::DSL by 'include YNelson'.
68
68
  #
@@ -70,6 +70,20 @@ module YNelson
70
70
  receiver.extend YNelson::DSL
71
71
  receiver.delegate :y_nelson_agent, to: "self.class"
72
72
  end
73
+
74
+ # TODO: YNelson class, obviously, works. But there is something funny
75
+ # about how it works. It seems that all the important methods, such
76
+ # as Place(), Transition(), run!() don't go through the Agent (via
77
+ # receiver.extend YNelson::DSL), but instead go directly through
78
+ # include YPetri::World::PetriNetAspect and
79
+ # include YPetri::World::SimulationAspect. While it is appropriate
80
+ # that YNelson singleton class, since we have decided that it would
81
+ # be basically a kind of YPetri::World, should have attributes of
82
+ # YPetri::World, it is surprising that the method calls that are
83
+ # supposed to be intercepted by the agent and only then sent to the
84
+ # world, are handled by the world directly. This seems to be a problem
85
+ # and a topic for the future refactor.
86
+
73
87
  end # class << self
74
88
 
75
89
  # Parametrize the Place / Transition / Net classes.
data/y_nelson.gemspec CHANGED
@@ -8,12 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.version = YNelson::VERSION
9
9
  spec.authors = ["boris"]
10
10
  spec.email = ["\"boris@iis.sinica.edu.tw\""]
11
- spec.description = %q{Formalization and generalization of a spreadsheet.}
12
11
  spec.summary = %q{A fusion of functional Petri net with a zz structure.}
12
+ spec.description = %q{Formalization and generalization of a spreadsheet.}
13
13
  spec.homepage = ""
14
14
  spec.license = "GPLv3"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'yzz'
22
22
  spec.add_dependency 'y_petri'
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
25
  spec.add_development_dependency "rake"
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_nelson
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-21 00:00:00.000000000 Z
11
+ date: 2014-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yzz
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '1.6'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -75,17 +75,15 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
77
  - Gemfile
78
+ - Introduction_to_Ruby_for_YNelson_Users.lyx
79
+ - Introduction_to_Ruby_for_YNelson_Users.pdf
78
80
  - Introduction_to_YNelson.lyx
81
+ - Introduction_to_YNelson.pdf
79
82
  - LICENSE.txt
83
+ - Object_model_of_YNelson_and_YPetri.lyx
84
+ - Object_model_of_YNelson_and_YPetri.pdf
80
85
  - README.md
81
86
  - Rakefile
82
- - Ruby_for_YNelson_Users_in_20_minutes.lyx
83
- - Ruby_for_YNelson_Users_in_20_minutes.pdf
84
- - YNelson_&_YPetri_User_Manual.lyx
85
- - YNelson_&_YPetri_User_Manual.pdf
86
- - YNelson_-_Hands-on_Tutorial.lyx
87
- - YNelson_-_Hands-on_Tutorial.pdf
88
- - config/mongoid.yml
89
87
  - lib/y_nelson.rb
90
88
  - lib/y_nelson/agent.rb
91
89
  - lib/y_nelson/dimension.rb
@@ -96,11 +94,9 @@ files:
96
94
  - lib/y_nelson/transition.rb
97
95
  - lib/y_nelson/version.rb
98
96
  - lib/y_nelson/yzz.rb
99
- - lib/y_nelson/zz.png
100
97
  - lib/y_nelson/zz_point.rb
101
98
  - test/mongoid_example.rb
102
99
  - test/y_nelson_test.rb
103
- - test/zz.png
104
100
  - y_nelson.gemspec
105
101
  homepage: ''
106
102
  licenses:
@@ -122,11 +118,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
118
  version: '0'
123
119
  requirements: []
124
120
  rubyforge_project:
125
- rubygems_version: 2.0.3
121
+ rubygems_version: 2.0.14
126
122
  signing_key:
127
123
  specification_version: 4
128
124
  summary: A fusion of functional Petri net with a zz structure.
129
125
  test_files:
130
126
  - test/mongoid_example.rb
131
127
  - test/y_nelson_test.rb
132
- - test/zz.png