Module: Pione::PNML::OutputReduction
- Defined in:
- lib/pione/pnml/output-reduction.rb
Overview
OutputReduction
is a net rewriting rule. This rule removes unnecessary
output nodes of transitions. For example, the net likes the following
A --> empty place --> empty transition --> place --> B
is rewritten as the following.
A -> place -> B
Class Method Summary collapse
-
.find_subjects(net, env) ⇒ Array
Return subjects(source place, target transition, and the arc) if the net satisfies output reduction's condtions.
-
.rewrite(net, subjects, env) ⇒ void
Rewrite the net with subjects by the following way.
Class Method Details
.find_subjects(net, env) ⇒ Array
Return subjects(source place, target transition, and the arc) if the net satisfies output reduction's condtions. The conditions are followings:
- There is an empty source place. It is an output of named transition.
- There is an empty target transition.
- There is an arc that connects the source and the target.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pione/pnml/output-reduction.rb', line 26 def self.find_subjects(net, env) net.places.each do |place| # source place should be empty next unless Perspective.empty_place?(env, place) # source place should be an output of named transition next if net.find_all_transitions_by_target_id(place.id).map do |transition| not(Perspective.empty_transition?(env, transition)) end.empty? transitions = net.find_all_transitions_by_source_id(place.id) # only one transition if transitions.size == 1 transition = transitions.first # the transtion is connected to only one place at source side if net.find_all_places_by_target_id(transition.id).size == 1 # target transition should be empty next unless Perspective.empty?(env, transition) return [place, transition, net.find_arc(place.id, transition.id)] end end end return nil end |
.rewrite(net, subjects, env) ⇒ void
This method returns an undefined value.
Rewrite the net with subjects by the following way.
- Remove the subject place.
- Remove the subject transition.
- Remove the subject and related arcs.
- Connect discontinuous nodes by new arcs.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pione/pnml/output-reduction.rb', line 69 def self.rewrite(net, subjects, env) place, transition, arc = subjects # remove subjects from the net net.places.delete(place) net.transitions.delete(transition) net.arcs.delete(arc) # remove related arcs input_arcs = net.find_all_arcs_by_target_id(place.id) input_arcs.each {|arc| net.arcs.delete(arc)} output_arcs = net.find_all_arcs_by_source_id(transition.id) output_arcs.each {|arc| net.arcs.delete(arc)} # append new arcs input_arcs.each do |input_arc| output_arcs.each do |output_arc| net.arcs << Arc.new(net, net.generate_id, input_arc.source_id, output_arc.target_id) end end end |