Class: YPetri::Net::State::Feature::Flux

Inherits:
YPetri::Net::State::Feature show all
Defined in:
lib/y_petri/net/state/feature/flux.rb

Overview

Flux of a Petri net TS transition.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from YPetri::Net::State::Feature

#%, Assignment, Delta, Firing, Flux, Gradient, Marking, infer_from_node

Constructor Details

#initialize(id) ⇒ Flux

The constructor of a marking feature takes exactly one argument (transition identifier).


53
54
55
# File 'lib/y_petri/net/state/feature/flux.rb', line 53

def initialize id
  @transition = net.transition id.is_a?( Flux ) ? id.transition : id
end

Class Attribute Details

.instancesObject (readonly)

Returns the value of attribute instances


35
36
37
# File 'lib/y_petri/net/state/feature/flux.rb', line 35

def instances
  @instances
end

Instance Attribute Details

#transitionObject (readonly)

Returns the value of attribute transition


6
7
8
# File 'lib/y_petri/net/state/feature/flux.rb', line 6

def transition
  @transition
end

Class Method Details

.__new__Object


37
# File 'lib/y_petri/net/state/feature/flux.rb', line 37

alias __new__ new

.new(id) ⇒ Object


39
40
41
# File 'lib/y_petri/net/state/feature/flux.rb', line 39

def new id
  instances[ id ]
end

.of(transition_id) ⇒ Object

Alias of #new method.


45
46
47
# File 'lib/y_petri/net/state/feature/flux.rb', line 45

def of transition_id
  new transition_id
end

.parametrize(*args) ⇒ Object

Customization of the Class#parametrize method.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/y_petri/net/state/feature/flux.rb', line 11

def parametrize *args
  Class.instance_method( :parametrize ).bind( self ).( *args ).tap do |ç|
    ç.instance_variable_set( :@instances,
                             Hash.new do |hsh, id|
                               case id
                               when self then
                                 hsh[ id.transition ]
                               when ç.net.Transition then
                                 t = begin
                                       ç.net.TS_transitions( id ).first
                                     rescue TypeError => err
                                       msg = "Transition #{id} not " +
                                         "recognized as TS transition in " +
                                         "net #{ç.net}! (%s)"
                                       raise TypeError, msg % err
                                     end
                                 hsh[ id ] = ç.__new__( t )
                               else
                                 hsh[ ç.net.transition( id ) ]
                               end
                             end )
  end
end

Instance Method Details

#==(other) ⇒ Object

Flux features are equal if they are of equal PS and refer to the same transition.


96
97
98
# File 'lib/y_petri/net/state/feature/flux.rb', line 96

def == other
  other.is_a? net.State.Feature.Flux and transition == other.transition
end

#extract_from(arg, **nn) ⇒ Object

Extracts the receiver marking feature from the argument. This can be typically a simulation instance.


60
61
62
63
64
65
66
67
# File 'lib/y_petri/net/state/feature/flux.rb', line 60

def extract_from arg, **nn
  case arg
  when YPetri::Simulation then
    arg.send( :TS_transitions, transition ).first.flux
  else
    fail TypeError, "Argument type not supported!"
  end
end

#inspectObject

Inspect string of the flux feature.


89
90
91
# File 'lib/y_petri/net/state/feature/flux.rb', line 89

def inspect
  "<Feature::Flux of #{transition.name ? transition.name : transition}>"
end

#labelObject

Label for the flux feature (to use in the graphics etc.)


83
84
85
# File 'lib/y_petri/net/state/feature/flux.rb', line 83

def label
  "Φ:#{transition.name}"
end

#to_sObject

A string briefly describing the flux feature.


77
78
79
# File 'lib/y_petri/net/state/feature/flux.rb', line 77

def to_s
  label
end

#typeObject

Type of this feature.


71
72
73
# File 'lib/y_petri/net/state/feature/flux.rb', line 71

def type
  :flux
end