Module: YPetri::Simulation::MarkingVector::Access
- Defined in:
- lib/y_petri/simulation/marking_vector/access.rb
Instance Method Summary collapse
-
#increment_marking(Δ_free) ⇒ Object
Expects a Δ marking vector for free places and performs the specified change on the marking vector of the simulation.
-
#m(ids = nil) ⇒ Object
Marking of all places (as array).
-
#m_vector(ids = nil) ⇒ Object
Marking of all places (as a column vector).
-
#marking(ids = nil) ⇒ Object
Marking of free places (as array).
-
#marking_vector(ids = nil) ⇒ Object
Marking vector of free places.
-
#p_m(ids = nil) ⇒ Object
(also: #pn_m)
Marking of the indicated places (as hash with place names as keys).
-
#p_marking(ids = nil) ⇒ Object
(also: #pn_marking)
Marking of free places (as hash with place names as keys).
-
#place_m(ids = nil) ⇒ Object
Marking of all places (as hash).
-
#place_marking(ids = nil) ⇒ Object
Marking of free places (as hash).
-
#pm(ids = nil, gap: 0, precision: 3) ⇒ Object
Pretty prints marking of the indicated places as hash with place names as keys.
-
#update_m(new_m) ⇒ Object
Modifies the marking vector.
-
#update_marking(new_m) ⇒ Object
Modifies the marking vector.
Instance Method Details
#increment_marking(Δ_free) ⇒ Object
Expects a Δ marking vector for free places and performs the specified change on the marking vector of the simulation.
109 110 111 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 109 def increment_marking Δ_free @m_vector += f2a * Δ_free end |
#m(ids = nil) ⇒ Object
Marking of all places (as array).
19 20 21 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 19 def m ids=nil m_vector( ids ).to_a end |
#m_vector(ids = nil) ⇒ Object
Marking of all places (as a column vector).
9 10 11 12 13 14 15 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 9 def m_vector ids=nil if ids.nil? then @m_vector or fail TypeError, "Marking vector not established yet!" else m_vector.select( ids ) end end |
#marking(ids = nil) ⇒ Object
Marking of free places (as array).
71 72 73 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 71 def marking ids=nil marking_vector( ids ).to_a end |
#marking_vector(ids = nil) ⇒ Object
Marking vector of free places.
65 66 67 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 65 def marking_vector ids=nil m_vector free_places( ids ) end |
#p_m(ids = nil) ⇒ Object Also known as: pn_m
Marking of the indicated places (as hash with place names as keys).
31 32 33 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 31 def p_m ids=nil places( ids ).names( true ) >> m( ids ) end |
#p_marking(ids = nil) ⇒ Object Also known as: pn_marking
Marking of free places (as hash with place names as keys).
83 84 85 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 83 def p_marking ids=nil marking_vector( ids ).to_h end |
#place_m(ids = nil) ⇒ Object
Marking of all places (as hash).
25 26 27 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 25 def place_m ids=nil m_vector( ids ).to_hash end |
#place_marking(ids = nil) ⇒ Object
Marking of free places (as hash).
77 78 79 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 77 def place_marking ids=nil marking_vector( ids ).to_hash end |
#pm(ids = nil, gap: 0, precision: 3) ⇒ Object
Pretty prints marking of the indicated places as hash with place names as keys. Takes optional list of place ids (ordered argument no. 1), and optional 2 named arguments (:gap
and :precision
), as in #pretty_print_numeric_values
.
41 42 43 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 41 def pm ids=nil, gap: 0, precision: 3 p_m( ids ).pretty_print_numeric_values gap: gap, precision: precision end |
#update_m(new_m) ⇒ Object
Modifies the marking vector. Takes one argument. If the argument is a hash of pairs { place => new value }, only the specified places’ markings are updated. If the argument is an array, it must match the number of places in the simulation, and all marking values are updated.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 50 def update_m new_m case new_m when Hash then # assume { place => marking } hash new_m.each_pair { |id, val| m_vector.set( id, val ) } when Array then msg = "T be a collection with size == number of net's places!" fail TypeError, msg unless new_m.size == places.size update_m( places >> new_m ) else # convert it with #each update_m( new_m.each.to_a ) end end |
#update_marking(new_m) ⇒ Object
Modifies the marking vector. Like #update_m
, but the places must be free places, and if the argument is an array, it must match the number of free places in the simulation’s net.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/y_petri/simulation/marking_vector/access.rb', line 92 def update_marking new_m case new_m when Hash then # assume { place => marking } hash ( free_places( *new_m.keys ) >> new_m.values ) .each_pair { |id, val| m_vector.set( id, val ) } when Array then msg = "T be a collection with size == number of net's free places!" fail TypeError, msg unless new_m.size == free_places.size update_m( free_places >> new_m ) else # convert it with #each update_marking( new_m.each.to_a ) end end |