Sha256: b6f2b3851718287977d448fbfcb18c67d288a51a83a1c307c0833809add31f12

Contents?: true

Size: 1.72 KB

Versions: 39

Compression:

Stored size: 1.72 KB

Contents

#encoding: utf-8

# Simulation mixin providing access to the initial marking.
#
class YPetri::Simulation::InitialMarking
  module Access
    # Without arguments, acts as a getter of @initial_marking. If arguments are
    # supplied, they must identify free places, and are mapped to their initial
    # marking.
    # 
    def initial_marking ids=nil
      if ids.nil? then
        @initial_marking or
          fail TypeError, "InitialMarking object not instantiated yet!"
      else
        free_places( ids ).map { |pl| initial_marking[ place( pl ) ] }
      end
    end

    # Without arguments, returns the marking of all the simulation's places
    # (both free and clamped) as it appears after reset. If arguments are
    # supplied, they must identify places, and are converted to either their
    # initial marking (free places), or their clamp value (clamped places).
    # 
    def im ids=nil
      return im( places ) if ids.nil?
      places( ids ).map { |pl|
        pl.free? ? initial_marking( of: pl ) : marking_clamp( of: pl )
      }
    end

    # Returns initial marking vector for free places. Like +#initial_marking+,
    # but returns a column vector.
    # 
    def initial_marking_vector ids=nil
      initial_marking( ids ).to_column_vector
    end

    # Returns initial marking vector for all places. Like +#initial_marking+,
    # but returns a column vector.
    # 
    def im_vector ids=nil
      im( ids ).to_column_vector
    end

    private

    # Sets the initial marking of a place (frontend of +InitialMarking#set+).
    # 
    def set_initial_marking( of: (fail ArgumentError), to: (fail ArgumentError) )
      initial_marking.set( of, to: to )
    end
  end # module Access
end # class YPetri::Simulation::InitialMarking

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
y_petri-2.2.4 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.2.3 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.2.2 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.2.1 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.2.0 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.51 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.50 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.49 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.48 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.47 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.46 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.45 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.44 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.42 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.40 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.39 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.37 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.36 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.35 lib/y_petri/simulation/initial_marking/access.rb
y_petri-2.1.34 lib/y_petri/simulation/initial_marking/access.rb