y_petri 2.2.4 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +675 -0
  3. data/README.md +6 -3
  4. data/Rakefile +1 -1
  5. data/lib/y_petri/agent/{petri_net_related.rb → petri_net_aspect.rb} +34 -10
  6. data/lib/y_petri/agent/{simulation_related.rb → simulation_aspect.rb} +49 -34
  7. data/lib/y_petri/agent.rb +5 -5
  8. data/lib/y_petri/core/guarded.rb +24 -0
  9. data/lib/y_petri/core/timed/euler.rb +4 -8
  10. data/lib/y_petri/core/timed/gillespie.rb +11 -17
  11. data/lib/y_petri/core/timed/methods.rb +23 -0
  12. data/lib/y_petri/core/timed/pseudo_euler.rb +10 -13
  13. data/lib/y_petri/core/timed/quasi_euler.rb +9 -8
  14. data/lib/y_petri/core/timed/runge_kutta.rb +10 -18
  15. data/lib/y_petri/core/timed.rb +6 -14
  16. data/lib/y_petri/core/timeless/methods.rb +15 -0
  17. data/lib/y_petri/core/timeless/pseudo_euler.rb +4 -8
  18. data/lib/y_petri/core/timeless.rb +9 -4
  19. data/lib/y_petri/core.rb +44 -42
  20. data/lib/y_petri/net/data_set.rb +246 -142
  21. data/lib/y_petri/net/node_access.rb +282 -0
  22. data/lib/y_petri/net/own_state.rb +14 -4
  23. data/lib/y_petri/net/state/feature/assignment.rb +123 -0
  24. data/lib/y_petri/net/state/feature/delta.rb +55 -35
  25. data/lib/y_petri/net/state/feature/firing.rb +68 -25
  26. data/lib/y_petri/net/state/feature/flux.rb +9 -2
  27. data/lib/y_petri/net/state/feature/gradient.rb +36 -19
  28. data/lib/y_petri/net/state/feature/marking.rb +10 -5
  29. data/lib/y_petri/net/state/feature.rb +105 -11
  30. data/lib/y_petri/net/state/features/record.rb +144 -99
  31. data/lib/y_petri/net/state/features.rb +327 -200
  32. data/lib/y_petri/net/state.rb +48 -82
  33. data/lib/y_petri/net/visualization.rb +1 -1
  34. data/lib/y_petri/net.rb +62 -47
  35. data/lib/y_petri/place/arcs.rb +44 -0
  36. data/lib/y_petri/place/features.rb +115 -0
  37. data/lib/y_petri/place.rb +62 -29
  38. data/lib/y_petri/simulation/dependency.rb +31 -67
  39. data/lib/y_petri/simulation/feature_set.rb +1 -1
  40. data/lib/y_petri/simulation/initial_marking/access.rb +42 -26
  41. data/lib/y_petri/simulation/marking_clamps/access.rb +22 -17
  42. data/lib/y_petri/simulation/marking_clamps.rb +0 -2
  43. data/lib/y_petri/simulation/marking_vector/access.rb +102 -40
  44. data/lib/y_petri/simulation/marking_vector.rb +35 -37
  45. data/lib/y_petri/simulation/matrix.rb +1 -1
  46. data/lib/y_petri/simulation/node_representation.rb +25 -0
  47. data/lib/y_petri/simulation/nodes/access.rb +78 -0
  48. data/lib/y_petri/simulation/{elements.rb → nodes.rb} +14 -13
  49. data/lib/y_petri/simulation/place_mapping.rb +2 -2
  50. data/lib/y_petri/simulation/place_representation.rb +8 -7
  51. data/lib/y_petri/simulation/places/access.rb +89 -70
  52. data/lib/y_petri/simulation/places/free.rb +1 -1
  53. data/lib/y_petri/simulation/places/types.rb +20 -22
  54. data/lib/y_petri/simulation/places.rb +23 -18
  55. data/lib/y_petri/simulation/recorder.rb +23 -18
  56. data/lib/y_petri/simulation/timed/recorder.rb +19 -11
  57. data/lib/y_petri/simulation/timed.rb +93 -29
  58. data/lib/y_petri/simulation/timeless/recorder.rb +11 -6
  59. data/lib/y_petri/simulation/timeless.rb +13 -3
  60. data/lib/y_petri/simulation/transition_representation/A.rb +24 -4
  61. data/lib/y_petri/simulation/transition_representation/S.rb +11 -1
  62. data/lib/y_petri/simulation/transition_representation/T.rb +1 -1
  63. data/lib/y_petri/simulation/transition_representation/Ts.rb +1 -1
  64. data/lib/y_petri/simulation/transition_representation/a.rb +1 -1
  65. data/lib/y_petri/simulation/transition_representation/s.rb +12 -1
  66. data/lib/y_petri/simulation/transition_representation/t.rb +1 -1
  67. data/lib/y_petri/simulation/transition_representation/tS.rb +1 -1
  68. data/lib/y_petri/simulation/transition_representation/ts.rb +1 -1
  69. data/lib/y_petri/simulation/transition_representation/types.rb +1 -1
  70. data/lib/y_petri/simulation/transition_representation.rb +4 -11
  71. data/lib/y_petri/simulation/transitions/A.rb +17 -2
  72. data/lib/y_petri/simulation/transitions/S.rb +1 -1
  73. data/lib/y_petri/simulation/transitions/T.rb +1 -1
  74. data/lib/y_petri/simulation/transitions/Ts.rb +6 -5
  75. data/lib/y_petri/simulation/transitions/a.rb +1 -1
  76. data/lib/y_petri/simulation/transitions/access.rb +195 -168
  77. data/lib/y_petri/simulation/transitions/s.rb +1 -1
  78. data/lib/y_petri/simulation/transitions/t.rb +1 -1
  79. data/lib/y_petri/simulation/transitions/tS.rb +1 -1
  80. data/lib/y_petri/simulation/transitions/ts.rb +1 -1
  81. data/lib/y_petri/simulation/transitions/types.rb +1 -1
  82. data/lib/y_petri/simulation/transitions.rb +5 -7
  83. data/lib/y_petri/simulation.rb +84 -90
  84. data/lib/y_petri/transition/A.rb +8 -2
  85. data/lib/y_petri/transition/T.rb +25 -2
  86. data/lib/y_petri/transition/arcs.rb +19 -3
  87. data/lib/y_petri/transition/construction_convenience.rb +11 -10
  88. data/lib/y_petri/transition/t.rb +14 -1
  89. data/lib/y_petri/transition/types.rb +6 -1
  90. data/lib/y_petri/transition.rb +9 -12
  91. data/lib/y_petri/version.rb +1 -1
  92. data/lib/y_petri/world/dependency.rb +3 -3
  93. data/lib/y_petri/world/{petri_net_related.rb → petri_net_aspect.rb} +4 -4
  94. data/lib/y_petri/world/simulation_aspect.rb +352 -0
  95. data/lib/y_petri/world.rb +4 -4
  96. data/lib/y_petri.rb +1 -1
  97. data/test/agent_test.rb +2 -1
  98. data/test/examples/demonstrator.rb +4 -1
  99. data/test/examples/demonstrator_2.rb +5 -0
  100. data/test/examples/demonstrator_4.rb +6 -5
  101. data/test/examples/example_2.rb +2 -0
  102. data/test/examples/manual_examples.rb +4 -4
  103. data/test/net_test.rb +457 -54
  104. data/test/place_test.rb +11 -7
  105. data/test/simulation_test.rb +358 -331
  106. data/test/transition_test.rb +11 -10
  107. data/test/world_test.rb +2 -0
  108. data/test/y_petri_test.rb +2 -1
  109. data/y_petri.gemspec +24 -18
  110. metadata +71 -17
  111. data/LICENSE +0 -22
  112. data/lib/y_petri/net/element_access.rb +0 -239
  113. data/lib/y_petri/simulation/element_representation.rb +0 -20
  114. data/lib/y_petri/simulation/elements/access.rb +0 -57
  115. data/lib/y_petri/transition/type.rb +0 -103
  116. data/lib/y_petri/transition/type_information.rb +0 -103
  117. data/lib/y_petri/world/simulation_related.rb +0 -176
