Module: YPetri::Net::ElementAccess

Defined in:
lib/y_petri/net/element_access.rb

Overview

Selections of various kinds of places / transitions (place names / transition names) in a Petri net.

Instance Method Summary collapse

Instance Method Details

#a_transitions(ids = nil) ⇒ Object Also known as: a_tt

a transitions.



167
168
169
170
171
# File 'lib/y_petri/net/element_access.rb', line 167

def a_transitions ids=nil
  return transitions.select &:a? if ids.nil?
  transitions( ids ).aT_all "transition identifiers",
                            "be a (non-assignment)", &:a?
end

#A_transitions(ids = nil) ⇒ Object Also known as: A_tt

A transitions.



153
154
155
156
# File 'lib/y_petri/net/element_access.rb', line 153

def A_transitions ids=nil
  return transitions.select &:A? if ids.nil?
  transitions( ids ).aT_all "transition identifiers", "be A", &:A?
end

#element(id) ⇒ Object

Returns the net’s element identified by the argument



46
47
48
49
50
51
52
# File 'lib/y_petri/net/element_access.rb', line 46

def element id
  begin; place( id ); rescue NameError, TypeError
    begin; transition( id ); rescue NameError, TypeError
      raise TypeError, "The net does not include place/transition #{id}!"
    end
  end
end

#elements(ids = nil) ⇒ Object

Returns the net’s elements identified by the argument’s elements.



56
57
58
59
# File 'lib/y_petri/net/element_access.rb', line 56

def elements ids=nil
  return @places + @transitions if ids.nil?
  ids.map { |id| element id }
end

#en(ids = nil) ⇒ Object

Returns the names of the net’s elements identified by the array.



63
64
65
# File 'lib/y_petri/net/element_access.rb', line 63

def en ids=nil
  elements( ids ).names
end

#include?(id) ⇒ Boolean Also known as: includes?

Inquirer whether the net includes an element.

Returns:

  • (Boolean)


23
24
25
# File 'lib/y_petri/net/element_access.rb', line 23

def include? id
  include_place?( id ) || include_transition?( id )
end

#includes_place?(id) ⇒ Boolean Also known as: include_place?

Does the net include a place?

Returns:

  • (Boolean)


7
8
9
10
11
# File 'lib/y_petri/net/element_access.rb', line 7

def includes_place? id
  begin
    place( id ) and true
  rescue NameError, TypeError; false end
end

#includes_transition?(id) ⇒ Boolean Also known as: include_transition?

Does the net include a transition?

Returns:

  • (Boolean)


16
17
18
# File 'lib/y_petri/net/element_access.rb', line 16

def includes_transition? id
  begin; transition( id ) and true; rescue NameError, TypeError; false end
end

#nA(ids = nil) ⇒ Object

Names of A transitions.



161
162
163
# File 'lib/y_petri/net/element_access.rb', line 161

def nA ids=nil
  A_transitions( ids ).names
end

#na(ids = nil) ⇒ Object

Names of a transitions.



176
177
178
# File 'lib/y_petri/net/element_access.rb', line 176

def na ids=nil
  A_transitions( ids ).names
end

#ns(ids = nil) ⇒ Object

Names of s transitions.



206
207
208
# File 'lib/y_petri/net/element_access.rb', line 206

def ns ids=nil
  s_transitions( ids ).names
end

#nS(ids = nil) ⇒ Object

Names of S transitions.



191
192
193
# File 'lib/y_petri/net/element_access.rb', line 191

def nS ids=nil
  S_transitions( ids ).names
end

#nt(ids = nil) ⇒ Object

Names of t transitions.



236
237
238
# File 'lib/y_petri/net/element_access.rb', line 236

def nt ids=nil
  t_transitions( ids ).names
end

#nT(ids = nil) ⇒ Object

Names of T transitions.



221
222
223
# File 'lib/y_petri/net/element_access.rb', line 221

def nT ids=nil
  T_transitions( ids ).names
end

#nts(ids = nil) ⇒ Object

Names of ts transitions.



105
106
107
# File 'lib/y_petri/net/element_access.rb', line 105

def nts ids=nil
  ts_transitions( ids ).names
end

#nTS(ids = nil) ⇒ Object

Names of TS transitions.



147
148
149
# File 'lib/y_petri/net/element_access.rb', line 147

def nTS ids=nil
  TS_transitions( ids ).names
end

#ntS(ids = nil) ⇒ Object

Names of tS transitions.



119
120
121
# File 'lib/y_petri/net/element_access.rb', line 119

def ntS ids=nil
  tS_transitions( ids ).names
end

#nTs(ids = nil) ⇒ Object

Names of Ts transitions.



