Module: YPetri::Agent::PetriNetAspect

Defined in:
lib/y_petri/agent/petri_net_aspect.rb

Overview

Petri net aspect of YPetri::Agent.

Constant Summary collapse

NetSelection =

A class representing a selection of nets.

Class.new YPetri::Agent::Selection

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#net_pointObject

Net point.



12
13
14
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 12

def net_point
  @net_point
end

#net_selectionObject (readonly)

Net selection.



16
17
18
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 16

def net_selection
  @net_selection
end

Instance Method Details

#AT(*codomain, **nn, &block) ⇒ Object

Assignment transition constructor: Creates a new assignment transition in the current world. Ordered arguments are collected as codomain. Domain key (+:domain) is optional. Assignment closure must be supplied in a block.



83
84
85
86
87
88
89
90
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 83

def AT( *codomain, **nn, &block )
  fail ArgumentError, "Assignment transition constructor requires a block " +
    "defining the assignment function!" unless block
  world.Transition.send( :new,
                         codomain: codomain,
                         assignment: block,
                         **nn )
end

#initializeObject

Standard initialization method. Takes no arguments.



20
21
22
23
24
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 20

def initialize
  net_point_reset
  @net_selection = NetSelection.new
  super
end

#net(id = nil) ⇒ Object

Returns the net identified, or the net at point (if no argument given).



150
151
152
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 150

def net id=nil
  id.nil? ? @net_point : world.net( id )
end

#Net(*ordered, of: nil, **named, &block) ⇒ Object

Net constructor: Creates a new Net instance in the current world.



140
141
142
143
144
145
146
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 140

def Net *ordered, of: nil, **named, &block
  if of.nil? then
    world.Net.send( :new, *ordered, **named, &block )
  else
    world.Net.of( of, *ordered, **named, &block )
  end
end

#net_point_reset(id = world.Net.instance( :Top )) ⇒ Object

Sets the net point to a given net, or to world.Net::Top if none given.



156
157
158
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 156

def net_point_reset id=world.Net.instance( :Top )
  @net_point = world.net( id )
end

#nnObject

Names of the nets.



58
59
60
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 58

def nn
  nets.names
end

#pl(place_id) ⇒ Object

Returns the name of a place identified by the argument.



34
35
36
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 34

def pl( place_id )
  place( place_id ).name
end

#Place(*ordered_args, **named_args, &block) ⇒ Object

Constructor of a place: Creates a new place in the current world.



64
65
66
67
68
69
70
71
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 64

def Place( *ordered_args, **named_args, &block )
  fail ArgumentError, "If block is given, :guard named argument " +
    "must not be given!" if named_args.has? :guard if block
  named_args.update( guard: block ) if block # use block as a guard
  named_args.may_have :default_marking, syn!: :m!
  named_args.may_have :marking, syn!: :m
  world.Place.send( :new, *ordered_args, **named_args, &block )
end

#pnObject

Names of the places.



46
47
48
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 46

def pn
  places.names
end

#tnObject

Names of the transitions.



52
53
54
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 52

def tn
  transitions.names
end

#tr(transition_id) ⇒ Object

Returns the name of a transition identified by the argument.



40
41
42
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 40

def tr( transition_id )
  transition( transition_id ).name
end

#Transition(*ordered, **named, &block) ⇒ Object

Constructor of a transition: Creates a new transition in the current world.



75
76
77
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 75

def Transition( *ordered, **named, &block )
  world.Transition.send( :new, *ordered, **named, &block )
end

#TS(*domain, **stoichiometry, &block) ⇒ Object

Timed stoichiometric transition constructor, that expects stoichiometry given directly as hash-collected arguments. Two special keys allowed are :name (alias +:ɴ) and :domain. (Key :codomain is not allowed.)



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 110

def TS *domain, **stoichiometry, &block
  nn = stoichiometry
  args = { s: nn }
  args.update name: nn.delete( :name ) if nn.has? :name, syn!: 
  if domain.empty? then
    args.update domain: nn.delete( :domain ) if nn.has? :domain
  else
    fail ArgumentError, "There must not be any ordered arguments if " +
      "named argument :domain is given!" if nn.has? :domain
    args.update domain: domain
  end
  args.update rate: nn.delete( :rate ) if nn.has? :rate, syn!: :rate_closure
  TT **args, &block
end

#TT(*ordered, **named, &block) ⇒ Object

Timed transition constructor: Creates a new timed transition in the current world. Rate can be supplied either as :rate named argument, or as a block. If none is supplied, rate argument defaults to 1.



96
97
98
99
100
101
102
103
104
# File 'lib/y_petri/agent/petri_net_aspect.rb', line 96

def TT( *ordered, **named, &block )
  if named.has? :rate then
    fail ArgumentError, "Block must not be given if :rate named argument " +
      "is given!" if block
  else
    named.update rate: block || 1 # default rate is 1
  end
  world.Transition.send( :new, *ordered, **named )
end