Sha256: 69aba531a8ad14fea68799110255862d166c82760fc2280b39dcb4b244cbf10e

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

#encoding: utf-8

# A mixin for collections of Ts transitions.
# 
class YPetri::Simulation::Transitions
  module Type_Ts
    include Type_T
    include Type_s

    # gradient closure accessor.
    # 
    def gradient_closure
      @gradient_closure ||= to_gradient_closure
    end

    # Member gradient closures.
    # 
    def gradient_closures
      map &:gradient_closure
    end

    # Gradient contribution for free places.
    # 
    def gradient
      gradient_closure.call
    end

    # Gradient contribution to all places.
    # 
    def ∇
      f2a * gradient
    end
    alias gradient_all ∇

    # Constructs a gradient closure that outputs a gradient vector corresponding
    # to free places. The vector is the gradient contribution of the transitions
    # in this collection.
    # 
    def to_gradient_closure
      fp = free_places
      closures = gradient_closures
      sMV = simulation.MarkingVector
      stu = simulation.time_unit

      code_sections = map.with_index do |t, i|
        "a = closures[ #{i} ].call\n" +
          t.increment_by_codomain_code( vector: "g", source: "a" )
      end
      body = code_sections.join( "\n" )
      λ = <<-LAMBDA
        -> do
        g = sMV.zero( fp ) / stu
        #{body}
        return g
        end
      LAMBDA
      eval λ
    end
  end # module Type_Ts
end # class YPetri::Simulation::Transitions

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
y_petri-2.1.12 lib/y_petri/simulation/transitions/Ts.rb
y_petri-2.1.11 lib/y_petri/simulation/transitions/Ts.rb
y_petri-2.1.10 lib/y_petri/simulation/transitions/Ts.rb
y_petri-2.1.9 lib/y_petri/simulation/transitions/Ts.rb
y_petri-2.1.7 lib/y_petri/simulation/transitions/Ts.rb
y_petri-2.1.6 lib/y_petri/simulation/transitions/Ts.rb
y_petri-2.1.3 lib/y_petri/simulation/transitions/Ts.rb