module YPetri::World::SimulationAspect
Workspace instance methods related to the Simulation aspect of YPetri
(stored marking collections, clamp collections, inital marking collections, management of simulations…)
Workspace instance methods related to the Simulation aspect of YPetri
(stored marking collections, clamp collections, inital marking collections, management of simulations…)
Attributes
Collections of clamps, initial marking vectors, and simulation settings.
Collections of clamps, initial marking vectors, and simulation settings.
Collections of clamps, initial marking vectors, and simulation settings.
Public Class Methods
Instance initialization.
# File lib/y_petri/world/simulation_aspect.rb, line 16 def initialize @simulations = {} # { simulation => its settings } @clamp_collections = { Base: {} } # { collection name => clamp hash } @initial_marking_collections = { Base: {} } # { collection name => im hash } @simulation_settings_collections = # { collection name => ss hash } { Base: ( YPetri::Simulation::DEFAULT_SETTINGS.call .update YPetri::Simulation::Timed::DEFAULT_SETTINGS.call ) } super end
Public Instance Methods
Clamp collection identified by the argument.
# File lib/y_petri/world/simulation_aspect.rb, line 55 def clamp_collection name=:Base @clamp_collections[name] end
Clamp collection names.
# File lib/y_petri/world/simulation_aspect.rb, line 34 def clamp_collection_names @clamp_collections.keys end
Marking collection identified by the argument.
# File lib/y_petri/world/simulation_aspect.rb, line 62 def initial_marking_collection name=:Base @initial_marking_collections[name] end
Initial marking collection names.
# File lib/y_petri/world/simulation_aspect.rb, line 41 def initial_marking_collection_names @initial_marking_collections.keys end
Makes a new timed simulation. Named arguments for this method are the same as for TimedSimulation#new, but in addition, :name can be supplied.
To create a simulation, simulation settings collection, initial marking collection, and clamp collection have to be specified. A place clamp, is a fixed value, at which the marking is held. Similarly, initial marking is the marking, which a free place receives at the beginning. Free places are those, that are not clamped. After initialization, marking of free places is allowed to change as the transition fire.
For example, having places :P1..:P5, clamped :P1, :P2 can be written as eg.:
-
clamps = { P1: 4, P2: 5 }
Places :P3, :P4, :P5 are free. Their initial marking has to be specified, which can be written as eg.:
-
initial_markings = { P3: 1, P4: 2, P5: 3 }
As for simulation settings, their exact nature depends on the simulation method. For default Euler method, there are 3 important parameters:
- <em>step_size</em>, - <em>sampling_period</em>, - <em>target_time</em>
For example, default simulation settings are:
-
default_ss = { step_size: 0.1, sampling_period: 5, target_time: 60 }
# File lib/y_petri/world/simulation_aspect.rb, line 148 def new_simulation( net: Net()::Top, **nn ) net_inst = net( net ) nn.may_have :cc, syn!: :clamp_collection nn.may_have :imc, syn!: :initial_marking_collection nn.may_have :ssc, syn!: :simulation_settings_collection cc_id = nn.delete( :cc ) || :Base imc_id = nn.delete( :imc ) || :Base ssc_id = nn.delete( :ssc ) || :Base # Construct the simulation key: key = if nn.has? :name, syn!: :É´ then # explicit key (name) nn[:name] else # constructed key {}.merge( net: net_inst, cc: cc_id, imc: imc_id, ssc: ssc_id ) .merge( nn ) end # Let's clarify what we got so far. sim_settings = ssc( ssc_id ) mc_hash = cc( cc_id ) im_hash = imc( imc_id ) # Create and return the simulation sim = net_inst.simulation **sim_settings.merge( initial_marking: im_hash, marking_clamps: mc_hash ).merge( nn ) @simulations[ key ] = sim end
Creates a new clamp collection. If collection identifier is not given, resets :Base clamp collection to new values.
# File lib/y_petri/world/simulation_aspect.rb, line 77 def set_clamp_collection( name=:Base, clamp_hash ) @clamp_collections[name] = clamp_hash end
Creates a new initial marking collection. If collection identifier is not given, resets :Base initial marking collection to new values.
# File lib/y_petri/world/simulation_aspect.rb, line 85 def set_initial_marking_collection( name=:Base, initial_marking_hash ) @initial_marking_collections[name] = initial_marking_hash end
Creates a new simulation settings collection. If collection identifier is not given, resets :Base simulation settings collection to new values.
# File lib/y_petri/world/simulation_aspect.rb, line 93 def set_simulation_settings_collection( name=:Base, sim_set_hash ) @simulation_settings_collections[name] = sim_set_hash end
Presents a simulation specified by the argument, which must be a hash with four items: :net, :clamp_collection, :inital_marking_collection and :simulation_settings_collection.
# File lib/y_petri/world/simulation_aspect.rb, line 102 def simulation settings={} key = case settings when ~:may_have then # it is a hash or equivalent settings.may_have :net settings.may_have :cc, syn!: :clamp_collection settings.may_have :imc, syn!: :initial_marking_collection settings.may_have :ssc, syn!: :simulation_settings_collection { net: net( settings[:net] || self.Net::Top ), # the key cc: settings[:cc] || :Base, imc: settings[:imc] || :Base, ssc: settings[:ssc] || :Base } else # use the unprocessed argument itself as the key settings end @simulations[ key ] end
Simulation settings collection specified by the argument.
# File lib/y_petri/world/simulation_aspect.rb, line 69 def simulation_settings_collection name=:Base @simulation_settings_collections[name] end
Simulation settings collection names.
# File lib/y_petri/world/simulation_aspect.rb, line 48 def simulation_settings_collection_names @simulation_settings_collections.keys end
Hash of simulation instances and their settings.
# File lib/y_petri/world/simulation_aspect.rb, line 28 def simulations @simulations end