@@ -1,6 +1,7 @@
1
1
  #! /usr/bin/ruby
2
2
  # encoding: utf-8
3
3
 
4
+ gem 'minitest'
4
5
  require 'minitest/autorun'
5
6
  require 'y_support/typing'
6
7
 
@@ -63,13 +64,13 @@ describe ::YPetri::Transition do
63
64
  assert [@t1, @t2, @t3].all? { |t| t.s? }
64
65
  # Now let's flex them:
65
66
  @t1.fire!
66
- [@p1.m, @p3.m].must_equal [3, 5]
67
+ [ @p1.marking, @p3.marking ].must_equal [3, 5]
67
68
  @t3.fire!
68
- [@p1.m, @p3.m].must_equal [3.5, 5.5]
69
+ [ @p1.marking, @p3.marking ].must_equal [3.5, 5.5]
69
70
  @t2.fire!
70
- [@p1.m, @p3.m].must_equal [7.0, 9.0]
71
- @t1.codomain_marking.must_equal [@p1.m, @p3.m]
72
- @t1.domain_marking.must_equal [@p2.m]
71
+ [ @p1.marking, @p3.marking ].must_equal [7.0, 9.0]
72
+ @t1.codomain_marking.must_equal [ @p1.marking, @p3.marking ]
73
+ @t1.domain_marking.must_equal [@p2.marking ]
73
74
  @t1.zero_action.must_equal [0, 0]
