pione 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.s3cfg +42 -0
- data/.travis.yml +18 -4
- data/.yardopts +1 -0
- data/Gemfile +3 -0
- data/History.txt +14 -0
- data/Procfile +7 -0
- data/Rakefile +25 -0
- data/bin/pione-interactive +6 -0
- data/bin/{pione-compiler → pione-notification-listener} +1 -1
- data/bin/{pione-broker → pione-task-worker-broker} +1 -1
- data/doc/man/pione-list-param.md +36 -0
- data/example/ActionError/ActionError.pione +9 -0
- data/example/ActionError/pione-package.json +15 -0
- data/example/CountChar/CountChar.pione +1 -1
- data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
- data/example/Touch/pione-package.json +15 -0
- data/lib/pione.rb +12 -0
- data/lib/pione/agent.rb +3 -3
- data/lib/pione/agent/basic-agent.rb +10 -4
- data/lib/pione/agent/input-generator.rb +3 -3
- data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
- data/lib/pione/agent/job-terminator.rb +2 -2
- data/lib/pione/agent/logger.rb +3 -3
- data/lib/pione/agent/messenger.rb +20 -9
- data/lib/pione/agent/notification-listener.rb +88 -0
- data/lib/pione/agent/task-worker-broker.rb +84 -0
- data/lib/pione/agent/task-worker.rb +3 -2
- data/lib/pione/agent/tuple-space-client.rb +1 -0
- data/lib/pione/agent/tuple-space-provider.rb +17 -35
- data/lib/pione/command.rb +33 -15
- data/lib/pione/command/action.rb +105 -0
- data/lib/pione/command/basic-command.rb +34 -376
- data/lib/pione/command/command-exception.rb +12 -11
- data/lib/pione/command/common.rb +198 -0
- data/lib/pione/command/option.rb +159 -204
- data/lib/pione/command/pione-action-exec.rb +85 -0
- data/lib/pione/command/pione-action-list.rb +43 -19
- data/lib/pione/command/pione-action-print.rb +79 -0
- data/lib/pione/command/pione-action.rb +8 -67
- data/lib/pione/command/pione-clean.rb +88 -68
- data/lib/pione/command/pione-client.rb +475 -332
- data/lib/pione/command/pione-command.rb +14 -31
- data/lib/pione/command/pione-compile.rb +90 -0
- data/lib/pione/command/pione-config-get.rb +53 -0
- data/lib/pione/command/pione-config-list.rb +64 -0
- data/lib/pione/command/pione-config-set.rb +59 -0
- data/lib/pione/command/pione-config-unset.rb +50 -0
- data/lib/pione/command/pione-config.rb +61 -0
- data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
- data/lib/pione/command/pione-diagnosis.rb +21 -0
- data/lib/pione/command/pione-interactive.rb +188 -0
- data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
- data/lib/pione/command/pione-lang-interactive.rb +146 -0
- data/lib/pione/command/pione-lang.rb +22 -0
- data/lib/pione/command/pione-log-format.rb +163 -0
- data/lib/pione/command/pione-log-list-id.rb +48 -0
- data/lib/pione/command/pione-log.rb +19 -101
- data/lib/pione/command/pione-notification-listener.rb +95 -0
- data/lib/pione/command/pione-package-add.rb +137 -0
- data/lib/pione/command/pione-package-build.rb +122 -0
- data/lib/pione/command/pione-package-show.rb +96 -0
- data/lib/pione/command/pione-package-update.rb +59 -0
- data/lib/pione/command/pione-package.rb +11 -139
- data/lib/pione/command/pione-task-worker-broker.rb +88 -0
- data/lib/pione/command/pione-task-worker.rb +148 -98
- data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
- data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
- data/lib/pione/command/pione-val.rb +39 -39
- data/lib/pione/command/spawner.rb +34 -27
- data/lib/pione/front.rb +4 -2
- data/lib/pione/front/basic-front.rb +86 -23
- data/lib/pione/front/client-front.rb +2 -2
- data/lib/pione/front/diagnosis-notification-front.rb +40 -0
- data/lib/pione/front/front-exception.rb +7 -1
- data/lib/pione/front/notification-listener-front.rb +36 -0
- data/lib/pione/front/notification-recipient-interface.rb +19 -0
- data/lib/pione/front/relay-front.rb +4 -4
- data/lib/pione/front/task-worker-broker-front.rb +19 -0
- data/lib/pione/front/task-worker-front.rb +2 -2
- data/lib/pione/front/tuple-space-provider-front.rb +3 -2
- data/lib/pione/global.rb +3 -1
- data/lib/pione/global/client-variable.rb +1 -1
- data/lib/pione/global/config.rb +63 -7
- data/lib/pione/global/diagnosis-variable.rb +26 -0
- data/lib/pione/global/item.rb +28 -5
- data/lib/pione/global/log-variable.rb +6 -5
- data/lib/pione/global/network-variable.rb +75 -4
- data/lib/pione/global/path-variable.rb +1 -1
- data/lib/pione/global/system-variable.rb +12 -12
- data/lib/pione/global/task-worker-broker-variable.rb +43 -0
- data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
- data/lib/pione/lang/boolean.rb +4 -0
- data/lib/pione/lang/data-expr.rb +1 -1
- data/lib/pione/lang/integer.rb +1 -1
- data/lib/pione/lang/string.rb +4 -0
- data/lib/pione/lang/type.rb +1 -1
- data/lib/pione/location.rb +1 -0
- data/lib/pione/location/data-location.rb +41 -13
- data/lib/pione/location/dropbox-location.rb +175 -56
- data/lib/pione/location/ftp-location.rb +4 -1
- data/lib/pione/location/http-location.rb +5 -3
- data/lib/pione/location/https-location.rb +4 -2
- data/lib/pione/location/local-location.rb +6 -3
- data/lib/pione/location/location-exception.rb +12 -0
- data/lib/pione/location/notification-scheme.rb +46 -0
- data/lib/pione/log.rb +8 -7
- data/lib/pione/log/debug.rb +9 -9
- data/lib/pione/log/domain-log.rb +6 -1
- data/lib/pione/log/message-log-receiver.rb +32 -0
- data/lib/pione/log/system-log.rb +62 -141
- data/lib/pione/model.rb +7 -0
- data/lib/pione/model/notification-listener-model.rb +29 -0
- data/lib/pione/model/task-worker-broker-model.rb +129 -0
- data/lib/pione/notification.rb +13 -0
- data/lib/pione/notification/address.rb +104 -0
- data/lib/pione/notification/exception.rb +10 -0
- data/lib/pione/notification/message.rb +109 -0
- data/lib/pione/notification/receiver.rb +90 -0
- data/lib/pione/notification/recipient.rb +68 -0
- data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
- data/lib/pione/notification/transmitter.rb +84 -0
- data/lib/pione/pnml.rb +35 -0
- data/lib/pione/pnml/annotation-extractor.rb +47 -0
- data/lib/pione/pnml/compiler.rb +176 -0
- data/lib/pione/pnml/input-merge-complement.rb +78 -0
- data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
- data/lib/pione/pnml/input-reduction.rb +80 -0
- data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
- data/lib/pione/pnml/io-expansion.rb +88 -0
- data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
- data/lib/pione/pnml/net-rewriter.rb +44 -0
- data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
- data/lib/pione/pnml/output-reduction.rb +86 -0
- data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
- data/lib/pione/pnml/pione-model.rb +417 -0
- data/lib/pione/pnml/pnml-exception.rb +23 -0
- data/lib/pione/pnml/pnml-model.rb +368 -0
- data/lib/pione/pnml/reader.rb +51 -0
- data/lib/pione/rule-engine/action-handler.rb +8 -6
- data/lib/pione/rule-engine/basic-handler.rb +5 -5
- data/lib/pione/rule-engine/engine-exception.rb +7 -6
- data/lib/pione/rule-engine/flow-handler.rb +27 -18
- data/lib/pione/system.rb +3 -1
- data/lib/pione/system/domain-dump.rb +34 -0
- data/lib/pione/system/file-cache.rb +92 -13
- data/lib/pione/system/init.rb +3 -0
- data/lib/pione/system/normalizer.rb +40 -0
- data/lib/pione/system/status.rb +5 -5
- data/lib/pione/system/system-exception.rb +14 -1
- data/lib/pione/task-worker-broker.rb +7 -0
- data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
- data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
- data/lib/pione/test-helper.rb +27 -0
- data/lib/pione/test-helper/command-helper.rb +9 -101
- data/lib/pione/tuple-space/basic-tuple.rb +1 -1
- data/lib/pione/tuple-space/tuple-definition.yml +4 -6
- data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
- data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
- data/lib/pione/util.rb +1 -2
- data/lib/pione/util/boolean-value.rb +62 -0
- data/lib/pione/util/completion.rb +111 -0
- data/lib/pione/util/evaluatable.rb +13 -27
- data/lib/pione/util/package-parameters-list.rb +15 -27
- data/lib/pione/util/zip.rb +8 -3
- data/lib/pione/version.rb +1 -1
- data/lib/rootage.rb +20 -0
- data/lib/rootage/action.rb +114 -0
- data/lib/rootage/argument.rb +46 -0
- data/lib/rootage/command.rb +218 -0
- data/lib/rootage/core.rb +532 -0
- data/lib/rootage/exception.rb +107 -0
- data/lib/rootage/help.rb +148 -0
- data/lib/rootage/help.txt.erb +31 -0
- data/lib/rootage/log.rb +226 -0
- data/lib/rootage/normalizer.rb +184 -0
- data/lib/rootage/option.rb +152 -0
- data/lib/rootage/scenario-test-result.erb +39 -0
- data/lib/rootage/scenario.rb +362 -0
- data/lib/rootage/test-helper.rb +115 -0
- data/man/pione-list-param.1 +44 -0
- data/misc/clock.rb +9 -0
- data/misc/machine-info.sh +21 -0
- data/misc/pione-completion.bash +238 -0
- data/misc/pione-completion.erb +53 -0
- data/misc/pione-completion.zsh +238 -0
- data/misc/pione.god +22 -0
- data/misc/ui.xml +23 -0
- data/pione.gemspec +3 -1
- data/test/agent/spec_basic-agent.rb +1 -1
- data/test/agent/spec_input-generator.rb +2 -2
- data/test/agent/spec_messenger.rb +6 -9
- data/test/agent/spec_notification-listener.rb +80 -0
- data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
- data/test/agent/spec_tuple-space-provider.rb +10 -6
- data/test/command/command-behavior.rb +3 -11
- data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
- data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
- data/test/command/spec_pione-action-exec.rb +16 -0
- data/test/command/spec_pione-action-list.rb +15 -10
- data/test/command/spec_pione-action-print.rb +14 -0
- data/test/command/spec_pione-action.rb +6 -19
- data/test/command/spec_pione-clean.rb +29 -46
- data/test/command/spec_pione-client.rb +29 -36
- data/test/command/spec_pione-command.rb +6 -6
- data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
- data/test/command/spec_pione-config-get.rb +47 -0
- data/test/command/spec_pione-config-list.rb +42 -0
- data/test/command/spec_pione-config-set.rb +38 -0
- data/test/command/spec_pione-config-unset.rb +44 -0
- data/test/command/spec_pione-config.rb +11 -0
- data/test/command/spec_pione-diagnosis-notification.rb +23 -0
- data/test/command/spec_pione-diagnosis.rb +11 -0
- data/test/command/spec_pione-lang-check-syntax.rb +12 -0
- data/test/command/spec_pione-lang.rb +11 -0
- data/test/command/spec_pione-log-format.rb +29 -0
- data/test/command/spec_pione-log-list-id.rb +17 -0
- data/test/command/spec_pione-log.rb +6 -20
- data/test/command/spec_pione-package-add.rb +55 -0
- data/test/command/spec_pione-package-build.rb +57 -0
- data/test/command/spec_pione-package-show.rb +72 -0
- data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
- data/test/command/spec_pione-package.rb +4 -104
- data/test/command/spec_pione-val.rb +10 -7
- data/test/global/spec_config.rb +50 -0
- data/test/global/spec_item.rb +1 -1
- data/test/literate-action/data/HelloWorld.md +1 -1
- data/test/location/location-behavior.rb +1 -1
- data/test/location/spec_dropbox-location.rb +39 -0
- data/test/location/spec_notification-scheme.rb +37 -0
- data/test/log/spec_debug.rb +5 -4
- data/test/log/spec_message-log-receiver.rb +13 -0
- data/test/log/spec_message-log.rb +6 -9
- data/test/log/spec_system-log.rb +5 -3
- data/test/notification/spec_address.rb +229 -0
- data/test/notification/spec_message.rb +30 -0
- data/test/notification/spec_receiver.rb +36 -0
- data/test/notification/spec_transmitter.rb +37 -0
- data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
- data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
- data/test/pnml/data/IOExpansionComplex.pnml +363 -0
- data/test/pnml/data/IOExpansionSimple.pnml +140 -0
- data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
- data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
- data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
- data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
- data/test/pnml/data/InputReductionComplex.pnml +192 -0
- data/test/pnml/data/InputReductionLong.pnml +344 -0
- data/test/pnml/data/InputReductionSimple.pnml +140 -0
- data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
- data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
- data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
- data/test/pnml/data/OutputReductionComplex.pnml +186 -0
- data/test/pnml/data/OutputReductionLong.pnml +344 -0
- data/test/pnml/data/OutputReductionSimple.pnml +140 -0
- data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
- data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
- data/test/pnml/data/SampleNet.pnml +238 -0
- data/test/pnml/spec_input-merge-complement.rb +40 -0
- data/test/pnml/spec_input-parallelization-complement.rb +50 -0
- data/test/pnml/spec_input-reduction.rb +113 -0
- data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
- data/test/pnml/spec_io-expansion.rb +126 -0
- data/test/pnml/spec_isolated-element-elimination.rb +25 -0
- data/test/pnml/spec_output-decomposition-complement.rb +40 -0
- data/test/pnml/spec_output-reduction.rb +114 -0
- data/test/pnml/spec_output-synchronization-complement.rb +62 -0
- data/test/pnml/spec_pione-element.rb +144 -0
- data/test/pnml/spec_pnml-element.rb +373 -0
- data/test/pnml/spec_reader.rb +16 -0
- data/test/rootage/spec_argument.rb +18 -0
- data/test/rootage/spec_command.rb +239 -0
- data/test/rootage/spec_core.rb +198 -0
- data/test/rootage/spec_scenario.rb +149 -0
- data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
- data/test/system/spec_file-cache.rb +6 -9
- data/test/tuple-space/spec_finished-tuple.rb +1 -1
- data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
- data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
- data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
- data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
- data/test/util/spec_boolean-value.rb +32 -0
- data/test/util/spec_completion.rb +22 -0
- data/test/util/spec_package-parameters-list.rb +39 -52
- data/test/util/spec_zip.rb +28 -1
- metadata +288 -47
- data/bin/pione-tuple-space-receiver +0 -5
- data/lib/pione/agent/broker.rb +0 -304
- data/lib/pione/agent/tuple-space-receiver.rb +0 -137
- data/lib/pione/command/pione-broker.rb +0 -104
- data/lib/pione/command/pione-compiler.rb +0 -57
- data/lib/pione/command/pione-relay-account-db.rb +0 -141
- data/lib/pione/command/pione-relay-client-db.rb +0 -118
- data/lib/pione/command/pione-relay.rb +0 -59
- data/lib/pione/command/pione-syntax-checker.rb +0 -214
- data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
- data/lib/pione/command/pione-update-package-info.rb +0 -53
- data/lib/pione/front/broker-front.rb +0 -22
- data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
- data/lib/pione/global/broker-variable.rb +0 -33
- data/lib/pione/system/domain-info.rb +0 -25
- data/lib/pione/util/pnml-compiler.rb +0 -168
- data/test/agent/spec_tuple-space-receiver.rb +0 -47
- 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
|