Module: YPetri::Agent::SimulationRelated
- Defined in:
- lib/y_petri/agent/simulation_related.rb
Overview
Agent instance methods related to simulation (initial marking collections, clamp collections, initial marking collections, management of simulations…)
Defined Under Namespace
Classes: SimulationPoint
Constant Summary collapse
- SimulationSelection =
Simulation selection class.
YPetri::Agent::Selection.parametrize( agent: self )
- SscSelection =
Simulation settings collection selection class.
YPetri::Agent::Selection.parametrize( agent: self )
- CcSelection =
Clamp collection selection class.
YPetri::Agent::Selection.parametrize( agent: self )
- ImcSelection =
Initial marking collection selection class.
YPetri::Agent::Selection.parametrize( agent: self )
- SscPoint =
Pointer to a collection of simulation settings.
YPetri::Agent::HashKeyPointer.parametrize( agent: self )
- CcPoint =
Pointer to a clamp collection.
YPetri::Agent::HashKeyPointer.parametrize( agent: self )
- ImcPoint =
Pointer to a collection of initial markings.
YPetri::Agent::HashKeyPointer.parametrize( agent: self )
Instance Attribute Summary collapse
-
#cc_point ⇒ Object
readonly
Returns the value of attribute cc_point.
-
#cc_selection ⇒ Object
readonly
Returns the value of attribute cc_selection.
-
#imc_point ⇒ Object
readonly
Returns the value of attribute imc_point.
-
#imc_selection ⇒ Object
readonly
Returns the value of attribute imc_selection.
-
#simulation_point ⇒ Object
readonly
Returns the value of attribute simulation_point.
-
#simulation_selection ⇒ Object
readonly
Returns the value of attribute simulation_selection.
-
#ssc_point ⇒ Object
readonly
Returns the value of attribute ssc_point.
-
#ssc_selection ⇒ Object
readonly
Returns the value of attribute ssc_selection.
Instance Method Summary collapse
-
#clamp(clamp_hash) ⇒ Object
FIXME: This is going to be tested.
-
#clamp_collection(id = nil) ⇒ Object
(also: #cc)
Returns identified clamp collection, or (if no argument given) one corresponding to cc_point.
-
#initial_marking(*args) ⇒ Object
(also: #im)
Returns or modifies current initial marking(s) as indicated by the argument field:.
-
#initial_marking_collection(id = nil) ⇒ Object
(also: #imc)
Returns identified initial marking collection, or (if no argument given) one corresponding to imc_point.
-
#initialize ⇒ Object
Agent initialziation method.
-
#new_simulation(*args, &block) ⇒ Object
Create a new timed simulation and make it available in the simulations table.
-
#plot(features) ⇒ Object
Plot the recording reduced into the given feature set.
-
#plot_delta(place_ids = nil, except: [], transitions: nil, title: "Delta plot", ylabel: "Delta [µM]", **options) ⇒ Object
Plot delta history of selected places with respect to a set of transitions.
-
#plot_firing(transition_ids = nil, except: [], title: "Firing plot", ylabel: "Firing [µM]", **options) ⇒ Object
Plot firing history of tS transitions.
-
#plot_flux(transition_ids = nil, except: [], title: "Flux plot", ylabel: "Flux [µM.s⁻¹]", **options) ⇒ Object
Plot flux history of TS transitions.
-
#plot_gradient(place_ids = nil, except: [], transitions: nil, title: "Gradient plot", ylabel: "Gradient [µM.s⁻¹]", **options) ⇒ Object
Plot gradient history of selected places with respect to a set of T transitions.
-
#plot_state(place_ids = nil, except: [], title: "State plot", ylabel: "Marking [µM]", **options) ⇒ Object
(also: #plot_marking)
Plot system state history.
-
#print_recording(filename = nil, **nn) ⇒ Object
Write the recorded samples in a file (csv).
-
#run!(*args) ⇒ Object
Create a new timed simulation and run it.
-
#set_sampling(Δt) ⇒ Object
Changes the sampling period of the current ssc (ssc = simulation settings collection).
-
#set_simulation_method(m) ⇒ Object
Changes the simulation method of the current ssc (ssc = simulation settings collection).
-
#set_step(Δt) ⇒ Object
(also: #set_step_size)
Changes the time step of the current ssc (ssc = simulation settings collection).
-
#set_target_time(time) ⇒ Object
Sets the time frame of the current ssc to run from zero to the time supplied as the argument.
-
#set_time(time_range) ⇒ Object
Sets the time frame of the current ssc (sim. settings collection).
-
#simulation(*args) ⇒ Object
Returns the simulation identified by the argument, or one at simulation point, if no argument given.
-
#simulation_settings_collection(id = nil) ⇒ Object
(also: #ssc)
Returns identified simulation settings collection, or (if no argument given) one corresponding to ssc_point.
-
#state ⇒ Object
Pretty print the state.
Instance Attribute Details
#cc_point ⇒ Object (readonly)
Returns the value of attribute cc_point.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def cc_point @cc_point end |
#cc_selection ⇒ Object (readonly)
Returns the value of attribute cc_selection.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def cc_selection @cc_selection end |
#imc_point ⇒ Object (readonly)
Returns the value of attribute imc_point.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def imc_point @imc_point end |
#imc_selection ⇒ Object (readonly)
Returns the value of attribute imc_selection.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def imc_selection @imc_selection end |
#simulation_point ⇒ Object (readonly)
Returns the value of attribute simulation_point.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def simulation_point @simulation_point end |
#simulation_selection ⇒ Object (readonly)
Returns the value of attribute simulation_selection.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def simulation_selection @simulation_selection end |
#ssc_point ⇒ Object (readonly)
Returns the value of attribute ssc_point.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def ssc_point @ssc_point end |
#ssc_selection ⇒ Object (readonly)
Returns the value of attribute ssc_selection.
62 63 64 |
# File 'lib/y_petri/agent/simulation_related.rb', line 62 def ssc_selection @ssc_selection end |
Instance Method Details
#clamp(clamp_hash) ⇒ Object
FIXME: This is going to be tested
160 161 162 163 164 |
# File 'lib/y_petri/agent/simulation_related.rb', line 160 def clamp clamp_hash clamp_hash.each_pair do |place, clamp| clamp_collection.merge! world.place( place ) => clamp end end |
#clamp_collection(id = nil) ⇒ Object Also known as: cc
Returns identified clamp collection, or (if no argument given) one corresponding to cc_point.
133 134 135 |
# File 'lib/y_petri/agent/simulation_related.rb', line 133 def clamp_collection id=nil if id.nil? then cc_point.get else clamp_collections[ id ] end end |
#initial_marking(*args) ⇒ Object Also known as: im
Returns or modifies current initial marking(s) as indicated by the argument field:
-
No arguments: returns current imc
-
Exactly one ordered argument: it is assumed to identify a place whose im in the current imc will be returned.
-
A hash: Assumed to be { place_id => im }, current imc is updated with it.
-
One ordered argument, and a hash: The imc identified by the ordered ordered arg is updated with the hash.
-
2 ordered arguments: First is assumed to identify an imc, second place whose im acc. to that imc to return.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/y_petri/agent/simulation_related.rb', line 178 def initial_marking *args; oo = args. case args.size when 0 then if oo.empty? then # no ordered arguments were given, initial_marking_collection # current imc will be returned else # hash was supplied, assumed of pairs { place_id => marking }, initial_marking_collection # it will be merged to imc .update( oo.with_keys do |key| place( key ) end ) end when 1 then # exactly one ordered argument was given, if oo.empty? then # without any named arguments, it is place = place( args[0] ) # assumed that it identifies a place, initial_marking_collection[ place ] # return its init. marking in imc else # One ordered argument (imc), and one hash (update values) given. im_coll = initial_marking_collection( args[0] ) im_coll.update( oo.with_keys do |key| place( key ) end ) end when 2 then # 2 ordered arguments (imc, place whose marking to return) im_coll = initial_marking_collection( args[0] ) place = place( args[1] ) im_coll[ place ] else raise ArgumentError, "Too many ordered parameters" end end |
#initial_marking_collection(id = nil) ⇒ Object Also known as: imc
Returns identified initial marking collection, or (if no argument given) one corresponding to imc_point.
141 142 143 144 145 |
# File 'lib/y_petri/agent/simulation_related.rb', line 141 def initial_marking_collection id=nil if id.nil? then imc_point.get else initial_marking_collections[ id ] end end |
#initialize ⇒ Object
Agent initialziation method.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/y_petri/agent/simulation_related.rb', line 73 def initialize # set up this agent's pointers @simulation_point = SimulationPoint.new( hash: simulations, hash_value_is: "simulation" ) @ssc_point = SscPoint.new( hash: simulation_settings_collections, hash_value_is: "simulation settings collection", default_key: :Base ) @cc_point = CcPoint.new( hash: clamp_collections, hash_value_is: "clamp collection", default_key: :Base ) @imc_point = ImcPoint.new( hash: initial_marking_collections, hash_value_is: "initial marking collection", default_key: :Base ) # set up this manipulator's selections @simulation_selection = SimulationSelection.new @ssc_selection = SscSelection.new @cc_selection = CcSelection.new @imc_selection = ImcSelection.new # do anything else prescribed super end |
#new_simulation(*args, &block) ⇒ Object
Create a new timed simulation and make it available in the simulations table.
242 243 244 245 246 247 |
# File 'lib/y_petri/agent/simulation_related.rb', line 242 def new_simulation *args, &block instance = world.new_simulation( *args, &block ) # Set the point to it simulation_point.set( simulations.rassoc( instance )[0] ) return instance end |
#plot(features) ⇒ Object
Plot the recording reduced into the given feature set.
267 268 269 270 |
# File 'lib/y_petri/agent/simulation_related.rb', line 267 def plot features ff = simulation.net.state.features( features ) simulation.recording.reduce_features( ff ).plot end |
#plot_delta(place_ids = nil, except: [], transitions: nil, title: "Delta plot", ylabel: "Delta [µM]", **options) ⇒ Object
Plot delta history of selected places with respect to a set of transitions.
324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/y_petri/agent/simulation_related.rb', line 324 def plot_delta( place_ids=nil, except: [], transitions: nil, title: "Delta plot", ylabel: "Delta [µM]", ** ) .may_have :delta_time, syn!: :Δt rec = simulation.recording pp = simulation.pp( place_ids ) - simulation.ee( except ) tt = transitions.nil? ? simulation.tt : tranisitions tt = simulation.tt( tt ) tt -= simulation.ee( except ) rec.delta( pp, transitions: tt, Δt: [:delta_time] ) .plot( title: title, ylabel: ylabel, ** ) end |
#plot_firing(transition_ids = nil, except: [], title: "Firing plot", ylabel: "Firing [µM]", **options) ⇒ Object
Plot firing history of tS transitions.
297 298 299 300 301 302 303 304 305 |
# File 'lib/y_petri/agent/simulation_related.rb', line 297 def plot_firing( transition_ids=nil, except: [], title: "Firing plot", ylabel: "Firing [µM]", ** ) rec = simulation.recording tt = transition_ids.nil? ? simulation.tS_tt : transition_ids tt = simulation.tS_tt( tt ) tt -= simulation.tt( except ) rec.firing( tt ).plot( title: title, ylabel: ylabel, ** ) end |
#plot_flux(transition_ids = nil, except: [], title: "Flux plot", ylabel: "Flux [µM.s⁻¹]", **options) ⇒ Object
Plot flux history of TS transitions.
285 286 287 288 289 290 291 292 293 |
# File 'lib/y_petri/agent/simulation_related.rb', line 285 def plot_flux( transition_ids=nil, except: [], title: "Flux plot", ylabel: "Flux [µM.s⁻¹]", ** ) rec = simulation.recording tt = transition_ids.nil? ? simulation.TS_tt : transition_ids tt = simulation.TS_tt( tt ) tt -= simulation.tt( except ) rec.flux( tt ).plot( title: title, ylabel: ylabel, ** ) end |
#plot_gradient(place_ids = nil, except: [], transitions: nil, title: "Gradient plot", ylabel: "Gradient [µM.s⁻¹]", **options) ⇒ Object
Plot gradient history of selected places with respect to a set of T transitions.
310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/y_petri/agent/simulation_related.rb', line 310 def plot_gradient( place_ids=nil, except: [], transitions: nil, title: "Gradient plot", ylabel: "Gradient [µM.s⁻¹]", ** ) rec = simulation.recording pp = simulation.pp( place_ids ) - simulation.ee( place_ids ) tt = transitions.nil? ? simulation.T_tt : transitions tt = simulation.T_tt( tt ) tt -= simulation.ee( except ) rec.gradient( pp, transitions: tt ) .plot( title: title, ylabel: ylabel, ** ) end |
#plot_state(place_ids = nil, except: [], title: "State plot", ylabel: "Marking [µM]", **options) ⇒ Object Also known as: plot_marking
Plot system state history.
274 275 276 277 278 279 280 |
# File 'lib/y_petri/agent/simulation_related.rb', line 274 def plot_state( place_ids=nil, except: [], title: "State plot", ylabel: "Marking [µM]", ** ) rec = simulation.recording pp = simulation.pp( place_ids ) - simulation.pp( except ) rec.marking( pp ).plot( title: title, ylabel: ylabel, ** ) end |
#print_recording(filename = nil, **nn) ⇒ Object
Write the recorded samples in a file (csv).
257 258 259 260 261 262 263 |
# File 'lib/y_petri/agent/simulation_related.rb', line 257 def print_recording( filename=nil, **nn ) if filename.nil? then simulation.recording.print **nn else File.open filename, "w" do |f| f << print_recording( **nn ) end end end |
#run!(*args) ⇒ Object
Create a new timed simulation and run it.
251 252 253 |
# File 'lib/y_petri/agent/simulation_related.rb', line 251 def run! *args new_simulation.run! *args end |
#set_sampling(Δt) ⇒ Object
Changes the sampling period of the current ssc (ssc = simulation settings collection).
228 229 230 |
# File 'lib/y_petri/agent/simulation_related.rb', line 228 def set_sampling Δt ssc.update sampling: Δt end |
#set_simulation_method(m) ⇒ Object
Changes the simulation method of the current ssc (ssc = simulation settings collection).
235 236 237 |
# File 'lib/y_petri/agent/simulation_related.rb', line 235 def set_simulation_method m ssc.update method: m end |
#set_step(Δt) ⇒ Object Also known as: set_step_size
Changes the time step of the current ssc (ssc = simulation settings collection).
207 208 209 |
# File 'lib/y_petri/agent/simulation_related.rb', line 207 def set_step Δt ssc.update step: Δt end |
#set_target_time(time) ⇒ Object
Sets the time frame of the current ssc to run from zero to the time supplied as the argument.
221 222 223 |
# File 'lib/y_petri/agent/simulation_related.rb', line 221 def set_target_time time set_time time * 0 .. time end |
#set_time(time_range) ⇒ Object
Sets the time frame of the current ssc (sim. settings collection).
214 215 216 |
# File 'lib/y_petri/agent/simulation_related.rb', line 214 def set_time time_range ssc.update time: time_range.aT_kind_of( Range ) end |
#simulation(*args) ⇒ Object
Returns the simulation identified by the argument, or one at simulation point, if no argument given. The simulation is identified in the same way as for #simulation_point_to method.
125 126 127 128 |
# File 'lib/y_petri/agent/simulation_related.rb', line 125 def simulation *args return simulation_point.get if args.empty? SimulationPoint.new( hash: simulations, hash_value_is: "simulation" ).get end |
#simulation_settings_collection(id = nil) ⇒ Object Also known as: ssc
Returns identified simulation settings collection, or (if no argument given) one corresponding to ssc_point.
151 152 153 154 155 |
# File 'lib/y_petri/agent/simulation_related.rb', line 151 def simulation_settings_collection id=nil if id.nil? then ssc_point.get else simulation_settings_collections[ id ] end end |
#state ⇒ Object
Pretty print the state.
116 117 118 119 |
# File 'lib/y_petri/agent/simulation_related.rb', line 116 def state pp pm return nil end |