74
75
  end
75
76
  end
@@ -97,11 +98,11 @@ describe ::YPetri::Transition do
97
98
  @t2.s.must_equal( { @p5.object_id => -1, @p1.object_id => 1 } )
98
99
  @t1.domain.must_equal [@p5] # inferred domain
99
100
  @t2.domain.must_equal [] # domain is empty in functionless transitions!
100
- [@p1.m, @p5.m].must_equal [1, 5]
101
+ [ @p1.marking, @p5.marking ].must_equal [1, 5]
101
102
  @t1.fire!
102
- [@p1.m, @p5.m].must_equal [2, 4]
103
+ [ @p1.marking, @p5.marking ].must_equal [2, 4]
103
104
  @t2.fire!
104
- [@p1.m, @p5.m].must_equal [3, 3]
105
+ [ @p1.marking, @p5.marking ].must_equal [3, 3]
105
106
  end
106
107
  end
107
108
 
@@ -117,10 +118,10 @@ describe ::YPetri::Transition do
117
118
  assert @t1.functional?
118
119
  assert @t1.timed?
119
120
  @t1.domain.must_equal [@p5]
120
- [@p1.m, @p5.m].must_equal [1, 5]
121
+ [ @p1.marking, @p5.marking ].must_equal [1, 5]
121
122
  @t1.rate_closure.arity.must_equal 0
122
123
  @t1.fire! 0.5
123
- [@p1.m, @p5.m].must_equal [1.5, 4.5]
124
+ [ @p1.marking, @p5.marking ].must_equal [1.5, 4.5]
124
125
  end
125
126
  end
126
127
 
data/test/world_test.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #! /usr/bin/ruby
2
2
  # encoding: utf-8
3
3
 
4
+ gem 'minitest'
4
5
  require 'minitest/autorun'
5
6
  require_relative '../lib/y_petri' # tested component itself
6
7
  # require 'y_petri'
@@ -62,6 +63,7 @@ describe YPetri::World do
62
63
  @w.simulation.run!
63
64
  rec_csv = @w.simulation.recording.to_csv
64
65
  expected_rec_csv =
66
+ ":event,:AA,:BB,:CC\n" +
65
67
  "0.0,1.0,2.0,3.0\n" +
66
68
  "10.0,0.86102,0.86102,4.13898\n" +
67
69
  "20.0,1.29984,0.29984,4.70016\n"
data/test/y_petri_test.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #! /usr/bin/ruby
2
- # encoding: utf-8
2
+ #encoding: utf-8
3
3
 
4
+ gem 'minitest'
4
5
  require 'minitest/autorun'
5
6
  require_relative '../lib/y_petri' # tested component itself
6
7
  # require 'y_petri'
