Class: YPetri::Net::State::Feature::Gradient
- Inherits:
-
YPetri::Net::State::Feature
- Object
- YPetri::Net::State::Feature
- YPetri::Net::State::Feature::Gradient
- Defined in:
- lib/y_petri/net/state/feature/gradient.rb
Overview
Gradient of a Petri net place caused by a certain set of T transitions.
Class Attribute Summary collapse
-
.instances ⇒ Object
readonly
Returns the value of attribute instances.
Instance Attribute Summary collapse
-
#place ⇒ Object
readonly
Returns the value of attribute place.
-
#transitions ⇒ Object
(also: #tt)
readonly
Returns the value of attribute transitions.
Class Method Summary collapse
- .__new__ ⇒ Object
-
.new(*args) ⇒ Object
(also: of)
Constructor #new is redefined to use instance cache.
-
.parametrize(*args) ⇒ Object
Customization of the Class#parametrize method.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Gradient features are equal if they are of equal PS and refer to the same place and transition set.
-
#extract_from(arg, **nn) ⇒ Object
Extracts the receiver gradient feature from the argument.
-
#initialize(*id) ⇒ Gradient
constructor
The constructor of a gradient feature takes one ordered argument (place identifier), and one named argument,
:transitions
, expecting an array of transition identifiers, whose contribution is taken into account in this gradient feature. -
#inspect ⇒ Object
Inspect string of the gradient feature.
-
#label ⇒ Object
Label for the gradient feature (to use in graphics etc.).
-
#to_s ⇒ Object
A string briefly describing the gradient feature.
-
#type ⇒ Object
Type of this feature.
Methods inherited from YPetri::Net::State::Feature
#%, Assignment, Delta, Firing, Flux, Gradient, Marking, infer_from_node
Constructor Details
#initialize(*id) ⇒ Gradient
The constructor of a gradient feature takes one ordered argument (place identifier), and one named argument, :transitions
, expecting an array of transition identifiers, whose contribution is taken into account in this gradient feature.
68 69 70 71 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 68 def initialize *id @place = net.place id.fetch( 0 ) @transitions = net.Transitions id.fetch( 1 ).fetch( :transitions ) end |
Class Attribute Details
.instances ⇒ Object (readonly)
Returns the value of attribute instances.
50 51 52 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 50 def instances @instances end |
Instance Attribute Details
#place ⇒ Object (readonly)
Returns the value of attribute place.
6 7 8 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 6 def place @place end |
#transitions ⇒ Object (readonly) Also known as: tt
Returns the value of attribute transitions.
6 7 8 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 6 def transitions @transitions end |
Class Method Details
.__new__ ⇒ Object
52 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 52 alias __new__ new |
.new(*args) ⇒ Object Also known as: of
Constructor #new is redefined to use instance cache.
56 57 58 59 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 56 def new *args return instances[ *args ] if args.size == 1 instances[ args ] end |
.parametrize(*args) ⇒ Object
Customization of the Class#parametrize method.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 12 def parametrize *args Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç| # First, prepare the hash of instances. hsh = Hash.new do |ꜧ, id| if id.is_a? self then ꜧ[ [ id.place, transitions: id.transitions.sort_by( &:object_id ) ] ] else p = id.fetch( 0 ) tt = id.fetch( 1 ).fetch( :transitions ) tt_array = Array( tt ) if tt == tt_array then if p.is_a? ç.net.Place and tt.all? { |t| t.is_a? ç.net.Transition } tt_sorted = tt.sort_by &:object_id if tt == tt_sorted then tt = begin ç.net.T_Transitions( tt ) rescue TypeError => err msg = "Transitions #{tt} not recognized as T " + "transitions in net #{ç.net}! (%s)" raise TypeError, msg % err end ꜧ[ id ] = ç.__new__( *id ) else ꜧ[ [ p, transitions: tt.sort_by( &:object_id ) ] ] end else ꜧ[ [ ç.net.place( p ), transitions: ç.net.Transitions( tt ) ] ] end else ꜧ[ [ p, transitions: tt_array ] ] end end end # And then, assign it to the :@instances variable. ç.instance_variable_set :@instances, hsh end end |
Instance Method Details
#==(other) ⇒ Object
Gradient features are equal if they are of equal PS and refer to the same place and transition set.
118 119 120 121 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 118 def == other other.is_a? net.State.Feature.Gradient and place == other.place && transitions == other.transitions end |
#extract_from(arg, **nn) ⇒ Object
Extracts the receiver gradient feature from the argument. This can be typically a simulation instance.
76 77 78 79 80 81 82 83 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 76 def extract_from arg, **nn case arg when YPetri::Simulation then arg.send( :T_Transitions, transitions ).gradient.fetch( place ) else fail TypeError, "Argument type not supported!" end end |
#inspect ⇒ Object
Inspect string of the gradient feature.
110 111 112 113 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 110 def inspect "<Feature::Gradient ∂:#{place.name || place}:[%s]>" % transitions.names( true ).join( ', ' ) end |
#label ⇒ Object
Label for the gradient feature (to use in graphics etc.)
99 100 101 102 103 104 105 106 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 99 def label "∂:#{place.name}:%s" % if transitions.size == 1 then transitions.first.name || transitions.first else "#{transitions.size}tt" end end |
#to_s ⇒ Object
A string briefly describing the gradient feature.
93 94 95 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 93 def to_s label end |
#type ⇒ Object
Type of this feature.
87 88 89 |
# File 'lib/y_petri/net/state/feature/gradient.rb', line 87 def type :gradient end |