Class: YPetri::Net::State::Feature::Marking

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

Overview

Marking of a Petri net place.

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(place) ⇒ Marking

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


51
52
53
# File 'lib/y_petri/net/state/feature/marking.rb', line 51

def initialize place
  @place = net.place( place )
end

Class Attribute Details

.instancesObject (readonly)

Returns the value of attribute instances


33
34
35
# File 'lib/y_petri/net/state/feature/marking.rb', line 33

def instances
  @instances
end

Instance Attribute Details

#placeObject (readonly)

Returns the value of attribute place


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

def place
  @place
end

Class Method Details

.__new__Object


35
# File 'lib/y_petri/net/state/feature/marking.rb', line 35

alias __new__ new

.new(id) ⇒ Object


37
38
39
# File 'lib/y_petri/net/state/feature/marking.rb', line 37

def new id
  instances[ id ]
end

.of(id) ⇒ Object

Alias of #new method.


43
44
45
# File 'lib/y_petri/net/state/feature/marking.rb', line 43

def of id
  new 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
# File 'lib/y_petri/net/state/feature/marking.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.place ]
                               when ç.net.Place then
                                 p = begin
                                       ç.net.place id
                                     rescue TypeError => err
                                       raise TypeError, "Place #{id} not " +
                                         "present in net #{ç.net}! (#{err})"
                                     end
                                 hsh[ id ] = ç.__new__( id )
                               else
                                 hsh[ ç.net.place( id ) ]
                               end
                             end )
  end
end

Instance Method Details

#==(other) ⇒ Object

Marking features are equal if they are of equal PS and refer to the same place.


94
95
96
# File 'lib/y_petri/net/state/feature/marking.rb', line 94

def == other
  other.is_a? net.State.Feature.Marking and place == other.place
end

#extract_from(arg, **nn) ⇒ Object

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


58
59
60
61
62
63
64
65
# File 'lib/y_petri/net/state/feature/marking.rb', line 58

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

#inspectObject

Inspect string of the marking feature.


87
88
89
# File 'lib/y_petri/net/state/feature/marking.rb', line 87

def inspect
  "<Feature::Marking of #{place.name ? place.name : place}>"
end

#labelObject

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


81
82
83
# File 'lib/y_petri/net/state/feature/marking.rb', line 81

def label
  ":#{place.name}"
end

#to_sObject

A string briefly describing the marking feature.


75
76
77
# File 'lib/y_petri/net/state/feature/marking.rb', line 75

def to_s
  "m:#{label}"
end

#typeObject

Type of this feature.


69
70
71
# File 'lib/y_petri/net/state/feature/marking.rb', line 69

def type
  :marking
end