data/y_petri.gemspec CHANGED
@@ -1,21 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/y_petri/version', __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'y_petri/version'
3
5
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["boris"]
6
- gem.email = ["\"boris@iis.sinica.edu.tw\""]
7
- gem.description = %q{a Petri net domain model and simulator}
8
- gem.summary = %q{a Petri net domain model and simulator}
9
- gem.homepage = ""
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "y_petri"
8
+ spec.version = YPetri::VERSION
9
+ spec.authors = ["boris"]
10
+ spec.email = ["\"boris@iis.sinica.edu.tw\""]
11
+ spec.summary = %q{Systems modelling and simulation gem, and a domain model of a special kind of Petri nets (YPetri nets) that can be used to model and simulate any kind of dynamic systems.}
12
+ spec.description = %q{YPetri is a gem for modelling and simulation of dynamic systems. Wiring diagram of a dynamic system to be modelled is expressed as YPetri net, a specific kind of Petri net that unifies discrete/continous, deterministic/stochastic, timed/timeless and stoichiometric/nonstoichiometric dichotomies, thus enabling modelling and simulation of dynamic systems of any kind whatsoever. Like Petri nets themselves, YPetri was inspired by problems from the domain of chemistry, but its use is not limited to it.}
13
+ spec.homepage = ""
14
+ spec.license = "GPLv3"
10
15
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "y_petri"
15
- gem.require_paths = ["lib"]
16
- gem.version = YPetri::VERSION
17
-
18
- gem.add_dependency "y_support"
19
- gem.add_dependency "gnuplot"
20
- gem.add_dependency "ruby-graphviz"
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "y_support"
24
+ spec.add_dependency "gnuplot"
25
+ spec.add_dependency "ruby-graphviz"
26
+ spec.add_dependency "distribution"
21
27
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_petri
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.4
4
+ version: 2.3.2
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-22 00:00:00.000000000 Z
11
+ date: 2014-04-23 00:00:00.000000000 Z
12
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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: y_support
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +80,27 @@ dependencies:
52
80
  - - '>='
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
- description: a Petri net domain model and simulator
83
+ - !ruby/object:Gem::Dependency
84
+ name: distribution
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: YPetri is a gem for modelling and simulation of dynamic systems. Wiring
98
+ diagram of a dynamic system to be modelled is expressed as YPetri net, a specific
99
+ kind of Petri net that unifies discrete/continous, deterministic/stochastic, timed/timeless
100
+ and stoichiometric/nonstoichiometric dichotomies, thus enabling modelling and simulation
101
+ of dynamic systems of any kind whatsoever. Like Petri nets themselves, YPetri was
102
+ inspired by problems from the domain of chemistry, but its use is not limited to
103
+ it.
56
104
  email:
57
105
  - '"boris@iis.sinica.edu.tw"'
58
106
  executables: []
@@ -61,32 +109,36 @@ extra_rdoc_files: []
61
109
  files:
62
110
  - .gitignore
63
111
  - Gemfile
64
- - LICENSE
112
+ - LICENSE.txt
65
113
  - README.md
66
114
  - Rakefile
67
115
  - lib/y_petri.rb
68
116
  - lib/y_petri/agent.rb
69
117
  - lib/y_petri/agent/hash_key_pointer.rb
70
- - lib/y_petri/agent/petri_net_related.rb
118
+ - lib/y_petri/agent/petri_net_aspect.rb
71
119
  - lib/y_petri/agent/selection.rb
72
- - lib/y_petri/agent/simulation_related.rb
120
+ - lib/y_petri/agent/simulation_aspect.rb
73
121
  - lib/y_petri/core.rb
122
+ - lib/y_petri/core/guarded.rb
74
123
  - lib/y_petri/core/timed.rb
75
124
  - lib/y_petri/core/timed/euler.rb
76
125
  - lib/y_petri/core/timed/gillespie.rb
126
+ - lib/y_petri/core/timed/methods.rb
77
127
  - lib/y_petri/core/timed/pseudo_euler.rb
78
128
  - lib/y_petri/core/timed/quasi_euler.rb
79
129
  - lib/y_petri/core/timed/runge_kutta.rb
80
130
  - lib/y_petri/core/timeless.rb
131
+ - lib/y_petri/core/timeless/methods.rb
81
132
  - lib/y_petri/core/timeless/pseudo_euler.rb
82
133
  - lib/y_petri/dsl.rb
83
134
  - lib/y_petri/fixed_assets.rb
84
135
  - lib/y_petri/net.rb
85
136
  - lib/y_petri/net/data_set.rb
86
- - lib/y_petri/net/element_access.rb
137
+ - lib/y_petri/net/node_access.rb
87
138
  - lib/y_petri/net/own_state.rb
88
139
  - lib/y_petri/net/state.rb
89
140
  - lib/y_petri/net/state/feature.rb
141
+ - lib/y_petri/net/state/feature/assignment.rb
90
142
  - lib/y_petri/net/state/feature/delta.rb
91
143
  - lib/y_petri/net/state/feature/firing.rb
