Module: Pione::PNML::IOExpansion

Defined in:
lib/pione/pnml/io-expansion.rb

Overview

IOException is a net rewriting rule. This rule transforms nets by expanding file places that are sandwiched by source and target rule transitions. For example, the net like the following

A --> 'p1' --> B

is written as the following.

A --> 'p1' --> empty transition --> 'p1' --> B

Class Method Summary collapse

Class Method Details

.find_subjects(net, env) ⇒ Array

Find subjects(sandwiched place and target side arcs) of this rule from the net. The conditions are followings:

  • There is a file place.
  • There are rule transitions.
  • There are arcs that connect the file place and the rule transitions.

Parameters:

Returns:

  • (Array)

    sandwiched place and target side arcs



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pione/pnml/io-expansion.rb', line 27

def self.find_subjects(net, env)
  net.transitions.each do |transition|
    # transition should be a rule
    next unless Perspective.rule_transition?(env, transition)

    net.find_all_places_by_source_id(transition.id).each do |place|
      # place should be a file
      next unless Perspective.data_place?(env, place)

      # collect target side arcs
      all_target_arcs = net.find_all_arcs_by_source_id(place.id)
      target_arcs = all_target_arcs.select do |arc|
        transition = net.find_transition(arc.target_id)
        transition and Perspective.rule_transition?(env, transition)
      end
      next unless target_arcs.size > 0

      # return subjects
      return [place, target_arcs]
    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 subject target arcs
  • Add a copied place and an accommodation transition.
  • Connect discontinuous nodes by new arcs.

Parameters:



65
66
67
68
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/io-expansion.rb', line 65

def self.rewrite(net, subjects, env)
  place, target_arcs = subjects

  # remove arcs
  target_arcs.each {|arc| net.arcs.delete(arc)}

  # create an expanded place
  expanded_place = Place.new(net, net.generate_id, place.name)
  net.places << expanded_place

  # create an accommodation transition
  transition = Transition.new(net, net.generate_id)
  net.transitions << transition

  # connect original place and accommodation transition
  net.arcs << Arc.new(net, net.generate_id, place.id, transition.id)

  # connect accommodation transition and expanded place
  net.arcs << Arc.new(net, net.generate_id, transition.id, expanded_place.id)

  # connect expanded place and rule transtions
  target_arcs.each do |arc|
    net.arcs << Arc.new(net, net.generate_id, expanded_place.id, arc.target_id)
  end
end