Module: YPetri::Place::Arcs

Defined in:
lib/y_petri/place/arcs.rb

Overview

Connectivity aspect of a Petri net place.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#downstream_arcsObject (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_arcsObject (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

#arcsObject

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

#dependentsObject 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_netObject

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_downstreamObject

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_recursivelyObject

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_upstreamObject

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_recursivelyObject

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_netObject

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

#precedentsObject 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_netObject

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