92
144
  - lib/y_petri/net/state/feature/flux.rb
@@ -98,13 +150,11 @@ files:
98
150
  - lib/y_petri/net/visualization.rb
99
151
  - lib/y_petri/place.rb
100
152
  - lib/y_petri/place/arcs.rb
153
+ - lib/y_petri/place/features.rb
101
154
  - lib/y_petri/place/guard.rb
102
155
  - lib/y_petri/place/guarded.rb
103
156
  - lib/y_petri/simulation.rb
104
157
  - lib/y_petri/simulation/dependency.rb
105
- - lib/y_petri/simulation/element_representation.rb
106
- - lib/y_petri/simulation/elements.rb
107
- - lib/y_petri/simulation/elements/access.rb
108
158
  - lib/y_petri/simulation/feature_set.rb
109
159
  - lib/y_petri/simulation/initial_marking.rb
110
160
  - lib/y_petri/simulation/initial_marking/access.rb
@@ -113,6 +163,9 @@ files:
113
163
  - lib/y_petri/simulation/marking_vector.rb
114
164
  - lib/y_petri/simulation/marking_vector/access.rb
115
165
  - lib/y_petri/simulation/matrix.rb
166
+ - lib/y_petri/simulation/node_representation.rb
167
+ - lib/y_petri/simulation/nodes.rb
168
+ - lib/y_petri/simulation/nodes/access.rb
116
169
  - lib/y_petri/simulation/place_mapping.rb
117
170
  - lib/y_petri/simulation/place_representation.rb
118
171
  - lib/y_petri/simulation/places.rb
@@ -157,15 +210,13 @@ files:
157
210
  - lib/y_petri/transition/cocking.rb
158
211
  - lib/y_petri/transition/construction_convenience.rb
159
212
  - lib/y_petri/transition/t.rb
160
- - lib/y_petri/transition/type.rb
161
- - lib/y_petri/transition/type_information.rb
162
213
  - lib/y_petri/transition/types.rb
163
214
  - lib/y_petri/transition/usable_without_world.rb
164
215
  - lib/y_petri/version.rb
165
216
  - lib/y_petri/world.rb
166
217
  - lib/y_petri/world/dependency.rb
167
- - lib/y_petri/world/petri_net_related.rb
168
- - lib/y_petri/world/simulation_related.rb
218
+ - lib/y_petri/world/petri_net_aspect.rb
219
+ - lib/y_petri/world/simulation_aspect.rb
169
220
  - test/acceptance/basic_usage_test.rb
170
221
  - test/acceptance/simulation_test.rb
171
222
  - test/acceptance/simulation_with_physical_units_test.rb
@@ -189,7 +240,8 @@ files:
189
240
  - test/y_petri_test.rb
190
241
  - y_petri.gemspec
191
242
  homepage: ''
192
- licenses: []
243
+ licenses:
244
+ - GPLv3
193
245
  metadata: {}
194
246
  post_install_message:
195
247
  rdoc_options: []
@@ -207,10 +259,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
259
  version: '0'
208
260
  requirements: []
209
261
  rubyforge_project:
210
- rubygems_version: 2.0.3
262
+ rubygems_version: 2.0.14
211
263
  signing_key:
212
264
  specification_version: 4
213
- summary: a Petri net domain model and simulator
265
+ summary: Systems modelling and simulation gem, and a domain model of a special kind
266
+ of Petri nets (YPetri nets) that can be used to model and simulate any kind of dynamic
267
+ systems.
214
268
  test_files:
215
269
  - test/acceptance/basic_usage_test.rb
