pione 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (304) hide show
  1. data/.gitignore +2 -0
  2. data/.s3cfg +42 -0
  3. data/.travis.yml +18 -4
  4. data/.yardopts +1 -0
  5. data/Gemfile +3 -0
  6. data/History.txt +14 -0
  7. data/Procfile +7 -0
  8. data/Rakefile +25 -0
  9. data/bin/pione-interactive +6 -0
  10. data/bin/{pione-compiler → pione-notification-listener} +1 -1
  11. data/bin/{pione-broker → pione-task-worker-broker} +1 -1
  12. data/doc/man/pione-list-param.md +36 -0
  13. data/example/ActionError/ActionError.pione +9 -0
  14. data/example/ActionError/pione-package.json +15 -0
  15. data/example/CountChar/CountChar.pione +1 -1
  16. data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
  17. data/example/Touch/pione-package.json +15 -0
  18. data/lib/pione.rb +12 -0
  19. data/lib/pione/agent.rb +3 -3
  20. data/lib/pione/agent/basic-agent.rb +10 -4
  21. data/lib/pione/agent/input-generator.rb +3 -3
  22. data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
  23. data/lib/pione/agent/job-terminator.rb +2 -2
  24. data/lib/pione/agent/logger.rb +3 -3
  25. data/lib/pione/agent/messenger.rb +20 -9
  26. data/lib/pione/agent/notification-listener.rb +88 -0
  27. data/lib/pione/agent/task-worker-broker.rb +84 -0
  28. data/lib/pione/agent/task-worker.rb +3 -2
  29. data/lib/pione/agent/tuple-space-client.rb +1 -0
  30. data/lib/pione/agent/tuple-space-provider.rb +17 -35
  31. data/lib/pione/command.rb +33 -15
  32. data/lib/pione/command/action.rb +105 -0
  33. data/lib/pione/command/basic-command.rb +34 -376
  34. data/lib/pione/command/command-exception.rb +12 -11
  35. data/lib/pione/command/common.rb +198 -0
  36. data/lib/pione/command/option.rb +159 -204
  37. data/lib/pione/command/pione-action-exec.rb +85 -0
  38. data/lib/pione/command/pione-action-list.rb +43 -19
  39. data/lib/pione/command/pione-action-print.rb +79 -0
  40. data/lib/pione/command/pione-action.rb +8 -67
  41. data/lib/pione/command/pione-clean.rb +88 -68
  42. data/lib/pione/command/pione-client.rb +475 -332
  43. data/lib/pione/command/pione-command.rb +14 -31
  44. data/lib/pione/command/pione-compile.rb +90 -0
  45. data/lib/pione/command/pione-config-get.rb +53 -0
  46. data/lib/pione/command/pione-config-list.rb +64 -0
  47. data/lib/pione/command/pione-config-set.rb +59 -0
  48. data/lib/pione/command/pione-config-unset.rb +50 -0
  49. data/lib/pione/command/pione-config.rb +61 -0
  50. data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
  51. data/lib/pione/command/pione-diagnosis.rb +21 -0
  52. data/lib/pione/command/pione-interactive.rb +188 -0
  53. data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
  54. data/lib/pione/command/pione-lang-interactive.rb +146 -0
  55. data/lib/pione/command/pione-lang.rb +22 -0
  56. data/lib/pione/command/pione-log-format.rb +163 -0
  57. data/lib/pione/command/pione-log-list-id.rb +48 -0
  58. data/lib/pione/command/pione-log.rb +19 -101
  59. data/lib/pione/command/pione-notification-listener.rb +95 -0
  60. data/lib/pione/command/pione-package-add.rb +137 -0
  61. data/lib/pione/command/pione-package-build.rb +122 -0
  62. data/lib/pione/command/pione-package-show.rb +96 -0
  63. data/lib/pione/command/pione-package-update.rb +59 -0
  64. data/lib/pione/command/pione-package.rb +11 -139
  65. data/lib/pione/command/pione-task-worker-broker.rb +88 -0
  66. data/lib/pione/command/pione-task-worker.rb +148 -98
  67. data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
  68. data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
  69. data/lib/pione/command/pione-val.rb +39 -39
  70. data/lib/pione/command/spawner.rb +34 -27
  71. data/lib/pione/front.rb +4 -2
  72. data/lib/pione/front/basic-front.rb +86 -23
  73. data/lib/pione/front/client-front.rb +2 -2
  74. data/lib/pione/front/diagnosis-notification-front.rb +40 -0
  75. data/lib/pione/front/front-exception.rb +7 -1
  76. data/lib/pione/front/notification-listener-front.rb +36 -0
  77. data/lib/pione/front/notification-recipient-interface.rb +19 -0
  78. data/lib/pione/front/relay-front.rb +4 -4
  79. data/lib/pione/front/task-worker-broker-front.rb +19 -0
  80. data/lib/pione/front/task-worker-front.rb +2 -2
  81. data/lib/pione/front/tuple-space-provider-front.rb +3 -2
  82. data/lib/pione/global.rb +3 -1
  83. data/lib/pione/global/client-variable.rb +1 -1
  84. data/lib/pione/global/config.rb +63 -7
  85. data/lib/pione/global/diagnosis-variable.rb +26 -0
  86. data/lib/pione/global/item.rb +28 -5
  87. data/lib/pione/global/log-variable.rb +6 -5
  88. data/lib/pione/global/network-variable.rb +75 -4
  89. data/lib/pione/global/path-variable.rb +1 -1
  90. data/lib/pione/global/system-variable.rb +12 -12
  91. data/lib/pione/global/task-worker-broker-variable.rb +43 -0
  92. data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
  93. data/lib/pione/lang/boolean.rb +4 -0
  94. data/lib/pione/lang/data-expr.rb +1 -1
  95. data/lib/pione/lang/integer.rb +1 -1
  96. data/lib/pione/lang/string.rb +4 -0
  97. data/lib/pione/lang/type.rb +1 -1
  98. data/lib/pione/location.rb +1 -0
  99. data/lib/pione/location/data-location.rb +41 -13
  100. data/lib/pione/location/dropbox-location.rb +175 -56
  101. data/lib/pione/location/ftp-location.rb +4 -1
  102. data/lib/pione/location/http-location.rb +5 -3
  103. data/lib/pione/location/https-location.rb +4 -2
  104. data/lib/pione/location/local-location.rb +6 -3
  105. data/lib/pione/location/location-exception.rb +12 -0
  106. data/lib/pione/location/notification-scheme.rb +46 -0
  107. data/lib/pione/log.rb +8 -7
  108. data/lib/pione/log/debug.rb +9 -9
  109. data/lib/pione/log/domain-log.rb +6 -1
  110. data/lib/pione/log/message-log-receiver.rb +32 -0
  111. data/lib/pione/log/system-log.rb +62 -141
  112. data/lib/pione/model.rb +7 -0
  113. data/lib/pione/model/notification-listener-model.rb +29 -0
  114. data/lib/pione/model/task-worker-broker-model.rb +129 -0
  115. data/lib/pione/notification.rb +13 -0
  116. data/lib/pione/notification/address.rb +104 -0
  117. data/lib/pione/notification/exception.rb +10 -0
  118. data/lib/pione/notification/message.rb +109 -0
  119. data/lib/pione/notification/receiver.rb +90 -0
  120. data/lib/pione/notification/recipient.rb +68 -0
  121. data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
  122. data/lib/pione/notification/transmitter.rb +84 -0
  123. data/lib/pione/pnml.rb +35 -0
  124. data/lib/pione/pnml/annotation-extractor.rb +47 -0
  125. data/lib/pione/pnml/compiler.rb +176 -0
  126. data/lib/pione/pnml/input-merge-complement.rb +78 -0
  127. data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
  128. data/lib/pione/pnml/input-reduction.rb +80 -0
  129. data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
  130. data/lib/pione/pnml/io-expansion.rb +88 -0
  131. data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
  132. data/lib/pione/pnml/net-rewriter.rb +44 -0
  133. data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
  134. data/lib/pione/pnml/output-reduction.rb +86 -0
  135. data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
  136. data/lib/pione/pnml/pione-model.rb +417 -0
  137. data/lib/pione/pnml/pnml-exception.rb +23 -0
  138. data/lib/pione/pnml/pnml-model.rb +368 -0
  139. data/lib/pione/pnml/reader.rb +51 -0
  140. data/lib/pione/rule-engine/action-handler.rb +8 -6
  141. data/lib/pione/rule-engine/basic-handler.rb +5 -5
  142. data/lib/pione/rule-engine/engine-exception.rb +7 -6
  143. data/lib/pione/rule-engine/flow-handler.rb +27 -18
  144. data/lib/pione/system.rb +3 -1
  145. data/lib/pione/system/domain-dump.rb +34 -0
  146. data/lib/pione/system/file-cache.rb +92 -13
  147. data/lib/pione/system/init.rb +3 -0
  148. data/lib/pione/system/normalizer.rb +40 -0
  149. data/lib/pione/system/status.rb +5 -5
  150. data/lib/pione/system/system-exception.rb +14 -1
  151. data/lib/pione/task-worker-broker.rb +7 -0
  152. data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
  153. data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
  154. data/lib/pione/test-helper.rb +27 -0
  155. data/lib/pione/test-helper/command-helper.rb +9 -101
  156. data/lib/pione/tuple-space/basic-tuple.rb +1 -1
  157. data/lib/pione/tuple-space/tuple-definition.yml +4 -6
  158. data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
  159. data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
  160. data/lib/pione/util.rb +1 -2
  161. data/lib/pione/util/boolean-value.rb +62 -0
  162. data/lib/pione/util/completion.rb +111 -0
  163. data/lib/pione/util/evaluatable.rb +13 -27
  164. data/lib/pione/util/package-parameters-list.rb +15 -27
  165. data/lib/pione/util/zip.rb +8 -3
  166. data/lib/pione/version.rb +1 -1
  167. data/lib/rootage.rb +20 -0
  168. data/lib/rootage/action.rb +114 -0
  169. data/lib/rootage/argument.rb +46 -0
  170. data/lib/rootage/command.rb +218 -0
  171. data/lib/rootage/core.rb +532 -0
  172. data/lib/rootage/exception.rb +107 -0
  173. data/lib/rootage/help.rb +148 -0
  174. data/lib/rootage/help.txt.erb +31 -0
  175. data/lib/rootage/log.rb +226 -0
  176. data/lib/rootage/normalizer.rb +184 -0
  177. data/lib/rootage/option.rb +152 -0
  178. data/lib/rootage/scenario-test-result.erb +39 -0
  179. data/lib/rootage/scenario.rb +362 -0
  180. data/lib/rootage/test-helper.rb +115 -0
  181. data/man/pione-list-param.1 +44 -0
  182. data/misc/clock.rb +9 -0
  183. data/misc/machine-info.sh +21 -0
  184. data/misc/pione-completion.bash +238 -0
  185. data/misc/pione-completion.erb +53 -0
  186. data/misc/pione-completion.zsh +238 -0
  187. data/misc/pione.god +22 -0
  188. data/misc/ui.xml +23 -0
  189. data/pione.gemspec +3 -1
  190. data/test/agent/spec_basic-agent.rb +1 -1
  191. data/test/agent/spec_input-generator.rb +2 -2
  192. data/test/agent/spec_messenger.rb +6 -9
  193. data/test/agent/spec_notification-listener.rb +80 -0
  194. data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
  195. data/test/agent/spec_tuple-space-provider.rb +10 -6
  196. data/test/command/command-behavior.rb +3 -11
  197. data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
  198. data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
  199. data/test/command/spec_pione-action-exec.rb +16 -0
  200. data/test/command/spec_pione-action-list.rb +15 -10
  201. data/test/command/spec_pione-action-print.rb +14 -0
  202. data/test/command/spec_pione-action.rb +6 -19
  203. data/test/command/spec_pione-clean.rb +29 -46
  204. data/test/command/spec_pione-client.rb +29 -36
  205. data/test/command/spec_pione-command.rb +6 -6
  206. data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
  207. data/test/command/spec_pione-config-get.rb +47 -0
  208. data/test/command/spec_pione-config-list.rb +42 -0
  209. data/test/command/spec_pione-config-set.rb +38 -0
  210. data/test/command/spec_pione-config-unset.rb +44 -0
  211. data/test/command/spec_pione-config.rb +11 -0
  212. data/test/command/spec_pione-diagnosis-notification.rb +23 -0
  213. data/test/command/spec_pione-diagnosis.rb +11 -0
  214. data/test/command/spec_pione-lang-check-syntax.rb +12 -0
  215. data/test/command/spec_pione-lang.rb +11 -0
  216. data/test/command/spec_pione-log-format.rb +29 -0
  217. data/test/command/spec_pione-log-list-id.rb +17 -0
  218. data/test/command/spec_pione-log.rb +6 -20
  219. data/test/command/spec_pione-package-add.rb +55 -0
  220. data/test/command/spec_pione-package-build.rb +57 -0
  221. data/test/command/spec_pione-package-show.rb +72 -0
  222. data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
  223. data/test/command/spec_pione-package.rb +4 -104
  224. data/test/command/spec_pione-val.rb +10 -7
  225. data/test/global/spec_config.rb +50 -0
  226. data/test/global/spec_item.rb +1 -1
  227. data/test/literate-action/data/HelloWorld.md +1 -1
  228. data/test/location/location-behavior.rb +1 -1
  229. data/test/location/spec_dropbox-location.rb +39 -0
  230. data/test/location/spec_notification-scheme.rb +37 -0
  231. data/test/log/spec_debug.rb +5 -4
  232. data/test/log/spec_message-log-receiver.rb +13 -0
  233. data/test/log/spec_message-log.rb +6 -9
  234. data/test/log/spec_system-log.rb +5 -3
  235. data/test/notification/spec_address.rb +229 -0
  236. data/test/notification/spec_message.rb +30 -0
  237. data/test/notification/spec_receiver.rb +36 -0
  238. data/test/notification/spec_transmitter.rb +37 -0
  239. data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
  240. data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
  241. data/test/pnml/data/IOExpansionComplex.pnml +363 -0
  242. data/test/pnml/data/IOExpansionSimple.pnml +140 -0
  243. data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
  244. data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
  245. data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
  246. data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
  247. data/test/pnml/data/InputReductionComplex.pnml +192 -0
  248. data/test/pnml/data/InputReductionLong.pnml +344 -0
  249. data/test/pnml/data/InputReductionSimple.pnml +140 -0
  250. data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
  251. data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
  252. data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
  253. data/test/pnml/data/OutputReductionComplex.pnml +186 -0
  254. data/test/pnml/data/OutputReductionLong.pnml +344 -0
  255. data/test/pnml/data/OutputReductionSimple.pnml +140 -0
  256. data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
  257. data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
  258. data/test/pnml/data/SampleNet.pnml +238 -0
  259. data/test/pnml/spec_input-merge-complement.rb +40 -0
  260. data/test/pnml/spec_input-parallelization-complement.rb +50 -0
  261. data/test/pnml/spec_input-reduction.rb +113 -0
  262. data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
  263. data/test/pnml/spec_io-expansion.rb +126 -0
  264. data/test/pnml/spec_isolated-element-elimination.rb +25 -0
  265. data/test/pnml/spec_output-decomposition-complement.rb +40 -0
  266. data/test/pnml/spec_output-reduction.rb +114 -0
  267. data/test/pnml/spec_output-synchronization-complement.rb +62 -0
  268. data/test/pnml/spec_pione-element.rb +144 -0
  269. data/test/pnml/spec_pnml-element.rb +373 -0
  270. data/test/pnml/spec_reader.rb +16 -0
  271. data/test/rootage/spec_argument.rb +18 -0
  272. data/test/rootage/spec_command.rb +239 -0
  273. data/test/rootage/spec_core.rb +198 -0
  274. data/test/rootage/spec_scenario.rb +149 -0
  275. data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
  276. data/test/system/spec_file-cache.rb +6 -9
  277. data/test/tuple-space/spec_finished-tuple.rb +1 -1
  278. data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
  279. data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
  280. data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
  281. data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
  282. data/test/util/spec_boolean-value.rb +32 -0
  283. data/test/util/spec_completion.rb +22 -0
  284. data/test/util/spec_package-parameters-list.rb +39 -52
  285. data/test/util/spec_zip.rb +28 -1
  286. metadata +288 -47
  287. data/bin/pione-tuple-space-receiver +0 -5
  288. data/lib/pione/agent/broker.rb +0 -304
  289. data/lib/pione/agent/tuple-space-receiver.rb +0 -137
  290. data/lib/pione/command/pione-broker.rb +0 -104
  291. data/lib/pione/command/pione-compiler.rb +0 -57
  292. data/lib/pione/command/pione-relay-account-db.rb +0 -141
  293. data/lib/pione/command/pione-relay-client-db.rb +0 -118
  294. data/lib/pione/command/pione-relay.rb +0 -59
  295. data/lib/pione/command/pione-syntax-checker.rb +0 -214
  296. data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
  297. data/lib/pione/command/pione-update-package-info.rb +0 -53
  298. data/lib/pione/front/broker-front.rb +0 -22
  299. data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
  300. data/lib/pione/global/broker-variable.rb +0 -33
  301. data/lib/pione/system/domain-info.rb +0 -25
  302. data/lib/pione/util/pnml-compiler.rb +0 -168
  303. data/test/agent/spec_tuple-space-receiver.rb +0 -47
  304. data/test/util/spec_pnml-compiler.rb +0 -32
