module YPetri::Core

This module represents a simulation core (execution machine), which can be either timed (class Core::Timed) or timeless (class Core::Timeless).

Constants

DEFAULT_METHOD

Attributes

clamped_pp[R]
free_pp[R]
guarded[R]
guarded?[R]
marking_of_clamped_places[R]
marking_of_free_places[R]
pp[R]
simulation[R]

Instead of getting the parametrized subclass of Timed/Timeless core belonging to a simulation, I am passing a simulation instance to the constructor now in order to gradually begin decoupling in my mind core simulation. If I ever make the core independent from the simulation, it will have its own representation of the net and its own capability to form wiring and apply the required numerical procedures.

simulation_method[R]

Public Class Methods

new(simulation: nil, method: nil, guarded: false, **named_args) click to toggle source
# File lib/y_petri/core.rb, line 32
def initialize simulation: nil, method: nil, guarded: false, **named_args
  @simulation = simulation or fail ArgumentError, "Core requires simulation!"
  @simulation_method = method || DEFAULT_METHOD

  if guarded then            # TODO: Guarded is unfinished business.
    fail NotImplementedMethod, "Guarded core is not implemented yet!"
    require_relative 'core/guarded' # TODO: Should be replaced with autoload.
  else @guarded = false end

  @free_pp = simulation.free_pp
  @clamped_pp = simulation.clamped_pp
  @pp = simulation.pp
  # TODO: Try to make the lines below simpler. In particular, in the future, core should
  # not depend on simulation at this level.
  @marking_of_free_places = simulation.MarkingVector.starting( @free_pp )
  @marking_of_clamped_places = simulation.MarkingVector.starting( @clamped_pp )

  # TODO: I don't remember how to load this in a simple way.
  simulation.state.to_hash.each do |place, value|
    if @marking_of_free_places.annotation.include? place then
      @marking_of_free_places.set( place, value )
    elsif @marking_of_clamped_places.annotation.include? place then
      @marking_of_clamped_places.set( place, value )
    else
      fail "Problem loading marking vector to timed core."
    end
  end
end

Public Instance Methods

assignment_transitions_all_fire!()
delta_t()
Alias for: delta_timeless
delta_tS() click to toggle source

Delta contribution by tS transitions.

# File lib/y_petri/core.rb, line 87
def delta_tS
  simulation.tS_stoichiometry_matrix * firing_vector_tS
end
delta_timeless() click to toggle source

Delta contribution to free places by timeless transitions.

# File lib/y_petri/core.rb, line 80
def delta_timeless
  delta_ts + delta_tS
end
Also aliased as: delta_t
delta_ts() click to toggle source

Delta contribution by ts transitions.

# File lib/y_petri/core.rb, line 93
def delta_ts
  simulation.ts_delta_closure.call
  # @delta_closure_for_ts_transitions.call
end
fire_all_assignment_transitions!() click to toggle source

Fires all the assignment transitions.

# File lib/y_petri/core.rb, line 129
def fire_all_assignment_transitions!
  simulation.A_direct_assignment_closure.call
  # @assignment_closure_for_A_transitions.call
end
firing_vector_tS() click to toggle source

Firing vector of tS transitions.

# File lib/y_petri/core.rb, line 100
def firing_vector_tS
  simulation.tS_firing_closure.call
  # @firing_closure_for_tS_transitions.call
end
increment_free_vector( by: fail( "No delta given!" ) ) click to toggle source

For now, alias method for increment_marking_vector. TODO: I already said to myself that I want the core not to rely on the simulation's increment_marking_vector_closure.

# File lib/y_petri/core.rb, line 119
def increment_free_vector( by: fail( "No delta given!" ) )
  print '.'
  simulation.increment_marking_vector_closure.( by )
  # Also, here it is not clear that #increment_marking_vector_closure
  # returns a closure that expects only Δ for free places. Should have
  # better mnemonic name.
end
increment_marking_vector( delta ) click to toggle source

Increments the marking vector by a given delta.

# File lib/y_petri/core.rb, line 107
def increment_marking_vector( delta )
  print '.'
  # TODO: From now on, this won't touch the simulation's property
  # at all. It will be left to the simulation to ask for the results,
  # or to rig the core to message back when done.
  simulation.increment_marking_vector_closure.( delta )
end
state() click to toggle source

Selector of the core's own state vector.

# File lib/y_petri/core.rb, line 63
def state
  # TODO: Make it more efficient. Later, when core is detached from
  # simulation, use own assets instead of simulation.MarkingVector
  simulation.MarkingVector.zero.tap do |mv|
    @marking_of_free_places.annotation.each do |place|
      mv.set place, @marking_of_free_places.fetch( place )
    end
    @marking_of_clamped_places.annotation.each do |place|
      mv.set place, @marking_of_clamped_places.fetch( place )
    end
  end
end