Module: Pione::PNML::InputMergeComplement

Defined in:
lib/pione/pnml/input-merge-complement.rb

Overview

InputMergeComplement is a net rewriting rule. This rule complements the name of input-merged empty place. For example, the net like the following

'p1' --> empty transition --+
                            |
'p2' --> empty transition --+--> empty place -> A
                            |
'p3' --> empty transition --+

is rewritten as the following.

'p1' --> empty transition --+
                            |
'p2' --> empty transition --+--> 'p1' or 'p2' or 'p3' -> A
                            |
'p3' --> empty transition --+

Class Method Summary collapse

Class Method Details

.find_subjects(net, env) ⇒ Array

Find subjects(source transitions and target palce) of this rule from the net. The conditions are followings:

  • There is an empty target place.
  • There are more than 2 empty source transitions.
  • Each source transition has only one named place as the input condition.
  • There are arcs that connect sources and the target.

Parameters:

Returns:

  • (Array)

    source transitions and target place



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pione/pnml/input-merge-complement.rb', line 34

def self.find_subjects(net, env)
  net.places.each do |place|
    # target place should be empty
    next unless Perspective.empty_place?(env, place)

    # collect transitions
    transitions = net.find_all_transitions_by_target_id(place.id).select do |transition|
      arcs = net.find_all_arcs_by_target_id(transition.id)
      if arcs.size == 1
        _place = net.find_place(arcs.first.source_id)
        Perspective.empty_transition?(env, transition) and Perspective.data_place?(env, _place)
      end
    end

    # there should be more than 2 transitions
    next unless transitions.size > 1

    return [transitions, place]
  end

  return nil
end

.rewrite(net, subjects, env) ⇒ void

This method returns an undefined value.

Rewrite subject place's name by using subject transitions.

Parameters:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pione/pnml/input-merge-complement.rb', line 66

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

  source_places = transitions.map do |transition|
    net.find_all_places_by_target_id(transition.id)
  end.flatten

  # build a new name
  new_name = source_places.map do |source_place|
    LabelExtractor.extract_data_expr(source_place.name)
  end.sort.join(" or ")

  # update the place name
  modifier = Perspective.data_modifier(env, place) || ""
  place.name = modifier + new_name
end