Class: YPetri::Core::Timed

Inherits:
Object
  • Object
show all
Defined in:
lib/y_petri/core/timed.rb

Overview

Timed simulation core. Knows several simulation methods applicable to timed nets.

Defined Under Namespace

Modules: Basic, Euler, Gillespie, RungeKutta, Ticked

Constant Summary collapse

METHODS =
{
  basic: Basic,   # simple PN execution, timeless tt fire after each step
  ticked: Ticked, # like basic, but timeless tt fire at every time tick
  euler: Euler,               # for timed nets only
  runge_kutta: RungeKutta,    # for timed nets only
  gillespie: Gillespie        # for timed nets only
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**named_args) ⇒ Timed

Returns a new instance of Timed.



34
35
36
37
38
39
40
# File 'lib/y_petri/core/timed.rb', line 34

def initialize **named_args
  super                       # TODO: Net type checking.
  @time = 0.0
  extend METHODS.fetch simulation_method
  @delta_s = simulation.MarkingVector.zero( @free_pp )
  @delta_S = simulation.MarkingVector.zero( @free_pp )
end

Instance Attribute Details

#timeObject (readonly)

From now on, core has its own time attribute and selector.



24
25
26
# File 'lib/y_petri/core/timed.rb', line 24

def time
  @time
end

Instance Method Details

#flux_vectorObject

Flux vector. The caller asserts that all the timed transitions are stoichiometric, or error.



83
84
85
86
87
88
# File 'lib/y_petri/core/timed.rb', line 83

def flux_vector
  msg = "#flux_vector method only applies to the timed simulations with " +
    "no Ts transitions. Try #flux_vector_TS instead!"
  fail msg unless Ts_transitions().empty?
  simulation.TS_rate_closure.call
end

#flux_vector_TSObject Also known as: propensity_vector_TS

Flux vector of TS transitions.



92
93
94
# File 'lib/y_petri/core/timed.rb', line 92

def flux_vector_TS
  simulation.TS_rate_closure.call
end

#gradientObject Also known as:

Gradient for free places.



61
62
63
# File 'lib/y_petri/core/timed.rb', line 61

def gradient
  gradient_Ts + gradient_TS
end

#gradient_TSObject

Gradient contribution by TS transitions.



76
77
78
# File 'lib/y_petri/core/timed.rb', line 76

def gradient_TS
  ( simulation.TS_stoichiometry_matrix * flux_vector_TS )
end

#gradient_TsObject

Gradient contribution by Ts transitions.



68
69
70
71
72
# File 'lib/y_petri/core/timed.rb', line 68

def gradient_Ts
  simulation.Ts_gradient_closure.call
  # this could be
  # @Ts_gradient_closure.call
end

#increment_time!(Δt) ⇒ Object

Increments core time by Δt.



44
45
46
# File 'lib/y_petri/core/timed.rb', line 44

def increment_time! Δt
  @time += Δt
end

#step!(Δt = simulation.step) ⇒ Object

Makes a single step by Δt.



50
51
52
53
54
55
56
57
# File 'lib/y_petri/core/timed.rb', line 50

def step! Δt=simulation.step
  # TODO: This one will act directly upon simulation. Subject of potential
  # change later.
  increment_marking_vector Δ( Δt )
  # TODO: The bottom two, obviously, act directly upon simulation.
  simulation.increment_time! Δt
  simulation.recorder.alert
end

#timed?Boolean

This inquirer (=Boolean selector) is always true for timed cores.

Returns:

  • (Boolean)


28
# File 'lib/y_petri/core/timed.rb', line 28

def timed?; true end

#timeless?Boolean

This inquirer (=Boolean selector) is always false for timed cores.

Returns:

  • (Boolean)


32
# File 'lib/y_petri/core/timed.rb', line 32

def timeless?; false end