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,23 @@
|
|
1
|
+
module Pione
|
2
|
+
module PNML
|
3
|
+
# `AmbiguousNetQueryResult` is an exception that raised when reuslt of net
|
4
|
+
# query is ambigous unexpectedly.
|
5
|
+
class AmbiguousNetQueryResult < StandardError
|
6
|
+
# @param name [String]
|
7
|
+
# net query method name
|
8
|
+
# @param query [Object]
|
9
|
+
# the query
|
10
|
+
# @param result [Object]
|
11
|
+
# the result
|
12
|
+
def initialize(name, query, result)
|
13
|
+
@name = name
|
14
|
+
@query = query
|
15
|
+
@result = result
|
16
|
+
end
|
17
|
+
|
18
|
+
def message
|
19
|
+
"The result of net query(%s, %s) is ambiguous: %s" % [@name, @query.inspect, @result.inspect]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,368 @@
|
|
1
|
+
module Pione
|
2
|
+
module PNML
|
3
|
+
# `Net` represents a net in PNML. PIONE handles PT-nets only, so this is
|
4
|
+
# consisted by places, transitions, and arcs.
|
5
|
+
class Net < StructX
|
6
|
+
# all places in the net
|
7
|
+
member :places, :default => lambda{ Array.new }
|
8
|
+
|
9
|
+
# all transitions in the net
|
10
|
+
member :transitions, :default => lambda{ Array.new }
|
11
|
+
|
12
|
+
# all arcs in the net
|
13
|
+
member :arcs, :default => lambda{ Array.new }
|
14
|
+
|
15
|
+
# Generate a new PNML's ID.
|
16
|
+
def generate_id
|
17
|
+
Util::UUID.generate
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return true if the net is valid. The criterion of validness is that all
|
21
|
+
# arcs connect places and transitions.
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
24
|
+
# true if the net is valid
|
25
|
+
def valid?
|
26
|
+
arcs.each do |arc|
|
27
|
+
source_transition = find_transition(arc.source_id)
|
28
|
+
source_place = find_place(arc.source_id)
|
29
|
+
target_transition = find_transition(arc.target_id)
|
30
|
+
target_place = find_place(arc.target_id)
|
31
|
+
|
32
|
+
# arc from transition to place
|
33
|
+
cond1 = not(source_transition.nil?) && not(target_place.nil?)
|
34
|
+
|
35
|
+
# arc from place to transition
|
36
|
+
cond2 = not(source_place.nil?) && not(target_transition.nil?)
|
37
|
+
|
38
|
+
unless cond1 or cond2
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
|
46
|
+
# Find the arc that connects from the source ID to the target ID. If no
|
47
|
+
# arcs found, return `nil`.
|
48
|
+
#
|
49
|
+
# @param source_id [String]
|
50
|
+
# source ID
|
51
|
+
# @param target_id [String]
|
52
|
+
# target ID
|
53
|
+
# @return [PNML::Arc]
|
54
|
+
# the arc, or `nil`
|
55
|
+
def find_arc(source_id, target_id)
|
56
|
+
_arcs = arcs.select {|arc| arc.source_id == source_id and arc.target_id == target_id}
|
57
|
+
|
58
|
+
# the result shouldn't be ambiguous
|
59
|
+
if _arcs.size > 1
|
60
|
+
raise AmbiguousNetQueryResult.new(__method__, place_id, _transitions)
|
61
|
+
end
|
62
|
+
|
63
|
+
return _arcs.first
|
64
|
+
end
|
65
|
+
|
66
|
+
# Find all arcs by the source ID.
|
67
|
+
#
|
68
|
+
# @param source_id [String]
|
69
|
+
# source ID
|
70
|
+
# @return [Array<Arc>]
|
71
|
+
# result arcs
|
72
|
+
def find_all_arcs_by_source_id(source_id)
|
73
|
+
arcs.select {|arc| arc.source_id == source_id}
|
74
|
+
end
|
75
|
+
|
76
|
+
# Find all arcs by the target ID.
|
77
|
+
#
|
78
|
+
# @param target_id [String]
|
79
|
+
# target ID
|
80
|
+
# @return [Array<Arc>]
|
81
|
+
# result arcs
|
82
|
+
def find_all_arcs_by_target_id(target_id)
|
83
|
+
arcs.select {|arc| arc.target_id == target_id}
|
84
|
+
end
|
85
|
+
|
86
|
+
# Return all arcs which have the direction from transtion to place.
|
87
|
+
#
|
88
|
+
# @return [Array<PNML::Arc>]
|
89
|
+
# arcs
|
90
|
+
def tp_arcs
|
91
|
+
arcs.select {|arc| arc.from_transition_to_place?}
|
92
|
+
end
|
93
|
+
|
94
|
+
# Return all arcs which have the direction from place to transition.
|
95
|
+
#
|
96
|
+
# @return [Array<PNML::Arc>]
|
97
|
+
# arcs
|
98
|
+
def pt_arcs
|
99
|
+
arcs.select {|arc| arc.from_place_to_transition?}
|
100
|
+
end
|
101
|
+
|
102
|
+
# Find a transition by ID.
|
103
|
+
#
|
104
|
+
# @param id [String]
|
105
|
+
# transition ID
|
106
|
+
# @return [Transition]
|
107
|
+
# transition
|
108
|
+
def find_transition(id)
|
109
|
+
transitions.find {|transition| transition.id == id}
|
110
|
+
end
|
111
|
+
|
112
|
+
# Find a transition by the name.
|
113
|
+
#
|
114
|
+
# @param name [String]
|
115
|
+
# the transition name
|
116
|
+
# @return [Transition]
|
117
|
+
# a transition, or nil
|
118
|
+
def find_transition_by_name(name)
|
119
|
+
_transitions = transitions.select {|transition| transition.name == name}
|
120
|
+
|
121
|
+
# the result shouldn't be ambiguous
|
122
|
+
if _transitions.size > 1
|
123
|
+
raise AmbiguousNetQueryResult.new(__method__, place_id, _transitions)
|
124
|
+
end
|
125
|
+
|
126
|
+
return _transitions.first
|
127
|
+
end
|
128
|
+
|
129
|
+
# Find all transitions by the name.
|
130
|
+
#
|
131
|
+
# @param name [String]
|
132
|
+
# transition's name
|
133
|
+
# @return [Array<Transition>]
|
134
|
+
# transitions
|
135
|
+
def find_all_transitions_by_name(name)
|
136
|
+
transitions.select {|transition| transition.name == name}
|
137
|
+
end
|
138
|
+
|
139
|
+
# Find a transition by the source place ID.
|
140
|
+
#
|
141
|
+
# @param place_id [String]
|
142
|
+
# place ID
|
143
|
+
# @return [Array<Transition>]
|
144
|
+
# result transitions
|
145
|
+
def find_transition_by_source_id(place_id)
|
146
|
+
_arcs = arcs.select {|arc| arc.source_id == place_id}
|
147
|
+
_transitions = _arcs.map do |arc|
|
148
|
+
transitions.find {|transition| transition.id == arc.target_id}
|
149
|
+
end.compact.uniq
|
150
|
+
|
151
|
+
# the result shouldn't be ambiguous
|
152
|
+
if _transitions.size > 1
|
153
|
+
raise AmbiguousNetQueryResult.new(__method__, place_id, _transitions)
|
154
|
+
end
|
155
|
+
|
156
|
+
return _transitions.first
|
157
|
+
end
|
158
|
+
|
159
|
+
# Find all transitions by the source place ID.
|
160
|
+
#
|
161
|
+
# @param place_id [String]
|
162
|
+
# place ID
|
163
|
+
# @return [Array<Transition>]
|
164
|
+
# result transitions
|
165
|
+
def find_all_transitions_by_source_id(place_id)
|
166
|
+
_arcs = arcs.select {|arc| arc.source_id == place_id}
|
167
|
+
_transitions = _arcs.map do |arc|
|
168
|
+
transitions.find {|transition| transition.id == arc.target_id}
|
169
|
+
end
|
170
|
+
return _transitions.compact.uniq
|
171
|
+
end
|
172
|
+
|
173
|
+
# Find a transition by the target place ID.
|
174
|
+
#
|
175
|
+
# @param place_id [String]
|
176
|
+
# place ID
|
177
|
+
# @return [Array<Transition>]
|
178
|
+
# result transitions
|
179
|
+
def find_transition_by_target_id(target_id)
|
180
|
+
_arcs = arcs.select {|arc| arc.target_id == target_id}
|
181
|
+
_transitions = _arcs.map do |arc|
|
182
|
+
transitions.find {|transition| transition.id == arc.source_id}
|
183
|
+
end.compact.uniq
|
184
|
+
|
185
|
+
# the result shouldn't be ambiguous
|
186
|
+
if _transitions.size > 1
|
187
|
+
raise AmbiguousNetQueryResult.new(__method__, place_id, _transitions)
|
188
|
+
end
|
189
|
+
|
190
|
+
return _transitions.first
|
191
|
+
end
|
192
|
+
|
193
|
+
# Find all transitions by the target place ID.
|
194
|
+
#
|
195
|
+
# @param place_id [String]
|
196
|
+
# place ID
|
197
|
+
# @return [Array<Transition>]
|
198
|
+
# result transitions
|
199
|
+
def find_all_transitions_by_target_id(target_id)
|
200
|
+
_arcs = arcs.select {|arc| arc.target_id == target_id}
|
201
|
+
_transitions = _arcs.map do |arc|
|
202
|
+
transitions.find {|transition| transition.id == arc.source_id}
|
203
|
+
end
|
204
|
+
return _transitions.compact.uniq
|
205
|
+
end
|
206
|
+
|
207
|
+
# Find a place by ID.
|
208
|
+
#
|
209
|
+
# @param id [String]
|
210
|
+
# the place ID
|
211
|
+
# @return [Place]
|
212
|
+
# place
|
213
|
+
def find_place(id)
|
214
|
+
places.find {|place| place.id == id}
|
215
|
+
end
|
216
|
+
|
217
|
+
# Find a place by the name.
|
218
|
+
#
|
219
|
+
# @param name [String]
|
220
|
+
# the place name
|
221
|
+
# @return [Place]
|
222
|
+
# a place, or nil
|
223
|
+
def find_place_by_name(name)
|
224
|
+
_places = places.select {|place| place.name == name}
|
225
|
+
|
226
|
+
# the result shouldn't be ambiguous
|
227
|
+
if _places.size > 1
|
228
|
+
raise AmbiguousNetQueryResult.new(__method__, name, _places)
|
229
|
+
end
|
230
|
+
|
231
|
+
return _places.first
|
232
|
+
end
|
233
|
+
|
234
|
+
# Find places by the name.
|
235
|
+
#
|
236
|
+
# @param name [String]
|
237
|
+
# place name
|
238
|
+
# @return [Array<Place>]
|
239
|
+
# places
|
240
|
+
def find_all_places_by_name(name)
|
241
|
+
places.select {|place| place.name == name}
|
242
|
+
end
|
243
|
+
|
244
|
+
# Find a place by the source transition ID.
|
245
|
+
#
|
246
|
+
# @param transition_id [String]
|
247
|
+
# transition ID
|
248
|
+
# @return [Array<Transition>]
|
249
|
+
# a result place
|
250
|
+
def find_place_by_source_id(transition_id)
|
251
|
+
_arcs = arcs.select {|arc| arc.source_id == transition_id}
|
252
|
+
_places = _arcs.map do |arc|
|
253
|
+
places.find {|place| place.id == arc.target_id}
|
254
|
+
end.compact.uniq
|
255
|
+
|
256
|
+
# the result shouldn't be ambiguous
|
257
|
+
if _places.size > 1
|
258
|
+
raise AmbiguousNetQueryResult.new(__method__, name, _places)
|
259
|
+
end
|
260
|
+
|
261
|
+
return _places.first
|
262
|
+
end
|
263
|
+
|
264
|
+
# Find all places by the source transition ID.
|
265
|
+
#
|
266
|
+
# @param transition_id [String]
|
267
|
+
# transition ID
|
268
|
+
# @return [Array<Transition>]
|
269
|
+
# result places
|
270
|
+
def find_all_places_by_source_id(transition_id)
|
271
|
+
_arcs = arcs.select {|arc| arc.source_id == transition_id}
|
272
|
+
_places = _arcs.map do |arc|
|
273
|
+
places.find {|place| place.id == arc.target_id}
|
274
|
+
end
|
275
|
+
return _places.compact.uniq
|
276
|
+
end
|
277
|
+
|
278
|
+
# Find a place by the target transition ID.
|
279
|
+
#
|
280
|
+
# @param transition_id [String]
|
281
|
+
# transition ID
|
282
|
+
# @return [Array<Transition>]
|
283
|
+
# result places
|
284
|
+
def find_place_by_target_id(transition_id)
|
285
|
+
_arcs = arcs.select {|arc| arc.target_id == transition_id}
|
286
|
+
_places = _arcs.map do |arc|
|
287
|
+
places.find {|place| place.id == arc.source_id}
|
288
|
+
end.compact.uniq
|
289
|
+
|
290
|
+
# the result shouldn't be ambiguous
|
291
|
+
if _places.size > 1
|
292
|
+
raise AmbiguousNetQueryResult.new(__method__, name, _places)
|
293
|
+
end
|
294
|
+
|
295
|
+
return _places.first
|
296
|
+
end
|
297
|
+
|
298
|
+
# Find all places by the target transition ID.
|
299
|
+
#
|
300
|
+
# @param transition_id [String]
|
301
|
+
# transition ID
|
302
|
+
# @return [Array<Transition>]
|
303
|
+
# result places
|
304
|
+
def find_all_places_by_target_id(transition_id)
|
305
|
+
_arcs = arcs.select {|arc| arc.target_id == transition_id}
|
306
|
+
_places = _arcs.map do |arc|
|
307
|
+
places.find {|place| place.id == arc.source_id}
|
308
|
+
end
|
309
|
+
return _places.compact.uniq
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
# `Node` is a meta class for `Place` and `Transition`.
|
314
|
+
class Node < StructX
|
315
|
+
# Eliminate comments from the string. This implementation is temporary, we
|
316
|
+
# should fix this.
|
317
|
+
def eliminate_comment(str)
|
318
|
+
# FIXME
|
319
|
+
str.sub(/#.*$/, "")
|
320
|
+
end
|
321
|
+
|
322
|
+
# Return true if the name is empty.
|
323
|
+
def empty_name?
|
324
|
+
name.nil? or /^\s*[<>]?\s*$/.match(eliminate_comment(name))
|
325
|
+
end
|
326
|
+
|
327
|
+
def inspect
|
328
|
+
"#<%s id=%s name=%s>" % [self.class.name, id.inspect, name.inspect]
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
# `Place` is a class represents places in PT-net.
|
333
|
+
class Place < Node
|
334
|
+
member :net
|
335
|
+
member :id
|
336
|
+
member :name
|
337
|
+
end
|
338
|
+
|
339
|
+
# `Transition` is a class represents transitions in PT-net.
|
340
|
+
class Transition < Node
|
341
|
+
member :net
|
342
|
+
member :id
|
343
|
+
member :name
|
344
|
+
end
|
345
|
+
|
346
|
+
# `Arc` is a class represents arcs in PT-net.
|
347
|
+
class Arc < StructX
|
348
|
+
member :net
|
349
|
+
member :id
|
350
|
+
member :source_id
|
351
|
+
member :target_id
|
352
|
+
|
353
|
+
# Return true if the arc has the direction from transition to place.
|
354
|
+
def from_transition_to_place?
|
355
|
+
net.transitions.any? {|t| t.id == source_id} and net.places.any? {|p| p.id == target_id}
|
356
|
+
end
|
357
|
+
|
358
|
+
# Return true if the arc has the direction from place to transition.
|
359
|
+
def from_place_to_transition?
|
360
|
+
net.places.any? {|p| p.id == source_id} and net.transitions.any? {|t| t.id == target_id}
|
361
|
+
end
|
362
|
+
|
363
|
+
def inspect
|
364
|
+
"#<Pione::PNML::Arc id=%s source_id=%s target_id=%s>" % [id.inspect, source_id.inspect, target_id.inspect]
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Pione
|
2
|
+
module PNML
|
3
|
+
class Reader
|
4
|
+
# Read a PNML file at the location and return `PNML::Net`.
|
5
|
+
#
|
6
|
+
# @param location [Location::DataLocation]
|
7
|
+
# PNML file's location
|
8
|
+
def self.read(location)
|
9
|
+
new(location.read).read
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(src)
|
13
|
+
@doc = REXML::Document.new(src)
|
14
|
+
end
|
15
|
+
|
16
|
+
def read
|
17
|
+
Net.new.tap do |net|
|
18
|
+
net.transitions = find_transitions(@doc, net)
|
19
|
+
net.places = find_places(@doc, net)
|
20
|
+
net.arcs = find_arcs(@doc, net)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Find all transtions in the document.
|
25
|
+
def find_transitions(doc, net)
|
26
|
+
REXML::XPath.match(doc, "/pnml/net/transition").map do |elt|
|
27
|
+
id = elt.attribute("id").value
|
28
|
+
name = REXML::XPath.first(elt, "name/text").texts.map{|text| text.value}.join("")
|
29
|
+
Transition.new(net, id, name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_places(doc, net)
|
34
|
+
REXML::XPath.match(doc, "/pnml/net/place").map do |elt|
|
35
|
+
id = elt.attribute("id").value
|
36
|
+
name = REXML::XPath.first(elt, "name/text").texts.map{|text| text.value}.join("")
|
37
|
+
Place.new(net, id, name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_arcs(doc, net)
|
42
|
+
REXML::XPath.match(doc, "/pnml/net/arc").map do |elt|
|
43
|
+
id = elt.attribute("id").value
|
44
|
+
source_id = elt.attribute("source").value # source place(data) id
|
45
|
+
target_id = elt.attribute("target").value # target transition(rule) id
|
46
|
+
Arc.new(net, id, source_id, target_id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -78,6 +78,8 @@ module Pione
|
|
78
78
|
# Write the action into a shell script.
|
79
79
|
def write_shell_script(&b)
|
80
80
|
file = @working_directory + "__pione-action__.sh"
|
81
|
+
content = @rule_definition.action_context.eval(@env).content
|
82
|
+
sh = Util::EmbededExprExpander.expand(@env, content)
|
81
83
|
|
82
84
|
# write the action
|
83
85
|
if @dry_run
|
@@ -85,9 +87,8 @@ module Pione
|
|
85
87
|
file.create("touch %s" % output.eval(@env).name)
|
86
88
|
end
|
87
89
|
else
|
88
|
-
|
89
|
-
|
90
|
-
file.create(Util::EmbededExprExpander.expand(@env, content))
|
90
|
+
file.create(sh)
|
91
|
+
|
91
92
|
# chmod 700
|
92
93
|
if @working_directory.scheme == "local"
|
93
94
|
FileUtils.chmod(0700, file.path)
|
@@ -95,8 +96,7 @@ module Pione
|
|
95
96
|
end
|
96
97
|
|
97
98
|
# message
|
98
|
-
|
99
|
-
user_message(["-"*60, lines, "-"*60].flatten, 0, "SH")
|
99
|
+
user_message(["-"*60, sh.split("\n"), "-"*60].flatten, 0, "SH")
|
100
100
|
|
101
101
|
return b.call(file.path)
|
102
102
|
end
|
@@ -117,7 +117,7 @@ module Pione
|
|
117
117
|
|
118
118
|
# the case the script has errored
|
119
119
|
unless $?.success?
|
120
|
-
raise ActionError.new(digest, (@working_directory + err).read)
|
120
|
+
raise ActionError.new(self, digest, (@working_directory + err).read)
|
121
121
|
end
|
122
122
|
|
123
123
|
# delete .stdout file if it is empty
|
@@ -177,6 +177,8 @@ module Pione
|
|
177
177
|
src = @working_directory + output.name
|
178
178
|
dest = output.location
|
179
179
|
System::FileCache.put(src, dest)
|
180
|
+
# copy the data to the caller's domain in file server
|
181
|
+
src.copy(dest)
|
180
182
|
end
|
181
183
|
end
|
182
184
|
|