Module: YPetri::World::SimulationAspect
- Defined in:
- lib/y_petri/world/simulation_aspect.rb,
lib/y_petri/world/simulation_aspect.rb
Overview
Workspace instance methods related to the Simulation aspect of YPetri (stored marking collections, clamp collections, inital marking collections, management of simulations…)
Instance Attribute Summary collapse
-
#clamp_collections ⇒ Object
readonly
Collections of clamps, initial marking vectors, and simulation settings.
-
#initial_marking_collections ⇒ Object
readonly
Collections of clamps, initial marking vectors, and simulation settings.
-
#simulation_settings_collections ⇒ Object
readonly
Collections of clamps, initial marking vectors, and simulation settings.
Instance Method Summary collapse
-
#clamp_collection(name = :Base) ⇒ Object
(also: #cc)
Clamp collection identified by the argument.
-
#clamp_collection_names ⇒ Object
(also: #ncc)
Clamp collection names.
-
#initial_marking_collection(name = :Base) ⇒ Object
(also: #imc)
Marking collection identified by the argument.
-
#initial_marking_collection_names ⇒ Object
(also: #nimc)
Initial marking collection names.
-
#initialize ⇒ Object
Instance initialization.
-
#new_simulation(net: Net().instance( :Top ), **nn) ⇒ Object
Makes a new timed simulation.
-
#set_clamp_collection(name = :Base, clamp_hash) ⇒ Object
(also: #set_cc)
Creates a new clamp collection.
-
#set_initial_marking_collection(name = :Base, initial_marking_hash) ⇒ Object
(also: #set_imc)
Creates a new initial marking collection.
-
#set_simulation_settings_collection(name = :Base, sim_set_hash) ⇒ Object
(also: #set_ssc)
Creates a new simulation settings collection.
-
#simulation(settings = {}) ⇒ Object
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.
-
#simulation_settings_collection(name = :Base) ⇒ Object
(also: #ssc)
Simulation settings collection specified by the argument.
-
#simulation_settings_collection_names ⇒ Object
(also: #nssc)
Simulation settings collection names.
-
#simulations ⇒ Object
Hash of simulation instances and their settings.
Instance Attribute Details
#clamp_collections ⇒ Object (readonly)
Collections of clamps, initial marking vectors, and simulation settings.
10 11 12 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 10 def clamp_collections @clamp_collections end |
#initial_marking_collections ⇒ Object (readonly)
Collections of clamps, initial marking vectors, and simulation settings.
10 11 12 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 10 def initial_marking_collections @initial_marking_collections end |
#simulation_settings_collections ⇒ Object (readonly)
Collections of clamps, initial marking vectors, and simulation settings.
10 11 12 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 10 def simulation_settings_collections @simulation_settings_collections end |
Instance Method Details
#clamp_collection(name = :Base) ⇒ Object Also known as: cc
Clamp collection identified by the argument.
55 56 57 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 55 def clamp_collection name=:Base @clamp_collections[name] end |
#clamp_collection_names ⇒ Object Also known as: ncc
Clamp collection names.
34 35 36 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 34 def clamp_collection_names @clamp_collections.keys end |
#initial_marking_collection(name = :Base) ⇒ Object Also known as: imc
Marking collection identified by the argument.
62 63 64 |
# 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 ⇒ Object Also known as: nimc
Initial marking collection names.
41 42 43 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 41 def initial_marking_collection_names @initial_marking_collections.keys end |
#initialize ⇒ Object
Instance initialization.
16 17 18 19 20 21 22 23 24 |
# 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 |
#new_simulation(net: Net().instance( :Top ), **nn) ⇒ Object
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 }
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# 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 |
#set_clamp_collection(name = :Base, clamp_hash) ⇒ Object Also known as: set_cc
Creates a new clamp collection. If collection identifier is not given, resets :Base clamp collection to new values.
77 78 79 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 77 def set_clamp_collection( name=:Base, clamp_hash ) @clamp_collections[name] = clamp_hash end |
#set_initial_marking_collection(name = :Base, initial_marking_hash) ⇒ Object Also known as: set_imc
Creates a new initial marking collection. If collection identifier is not given, resets :Base initial marking collection to new values.
85 86 87 |
# 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 |
#set_simulation_settings_collection(name = :Base, sim_set_hash) ⇒ Object Also known as: set_ssc
Creates a new simulation settings collection. If collection identifier is not given, resets :Base simulation settings collection to new values.
93 94 95 |
# 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 |
#simulation(settings = {}) ⇒ Object
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.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# 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(name = :Base) ⇒ Object Also known as: ssc
Simulation settings collection specified by the argument.
69 70 71 |
# 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 ⇒ Object Also known as: nssc
Simulation settings collection names.
48 49 50 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 48 def simulation_settings_collection_names @simulation_settings_collections.keys end |
#simulations ⇒ Object
Hash of simulation instances and their settings.
28 29 30 |
# File 'lib/y_petri/world/simulation_aspect.rb', line 28 def simulations @simulations end |