Class: YPetri::Simulation::PlaceMapping

Inherits:
Hash
  • Object
show all
Defined in:
lib/y_petri/simulation/place_mapping.rb

Direct Known Subclasses

InitialMarking, MarkingClamps

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(hash) ⇒ Object

Initializes the initial marking from a hash.



12
13
14
15
16
17
18
19
# File 'lib/y_petri/simulation/place_mapping.rb', line 12

def load hash
  new.tap do |inst|
    hash.with_values do |v|
      v = v.marking if v.is_a? YPetri::Place
      if v.is_a? Proc then v.call else v end
    end.tap &inst.method( :load )
  end
end

Instance Method Details

#delete(place_id) ⇒ Object

Deletes the value for a place.



53
54
55
# File 'lib/y_petri/simulation/place_mapping.rb', line 53

def delete place_id
  super place( place_id )
end

#fetch(place_id) ⇒ Object

Fetches the value for a place.



47
48
49
# File 'lib/y_petri/simulation/place_mapping.rb', line 47

def fetch place_id
  super place( place_id )
end

#keys_to_source_placesObject

Returns a hash, whose keys have been replaced with source places of the place representations in this place mapping.



60
61
62
# File 'lib/y_petri/simulation/place_mapping.rb', line 60

def keys_to_source_places
  with_keys do |key| key.source end
end

#load(hash) ⇒ Object

Loads initial the mappings from a hash places >> values.



41
42
43
# File 'lib/y_petri/simulation/place_mapping.rb', line 41

def load( hash )
  hash.each { |place, value| set place, to: value }
end

#set(place_id, to: (fail ArgumentError, "No :to value!")) ⇒ Object

Sets the mapping value for a given place to a given value.



35
36
37
# File 'lib/y_petri/simulation/place_mapping.rb', line 35

def set place_id, to: (fail ArgumentError, "No :to value!")
  update place( place_id ) => to
end

#vectorObject Also known as: to_marking_vector

Returns the initial marking as a column vector.



28
29
30
# File 'lib/y_petri/simulation/place_mapping.rb', line 28

def vector
  simulation.MarkingVector[ *self ]
end