@@ -0,0 +1,78 @@
1
+ module Pione
2
+ module PNML
3
+ # `InputMergeComplement` is a net rewriting rule. This rule complements the
4
+ # name of input-merged empty place. For example, the net like the following
5
+ #
6
+ # 'p1' --> empty transition --+
7
+ # |
8
+ # 'p2' --> empty transition --+--> empty place -> A
9
+ # |
10
+ # 'p3' --> empty transition --+
11
+ #
12
+ # is rewritten as the following.
13
+ #
14
+ # 'p1' --> empty transition --+
15
+ # |
16
+ # 'p2' --> empty transition --+--> 'p1' or 'p2' or 'p3' -> A
17
+ # |
18
+ # 'p3' --> empty transition --+
19
+ #
20
+ module InputMergeComplement
21
+ # Find subjects(source transitions and target palce) of this rule from the
22
+ # net. The conditions are followings:
23
+ #
24
+ # - There is an empty target place.
25
+ # - There are more than 2 empty source transitions.
26
+ # - Each source transition has only one named place as the input condition.
27
+ # - There are arcs that connect sources and the target.
28
+ #
29
+ # @param net [PNML::Net]
30
+ # rewriting target net
31
+ # @return [Array]
32
+ # source transitions and target place
33
+ def self.find_subjects(net)
34
+ net.places.each do |place|
35
+ # target place should have no names
36
+ next unless place.empty_name?
37
+
38
+ # collect transitions
39
+ transitions = net.find_all_transitions_by_target_id(place.id).select do |transition|
40
+ arcs = net.find_all_arcs_by_target_id(transition.id)
41
+ if arcs.size == 1
42
+ _place = net.find_place(arcs.first.source_id)
43
+ transition.empty_name? and Perspective.file?(_place)
44
+ end
45
+ end
46
+
47
+ # there should be more than 2 transitions
48
+ next unless transitions.size > 1
49
+
50
+ return [transitions, place]
51
+ end
52
+
53
+ return nil
54
+ end
55
+
56
+ # Rewrite subject place's name by using subject transitions.
57
+ #
58
+ # @param net [PNML::Net]
59
+ # rewriting target net
60
+ # @param subjects [Array]
61
+ # source transitions and target place
62
+ # @return [void]
63
+ def self.rewrite(net, subjects)
64
+ transitions, place = subjects
65
+
66
+ # build a new name
67
+ new_name = transitions.map do |transition|
68
+ arcs = net.find_all_arcs_by_target_id(transition.id)
69
+ _place = net.find_place(arcs.first.source_id)
70
+ Perspective.normalize_data_name(_place.name)
71
+ end.sort.join(" or ")
72
+
73
+ # update the place name
74
+ place.name = "%s%s" % [Perspective.modifier(place.name), new_name]
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,75 @@
1
+ module Pione
2
+ module PNML
3
+ # `InputParallelizationComplement` is a net rewriting rule. This rule
4
+ # complements names of empty places that form input parallelization
5
+ # pattern. For example, the net likes the following
6
+ #
7
+ # +--> empty place --> A
8
+ # |
9
+ # 'p1' --> empty transition --+--> empty place --> B
10
+ # |
11
+ # +--> empty place --> C
12
+ #
13
+ # is rewritten as the following.
14
+ #
15
+ # +--> 'p1' --> A
16
+ # |
17
+ # 'p1' --> empty transition --+--> 'p1' --> B
18
+ # |
19
+ # +--> 'p1' --> C
20
+ #
21
+ module InputParallelizationComplement
22
+ # Find subjects(input place and target places) of this rule from the
23
+ # net. The conditions are followings:
24
+ #
25
+ # - There is an empty source transition. It has only one named place as an
26
+ # input.
27
+ # - There are more than 2 target places that includes empty place.
28
+ # - There are arcs that connect the source and targets.
29
+ #
30
+ # @param net [PNML::Net]
31
+ # rewriting target net
32
+ # @return [Array]
33
+ # input place and target places
34
+ def self.find_subjects(net)
35
+ net.transitions.each do |transition|
36
+ # source transition should have no names
37
+ next unless transition.empty_name?
38
+
39
+ # transition should have only one named input
40
+ input_places = net.find_all_places_by_target_id(transition.id)
41
+ unless input_places.size == 1 and Perspective.file?(input_places.first)
42
+ next
43
+ end
44
+
45
+ # collect places
46
+ output_places = net.find_all_places_by_source_id(transition.id)
47
+ next unless output_places.all? {|output_place| output_place.empty_name?}
48
+
49
+ # there should be more than 2 places
50
+ next unless output_places.size > 1
51
+
52
+ return [input_places.first, output_places]
53
+ end
54
+
55
+ return nil
56
+ end
57
+
58
+ # Rewrite targe place's name same as input place's name.
59
+ #
60
+ # @param net [PNML::Net]
61
+ # rewriting target net
62
+ # @param subjects [Array]
63
+ # input place and target places
64
+ # @return [void]
65
+ def self.rewrite(net, subjects)
66
+ input_place, target_places = subjects
67
+
68
+ # rewrite names of target places
69
+ target_places.each do |place|
70
+ place.name = Perspective.normalize_data_name(input_place.name)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,80 @@
1
+ module Pione
2
+ module PNML
3
+ # `InputReduction` is a net rewriting rule. This rule removes unnecessary
4
+ # input nodes of transitions by following criteria. For example, the net
5
+ # likes the following(A and B are transitions)
6
+ #
7
+ # A --> place --> empty transition --> empty place --> B
8
+ #
9
+ # is rewritten as the following.
10
+ #
11
+ # A -> place -> B
12
+ #
13
+ module InputReduction
14
+ # Return subjects(source transtion, target place, and the arc) if the net
15
+ # satisfies input reduction's condtions. The conditions are followings:
16
+ #
17
+ # - There is an empty source transition.
18
+ # - There is an empty target place. It is an input of named transition.
19
+ # - There is an arc that connects the source and the target.
20
+ def self.find_subjects(net)
21
+ net.transitions.each do |rule|
22
+ # rule has its name
23
+ next unless Perspective.named?(rule)
24
+
25
+ # find source places
26
+ net.find_all_places_by_target_id(rule.id).each do |place|
27
+ # the source place has empty name
28
+ next unless Perspective.empty?(place)
29
+
30
+ # find transtions that generates the source place
31
+ transitions = net.find_all_transitions_by_target_id(place.id)
32
+
33
+ # only one transtion
34
+ if transitions.size == 1
35
+ transition = transitions.first
36
+
37
+ # the transition is connected to only one place at target side
38
+ if net.find_all_places_by_source_id(transition.id).size == 1
39
+ # the transition has empty name
40
+ if Perspective.empty?(transition)
41
+ return [transition, place, net.find_arc(transition.id, place.id)]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ return nil
49
+ end
50
+
51
+ # Rewrite the net with subjects by the following way.
52
+ #
53
+ # - Remove the subject place.
54
+ # - Remove the subject transition.
55
+ # - Remove the subject and related arcs.
56
+ # - Connect discontinuous nodes by new arcs.
57
+ def self.rewrite(net, subjects)
58
+ transition, place, arc = subjects
59
+
60
+ # remove subjects from the net
61
+ net.places.delete(place)
62
+ net.transitions.delete(transition)
63
+ net.arcs.delete(arc)
64
+
65
+ # remove related arcs
66
+ input_arcs = net.find_all_arcs_by_target_id(transition.id)
67
+ input_arcs.each {|arc| net.arcs.delete(arc)}
68
+ output_arcs = net.find_all_arcs_by_source_id(place.id)
69
+ output_arcs.each {|arc| net.arcs.delete(arc)}
70
+
71
+ # append new arcs
72
+ input_arcs.each do |input_arc|
73
+ output_arcs.each do |output_arc|
74
+ net.arcs << Arc.new(net, net.generate_id, input_arc.source_id, output_arc.target_id)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,41 @@
1
+ module Pione
2
+ module PNML
3
+ # `InvalidArcElimination` is a net rewriting rule. This rule removes invalid
4
+ # arcs from nets.
5
+ module InvalidArcElimination
6
+ # Find subjects(an invalid arc) by following criteria.
7
+ #
8
+ # - There is a arc.
9
+ # - It should connect source place and target transition, or source
10
+ # transition and target place.
11
+ def self.find_subjects(net)
12
+ net.arcs.each do |arc|
13
+ source_transition = net.find_transition(arc.source_id)
14
+ source_place = net.find_place(arc.source_id)
15
+ target_transition = net.find_transition(arc.target_id)
16
+ target_place = net.find_place(arc.target_id)
17
+
18
+ # arc from transition to place
19
+ cond1 = not(source_transition.nil?) && not(target_place.nil?)
20
+
21
+ # arc from place to transition
22
+ cond2 = not(source_place.nil?) && not(target_transition.nil?)
23
+
24
+ unless cond1 or cond2
25
+ return [arc]
26
+ end
27
+ end
28
+
29
+ return nil
30
+ end
31
+
32
+ # Rewrite the net by eliminating isolated node.
33
+ def self.rewrite(net, subjects)
34
+ arc = subjects.first
35
+
36
+ # eliminate
37
+ net.arcs.delete(arc)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,88 @@
1
+ module Pione
2
+ module PNML
3
+ # `IOException` is a net rewriting rule. This rule transforms nets by
4
+ # expanding file places that are sandwiched by source and target rule
5
+ # transitions. For example, the net like the following
6
+ #
7
+ # A --> 'p1' --> B
8
+ #
9
+ # is written as the following.
10
+ #
11
+ # A --> 'p1' --> empty transition --> 'p1' --> B
12
+ #
13
+ module IOExpansion
14
+ # Find subjects(sandwiched place and target side arcs) of this rule from
15
+ # the net. The conditions are followings:
16
+ #
17
+ # - There is a file place.
18
+ # - There are rule transitions.
19
+ # - There are arcs that connect the file place and the rule transitions.
20
+ #
21
+ # @param net [PNML::Net]
22
+ # rewriting target net
23
+ # @return [Array]
24
+ # sandwiched place and target side arcs
25
+ def self.find_subjects(net)
26
+ net.transitions.each do |transition|
27
+ # transition should be a rule
28
+ next unless Perspective.rule?(transition)
29
+
30
+ net.find_all_places_by_source_id(transition.id).each do |place|
31
+ # place should be a file
32
+ next unless Perspective.file?(place)
33
+
34
+ # collect target side arcs
35
+ all_target_arcs = net.find_all_arcs_by_source_id(place.id)
36
+ target_arcs = all_target_arcs.select do |arc|
37
+ transition = net.find_transition(arc.target_id)
38
+ transition and Perspective.rule?(transition)
39
+ end
40
+ next unless target_arcs.size > 0
41
+
42
+ # return subjects
43
+ return [place, target_arcs]
44
+ end
45
+ end
46
+
47
+ return nil
48
+ end
49
+
50
+ # Rewrite the net with subjects by the following way.
51
+ #
52
+ # - Remove subject target arcs
53
+ # - Add a copied place and an accommodation transition.
54
+ # - Connect discontinuous nodes by new arcs.
55
+ #
56
+ # @param net [PNML::Net]
57
+ # rewriting target net
58
+ # @param subjects [Array]
59
+ # sandwiched place and target side arcs
60
+ # @return [void]
61
+ def self.rewrite(net, subjects)
62
+ place, target_arcs = subjects
63
+
64
+ # remove arcs
65
+ target_arcs.each {|arc| net.arcs.delete(arc)}
66
+
67
+ # create an expanded place
68
+ expanded_place = Place.new(net, net.generate_id, place.name)
69
+ net.places << expanded_place
70
+
71
+ # create an accommodation transition
72
+ transition = Transition.new(net, net.generate_id)
73
+ net.transitions << transition
74
+
75
+ # connect original place and accommodation transition
76
+ net.arcs << Arc.new(net, net.generate_id, place.id, transition.id)
77
+
78
+ # connect accommodation transition and expanded place
79
+ net.arcs << Arc.new(net, net.generate_id, transition.id, expanded_place.id)
80
+
81
+ # connect expanded place and rule transtions
82
+ target_arcs.each do |arc|
83
+ net.arcs << Arc.new(net, net.generate_id, expanded_place.id, arc.target_id)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,32 @@
1
+ module Pione
2
+ module PNML
3
+ # `IsolatedElementElimination` is a net rewriting rule. This rule removes
4
+ # isolated elememts from nets.
5
+ module IsolatedElementElimination
6
+ # Find subjects(an isolated element) by following criteria.
7
+ #
8
+ # - There is a place or transition.
9
+ # - It has no arcs.
10
+ def self.find_subjects(net)
11
+ (net.places + net.transitions).each do |node|
12
+ input_arcs = net.find_all_arcs_by_source_id(node.id)
13
+ output_arcs = net.find_all_arcs_by_target_id(node.id)
14
+ if input_arcs.empty? and output_arcs.empty?
15
+ return [node]
16
+ end
17
+ end
18
+
19
+ return nil
20
+ end
21
+
22
+ # Rewrite the net by eliminating isolated node.
23
+ def self.rewrite(net, subjects)
24
+ subjects.each do |node|
25
+ # eliminate the node
26
+ net.transitions.delete(node)
27
+ net.places.delete(node)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ module Pione
2
+ module PNML
3
+ # `NetRewriter` is a class for rewriting PNML's net by PIONE's rewriting
4
+ # rules likes "input reduction", "output reduction", "IO expansion", and
5
+ # etc.
6
+ class NetRewriter
7
+ # Create a new net rewriter. Rewriting rules are setuped by the block.
8
+ #
9
+ # PNML::NetRewriter.new do |rules|
10
+ # rules << PNML::InputReduction
11
+ # rules << PNML::OutputReduction
12
+ # rules << PNML::IOExpansion
13
+ # end
14
+ def initialize(&b)
15
+ @rules = []
16
+ if block_given?
17
+ yield @rules
18
+ end
19
+ end
20
+
21
+ # Rewrite the net by rewriting rules recursively.
22
+ #
23
+ # @param net [PNML::Net]
24
+ # a net that is a target of this transformation
25
+ # @return [void]
26
+ def rewrite(net)
27
+ # find rewriting subjects
28
+ rule, subjects = @rules.inject(nil) do |res, _rule|
29
+ if res.nil? and _subjects = _rule.find_subjects(net)
30
+ [_rule, _subjects]
31
+ else
32
+ res
33
+ end
34
+ end
35
+
36
+ # rewrite the net with subjects and go next
37
+ if subjects
38
+ rule.rewrite(net, subjects)
39
+ rewrite(net)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end