133
134
135
# File 'lib/y_petri/net/element_access.rb', line 133

def nTs ids=nil
  Ts_transitions( ids ).names
end

#place(id) ⇒ Object

Returns the net’s place identified by the argument.



30
31
32
33
34
# File 'lib/y_petri/net/element_access.rb', line 30

def place id
  ( super rescue Place().instance( id ) ).tap do |p|
    fail TypeError, "No place #{id} in the net!" unless places.include? p
  end
end

#places(ids = nil) ⇒ Object Also known as: pp

Returns the net’s places identified by the argument’s elements.



69
70
71
72
# File 'lib/y_petri/net/element_access.rb', line 69

def places ids=nil
  return @places.dup if ids.nil?
  ids.map { |id| place id }
end

#pn(ids = nil) ⇒ Object

Names of places in the net.



85
86
87
# File 'lib/y_petri/net/element_access.rb', line 85

def pn ids=nil
  places( ids ).names
end

#S_transitions(ids = nil) ⇒ Object Also known as: S_tt

S transitions.



182
183
184
185
186
# File 'lib/y_petri/net/element_access.rb', line 182

def S_transitions ids=nil
  return transitions.select &:S? if ids.nil?
  transitions( ids ).aT_all "transition identifiers",
                            "be S (stoichiometric)", &:S?
end

#s_transitions(ids = nil) ⇒ Object Also known as: s_tt

s transitions.



197
198
199
200
201
# File 'lib/y_petri/net/element_access.rb', line 197

def s_transitions ids=nil
  return transitions.select &:s? if ids.nil?
  transitions( ids ).aT_all "transition identifiers",
                            "be s (non-stoichiometric)", &:s?
end

#t_transitions(ids = nil) ⇒ Object Also known as: t_tt

t transitions.



227
228
229
230
231
# File 'lib/y_petri/net/element_access.rb', line 227

def t_transitions ids=nil
  return transitions.select &:t? if ids.nil?
  transitions( ids ).aT_all "transition identifiers",
                            "be t (timeless)", &:t?
end

#T_transitions(ids = nil) ⇒ Object Also known as: T_tt

T transitions.



212
213
214
215
216
# File 'lib/y_petri/net/element_access.rb', line 212

def T_transitions ids=nil
  return transitions.select &:T? if ids.nil?
  transitions( ids ).aT_all "transition identifiers",
                            "be T (timed)", &:T?
end

#tn(ids = nil) ⇒ Object

Names of transitions in the net.



91
92
93
# File 'lib/y_petri/net/element_access.rb', line 91

def tn ids=nil
  transitions( ids ).names
end

#transition(id) ⇒ Object

Returns the net’s transition identified by the argument.



38
39
40
41
42
# File 'lib/y_petri/net/element_access.rb', line 38

def transition id
  ( super rescue Transition().instance( id ) ).tap do |t|
    transitions.include? t or fail TypeError, "No transition #{id} in the net!"
  end
end

#transitions(ids = nil) ⇒ Object Also known as: tt

Returns the net’s transitions identified by the argument’s elements.



77
78
79
80
# File 'lib/y_petri/net/element_access.rb', line 77

def transitions ids=nil
  return @transitions.dup if ids.nil?
  ids.map { |id| transition id }
end

#TS_transitions(ids = nil) ⇒ Object Also known as: TS_tt

TS transitions.



139
140
141
142
# File 'lib/y_petri/net/element_access.rb', line 139

def TS_transitions ids=nil
  return transitions.select &:TS? if ids.nil?
  transitions( ids ).aT_all "transition identifiers", "be TS", &:TS?
end

#Ts_transitions(ids = nil) ⇒ Object Also known as: Ts_tt

Ts transitions.



125
126
127
128
# File 'lib/y_petri/net/element_access.rb', line 125

def Ts_transitions ids=nil
  return transitions.select &:Ts? if ids.nil?
  transitions( ids ).aT_all "transition identifiers", "be Ts", &:Ts?
end

#ts_transitions(ids = nil) ⇒ Object Also known as: ts_tt

ts transitions.



97
98
99
100
# File 'lib/y_petri/net/element_access.rb', line 97

def ts_transitions ids=nil
  return transitions.select &:ts? if ids.nil?
  transitions( ids ).aT_all "transition identifiers", "be ts", &:ts?
end

#tS_transitions(ids = nil) ⇒ Object Also known as: tS_tt

tS transitions.



111
112
113
114
# File 'lib/y_petri/net/element_access.rb', line 111

def tS_transitions ids=nil
  return transitions.select &:tS? if ids.nil?
  transitions( ids ).aT_all "transition identifiers", "be tS", &:tS?
end