216
270
  - test/acceptance/simulation_test.rb
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 boris
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,239 +0,0 @@
1
- # Selections of various kinds of places / transitions (place names / transition
2
- # names) in a Petri net.
3
- #
4
- module YPetri::Net::ElementAccess
5
- # Does the net include a place?
6
- #
7
- def includes_place? id
8
- begin
9
- place( id ) and true
10
- rescue NameError, TypeError; false end
11
- end
12
- alias include_place? includes_place?
13
-
14
- # Does the net include a transition?
15
- #
16
- def includes_transition? id
17
- begin; transition( id ) and true; rescue NameError, TypeError; false end
18
- end
19
- alias include_transition? includes_transition?
20
-
21
- # Inquirer whether the net includes an element.
22
- #
23
- def include? id
24
- include_place?( id ) || include_transition?( id )
25
- end
26
- alias includes? include?
27
-
28
- # Returns the net's place identified by the argument.
29
- #
30
- def place id
31
- ( super rescue Place().instance( id ) ).tap do |p|
32
- fail TypeError, "No place #{id} in the net!" unless places.include? p
33
- end
34
- end
35
-
36
- # Returns the net's transition identified by the argument.
37
- #
38
- def transition id
39
- ( super rescue Transition().instance( id ) ).tap do |t|
40
- transitions.include? t or fail TypeError, "No transition #{id} in the net!"
41
- end
42
- end
43
-
44
- # Returns the net's element identified by the argument
45
- #
46
- def element id
47
- begin; place( id ); rescue NameError, TypeError
48
- begin; transition( id ); rescue NameError, TypeError
49
- raise TypeError, "The net does not include place/transition #{id}!"
50
- end
51
- end
52
- end
53
-
54
- # Returns the net's elements identified by the argument's elements.
55
- #
56
- def elements ids=nil
57
- return @places + @transitions if ids.nil?
58
- ids.map { |id| element id }
59
- end
60
-
61
- # Returns the names of the net's elements identified by the array.
62
- #
63
- def en ids=nil
64
- elements( ids ).names
65
- end
66
-
67
- # Returns the net's places identified by the argument's elements.
68
- #
69
- def places ids=nil
70
- return @places.dup if ids.nil?
71
- ids.map { |id| place id }
72
- end
73
- alias pp places
74
-
75
- # Returns the net's transitions identified by the argument's elements.
76
- #
77
- def transitions ids=nil
78
- return @transitions.dup if ids.nil?
79
- ids.map { |id| transition id }
80
- end
81
- alias tt transitions
82
-
83
- # Names of places in the net.
84
- #
85
- def pn ids=nil
86
- places( ids ).names
87
- end
88
-
89
- # Names of transitions in the net.
90
- #
91
- def tn ids=nil
92
- transitions( ids ).names
93
- end
94
-
95
- # *ts* transitions.
96
- #
97
- def ts_transitions ids=nil
98
- return transitions.select &:ts? if ids.nil?
99
- transitions( ids ).aT_all "transition identifiers", "be ts", &:ts?
100
- end
101
- alias ts_tt ts_transitions
102
-
103
- # Names of *ts* transitions.
104
- #
105
- def nts ids=nil
106
- ts_transitions( ids ).names
107
- end
108
-
109
- # *tS* transitions.
110
- #
111
- def tS_transitions ids=nil
112
- return transitions.select &:tS? if ids.nil?
113
- transitions( ids ).aT_all "transition identifiers", "be tS", &:tS?
114
- end
115
- alias tS_tt tS_transitions
116
-
117
- # Names of *tS* transitions.
118
- #
119
- def ntS ids=nil
120
- tS_transitions( ids ).names
121
- end
122
-
123
- # *Ts* transitions.
124
- #
125
- def Ts_transitions ids=nil
126
- return transitions.select &:Ts? if ids.nil?
127
- transitions( ids ).aT_all "transition identifiers", "be Ts", &:Ts?
128
- end
129
- alias Ts_tt Ts_transitions
130
-
131
- # Names of *Ts* transitions.
132
- #
133
- def nTs ids=nil
134
- Ts_transitions( ids ).names
135
- end
136
-
137
- # *TS* transitions.
138
- #
139
- def TS_transitions ids=nil
140
- return transitions.select &:TS? if ids.nil?
141
- transitions( ids ).aT_all "transition identifiers", "be TS", &:TS?
142
- end
143
- alias TS_tt TS_transitions
144
-
145
- # Names of *TS* transitions.
146
- #
147
- def nTS ids=nil
148
- TS_transitions( ids ).names
149
- end
150
-
151
- # *A* transitions.
152
- #
153
- def A_transitions ids=nil
154
- return transitions.select &:A? if ids.nil?
155
- transitions( ids ).aT_all "transition identifiers", "be A", &:A?
156
- end
157
- alias A_tt A_transitions
158
-
159
- # Names of *A* transitions.
160
- #
161
- def nA ids=nil
162
- A_transitions( ids ).names
163
- end
164
-
165
- # *a* transitions.
166
- #
167
- def a_transitions ids=nil
168
- return transitions.select &:a? if ids.nil?
169
- transitions( ids ).aT_all "transition identifiers",
170
- "be a (non-assignment)", &:a?
171
- end
172
- alias a_tt a_transitions
173
-
174
- # Names of *a* transitions.
175
- #
176
- def na ids=nil
177
- A_transitions( ids ).names
178
- end
179
-
180
- # *S* transitions.
181
- #
182
- def S_transitions ids=nil
183
- return transitions.select &:S? if ids.nil?
184
- transitions( ids ).aT_all "transition identifiers",
185
- "be S (stoichiometric)", &:S?
186
- end
187
- alias S_tt S_transitions
188
-
189
- # Names of *S* transitions.
190
- #
191
- def nS ids=nil
192
- S_transitions( ids ).names
193
- end
194
-
195
- # *s* transitions.
196
- #
197
- def s_transitions ids=nil
198
- return transitions.select &:s? if ids.nil?
199
- transitions( ids ).aT_all "transition identifiers",
200
- "be s (non-stoichiometric)", &:s?
201
- end
202
- alias s_tt s_transitions
203
-
204
- # Names of *s* transitions.
205
- #
206
- def ns ids=nil
207
- s_transitions( ids ).names
208
- end
209
-
210
- # *T* transitions.
211
- #
212
- def T_transitions ids=nil
213
- return transitions.select &:T? if ids.nil?
214
- transitions( ids ).aT_all "transition identifiers",
215
- "be T (timed)", &:T?
216
- end
217
- alias T_tt T_transitions
218
-
219
- # Names of *T* transitions.
220
- #
221
- def nT ids=nil
222
- T_transitions( ids ).names
223
- end
224
-
225
- # *t* transitions.
226
- #
227
- def t_transitions ids=nil
228
- return transitions.select &:t? if ids.nil?
229
- transitions( ids ).aT_all "transition identifiers",
230
- "be t (timeless)", &:t?
231
- end
232
- alias t_tt t_transitions
233
-
234
- # Names of *t* transitions.
235
- #
236
- def nt ids=nil
237
- t_transitions( ids ).names
238
- end
239
- end # class YPetri::Net::ElementAccess
@@ -1,20 +0,0 @@
1
- #encoding: utf-8
2
-
3
- # Representation of a YPetri::Place inside a YPetri::Simulation instance.
4
- #
5
- class YPetri::Simulation
6
- class ElementRepresentation
7
- ★ NameMagic
8
- ★ Dependency
9
-
10
- attr_reader :source # source place
11
-
12
- delegate :simulation, to: "self.class"
13
-
14
- # Expect a single YPetri place as an argument.
15
- #
16
- def initialize net_element_id
17
- @source = net.element( net_element_id )
18
- end
19
- end # class ElementRepresentation
20
- end # class YPetri::Simulation
@@ -1,57 +0,0 @@
1
- #encoding: utf-8
2
-
3
- # Simulation mixin providing access to elements (an element is either a
4
- # place, or a transition -- see also mixins +Places::Access+ and
5
- # +Transitions::Access+.
6
- #
7
- class YPetri::Simulation::Elements
8
- module Access
9
- # Does an element belong to the simulation?
10
- #
11
- def includes?( id )
12
- includes_place?( id ) || includes_transition?( id )
13
- end
14
- alias include? includes?
15
-
16
- # Element of the simulation (belonging to the net).
17
- #
18
- def e( id )
19
- element( id ).source
20
- end
21
-
22
- # Elements of the simulation (belonging to the net).
23
- #
24
- def ee( ids=nil )
25
- elements( ids ).map &:source
26
- end
27
-
28
- # Names of the simulation's elements. Arguments, if any, are treated
29
- # analogically to the +#elements+ method.
30
- #
31
- def en ids=nil
32
- elements( ids ).names
33
- end
34
-
35
- protected
36
-
37
- # Element instance identification.
38
- #
39
- def element( id )
40
- if include_place? id
41
- return place( id )
42
- end
43
- if include_transition? id
44
- return transition( id )
45
- end
46
- fail TypeError, "No element #{id} in the simulation!"
47
- end
48
-
49
- # Without arguments, returns all the elements (places + transitions). If
50
- # arguments are given, they are converted into elements.
51
- #
52
- def elements ids=nil
53
- return places + transitions if ids.nil?
54
- ids.map { |id| element id }
55
- end
56
- end # module Access
57
- end # class YPetri::Simulation::Elements