Module: YPetri::Place::Arcs
- Defined in:
- lib/y_petri/place/arcs.rb
Overview
Connectivity aspect of a Petri net place.
Instance Attribute Summary collapse
-
#downstream_arcs ⇒ Object
(also: #downstream_transitions)
readonly
Transitions whose action directly depends on this place.
-
#upstream_arcs ⇒ Object
(also: #upstream_transitions, #ϝ)
readonly
Transitions that can directly add/remove tokens from this place.
Instance Method Summary collapse
-
#aa(arg = nil) ⇒ Object
Names of the transitions connected to the place.
-
#arc(id) ⇒ Object
Arc (a transition connected to this place) identifier.
-
#arcs ⇒ Object
All the transitions connected to the place.
-
#dependents ⇒ Object
(also: #downstream_places)
Union of the codomains of the downstream transitions.
-
#downstream_net ⇒ Object
A net containing all the upstream transitions and their connected places.
-
#fire_downstream ⇒ Object
Fires the downstream transitions.
-
#fire_downstream! ⇒ Object
Fires the downstream transitions regardless of cocking.
-
#fire_downstream_recursively ⇒ Object
Fires the whole downstream portion of the net.
-
#fire_upstream ⇒ Object
Fires the upstream transitions.
-
#fire_upstream! ⇒ Object
Fires the upstream transitions regardless of cocking.
-
#fire_upstream_recursively ⇒ Object
Fires the whole upstream portion of the net.
-
#local_net ⇒ Object
A union of upstream local net and downstream local net.
-
#precedents ⇒ Object
(also: #upstream_places)
Union of the domains of the upstream transitions.
-
#upstream_net ⇒ Object
A net containing all the upstream transitions and their connected places.
Instance Attribute Details
#downstream_arcs ⇒ Object (readonly) Also known as: downstream_transitions
Transitions whose action directly depends on this place. Aliased as #downstream_transitions
.
17 18 19 |
# File 'lib/y_petri/place/arcs.rb', line 17 def downstream_arcs @downstream_arcs end |
#upstream_arcs ⇒ Object (readonly) Also known as: upstream_transitions, ϝ
Transitions that can directly add/remove tokens from this place. Aliased as #upstream_transitions
and #ϝ. (Digamma resembles “f”, meaning function, well known from existing spreadsheet software.)
10 11 12 |
# File 'lib/y_petri/place/arcs.rb', line 10 def upstream_arcs @upstream_arcs end |
Instance Method Details
#aa(arg = nil) ⇒ Object
Names of the transitions connected to the place. The optional argument controls what is returned for unnamed instances, and works just like in Array#names
method from y_support/name_magic
: The default value (nil) returns nil, true returns the instance itself, and false drops the unnamed instances from the list altogether.
32 33 34 |
# File 'lib/y_petri/place/arcs.rb', line 32 def aa arg=nil arcs.names arg end |
#arc(id) ⇒ Object
Arc (a transition connected to this place) identifier.
38 39 40 41 42 |
# File 'lib/y_petri/place/arcs.rb', line 38 def arc id transition = transition( id ) arcs.find { |t| t == transition } or fail TypeError, "No transition #{id} connected to #{self}!" end |
#arcs ⇒ Object
All the transitions connected to the place.
22 23 24 |
# File 'lib/y_petri/place/arcs.rb', line 22 def arcs upstream_arcs | downstream_arcs end |
#dependents ⇒ Object Also known as: downstream_places
Union of the codomains of the downstream transitions.
53 54 55 |
# File 'lib/y_petri/place/arcs.rb', line 53 def dependents downstream_transitions.map( &:downstream_places ).reduce( [], :| ) end |
#downstream_net ⇒ Object
A net containing all the upstream transitions and their connected places.
70 71 72 73 74 75 76 |
# File 'lib/y_petri/place/arcs.rb', line 70 def downstream_net net_klass = world.Net rescue YPetri::Net # for when not used as PS downstream_transitions.each_with_object net_klass.send( :new ) do |t, net| t.arcs.each { |place| net << place } net << t end end |
#fire_downstream ⇒ Object
Fires the downstream transitions.
107 108 109 |
# File 'lib/y_petri/place/arcs.rb', line 107 def fire_downstream downstream_arcs.each &:fire end |
#fire_downstream! ⇒ Object
Fires the downstream transitions regardless of cocking. (Normally, transitions should be cocked (#cock
method) before they are fired (#fire
method).)
115 116 117 |
# File 'lib/y_petri/place/arcs.rb', line 115 def fire_downstream! @downstream_arcs.each &:fire! end |
#fire_downstream_recursively ⇒ Object
Fires the whole downstream portion of the net. Cocking ensures that the recursive firing will eventually end.
122 123 124 125 |
# File 'lib/y_petri/place/arcs.rb', line 122 def fire_downstream_recursively # LATER: This as a global hash { place => fire_list } @downstream_arcs.each &:fire_downstream_recursively end |
#fire_upstream ⇒ Object
Fires the upstream transitions.
86 87 88 |
# File 'lib/y_petri/place/arcs.rb', line 86 def fire_upstream upstream_arcs.each &:fire end |
#fire_upstream! ⇒ Object
Fires the upstream transitions regardless of cocking. (Normally, transitions should be cocked (#cock
method) before they are fired (#fire
method).)
93 94 95 |
# File 'lib/y_petri/place/arcs.rb', line 93 def fire_upstream! upstream_arcs.each &:fire! end |
#fire_upstream_recursively ⇒ Object
Fires the whole upstream portion of the net. Cocking ensures that the recursive firing will eventually end.
100 101 102 103 |
# File 'lib/y_petri/place/arcs.rb', line 100 def fire_upstream_recursively # LATER: This as a global hash { place => fire_list } @upstream_arcs.each &:fire_upstream_recursively end |
#local_net ⇒ Object
A union of upstream local net and downstream local net.
80 81 82 |
# File 'lib/y_petri/place/arcs.rb', line 80 def local_net downstream_net + upstream_net end |
#precedents ⇒ Object Also known as: upstream_places
Union of the domains of the upstream transitions.
46 47 48 |
# File 'lib/y_petri/place/arcs.rb', line 46 def precedents upstream_transitions.map( &:upstream_places ).reduce( [], :| ) end |
#upstream_net ⇒ Object
A net containing all the upstream transitions and their connected places.
60 61 62 63 64 65 66 |
# File 'lib/y_petri/place/arcs.rb', line 60 def upstream_net net_klass = world.Net rescue YPetri::Net # for when not used as PS upstream_transitions.each_with_object net_klass.send( :new ) do |t, net| t.arcs.each { |place| net << place } net << t end end |