Module: YPetri::Agent::SimulationAspect
- Defined in:
- lib/y_petri/agent/simulation_aspect.rb
Overview
Simulation aspect of YPetri::Agent
: 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 not tested yet.
-
#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.
-
#load_file(f) ⇒ Object
Load a file.
-
#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(places = 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(transitions = nil, except: [], title: "Firing plot", ylabel: "Firing [µM]", **options) ⇒ Object
Plot firing history of tS transitions.
-
#plot_flux(transitions = nil, except: [], title: "Flux plot", ylabel: "Flux [µM.s⁻¹]", **options) ⇒ Object
Plot flux history of TS transitions.
-
#plot_gradient(places = 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_marking(places = nil, except: [], title: "State plot", ylabel: "Marking [µM]", **options) ⇒ Object
(also: #plot_state)
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.
-
#save_file(f, txt) ⇒ Object
Save a file.
-
#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.
-
#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_aspect.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_aspect.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_aspect.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_aspect.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_aspect.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_aspect.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_aspect.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_aspect.rb', line 62 def ssc_selection @ssc_selection end |
Instance Method Details
#clamp(clamp_hash) ⇒ Object
FIXME: This is not tested yet.
159 160 161 162 163 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 159 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.
132 133 134 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 132 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.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 177 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.
140 141 142 143 144 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 140 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_aspect.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 |
#load_file(f) ⇒ Object
Load a file
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 336 def load_file f rr = [] CSV.parse( File.open( f ), headers: true ) { |row| rr << row } r1 = rr.first.to_hash.with_keys { |k| eval k }.with_values { |v| eval v } ff = world.net.State.Features( r1.keys[ 1..-1 ] ) dataset = ff.DataSet.new rr.each { |row| r = row.to_hash.with_keys { |k| eval k }.with_values { |v| eval v } event = r.delete :event dataset[ event ] = ff.r.values } return dataset end |
#new_simulation(*args, &block) ⇒ Object
Create a new timed simulation and make it available in the simulations table.
241 242 243 244 245 246 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 241 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.
266 267 268 269 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 266 def plot features ff = simulation.net.State.Features( features ) simulation.recording.reduce_features( ff ).plot end |
#plot_delta(places = 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.
317 318 319 320 321 322 323 324 325 326 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 317 def plot_delta( places=nil, except: [], transitions: nil, title: "Delta plot", ylabel: "Delta [µM]", ** ) .may_have :delta_time, syn!: :Δt rec = simulation.recording pp = simulation.pp( *places ) - simulation.Nn( except ) tt = simulation.tt( *transitions ) - simulation.Nn( except ) simulation.recording.Delta( pp, transitions: tt, Δt: [:delta_time] ) .plot( title: title, ylabel: ylabel, ** ) end |
#plot_firing(transitions = nil, except: [], title: "Firing plot", ylabel: "Firing [µM]", **options) ⇒ Object
Plot firing history of tS transitions.
294 295 296 297 298 299 300 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 294 def plot_firing( transitions=nil, except: [], title: "Firing plot", ylabel: "Firing [µM]", ** ) rec = simulation.recording tt = simulation.tS_tt( *transitions ) - simulation.Tt( except ) rec.Firing( tt ).plot( title: title, ylabel: ylabel, ** ) end |
#plot_flux(transitions = nil, except: [], title: "Flux plot", ylabel: "Flux [µM.s⁻¹]", **options) ⇒ Object
Plot flux history of TS transitions.
284 285 286 287 288 289 290 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 284 def plot_flux( transitions=nil, except: [], title: "Flux plot", ylabel: "Flux [µM.s⁻¹]", ** ) rec = simulation.recording tt = simulation.TS_tt( *transitions ) - simulation.Tt( except ) rec.Flux( tt ).plot( title: title, ylabel: ylabel, ** ) end |
#plot_gradient(places = 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.
305 306 307 308 309 310 311 312 313 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 305 def plot_gradient( places=nil, except: [], transitions: nil, title: "Gradient plot", ylabel: "Gradient [µM.s⁻¹]", ** ) rec = simulation.recording pp = simulation.pp( *places ) - simulation.Nn( except ) tt = simulation.T_tt( *transitions ) - simulation.Nn( except ) rec.Gradient( pp, transitions: tt ) .plot( title: title, ylabel: ylabel, ** ) end |
#plot_marking(places = nil, except: [], title: "State plot", ylabel: "Marking [µM]", **options) ⇒ Object Also known as: plot_state
Plot system state history.
273 274 275 276 277 278 279 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 273 def plot_marking( places=nil, except: [], title: "State plot", ylabel: "Marking [µM]", ** ) rec = simulation.recording pp = simulation.pp( *places ) - 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).
256 257 258 259 260 261 262 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 256 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.
250 251 252 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 250 def run! *args new_simulation.run! *args end |
#save_file(f, txt) ⇒ Object
Save a file.
330 331 332 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 330 def save_file f, txt File.open( f, 'w' ) { |f| f.write "txt" } end |
#set_sampling(Δt) ⇒ Object
Changes the sampling period of the current ssc (ssc = simulation settings collection).
227 228 229 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 227 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).
234 235 236 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 234 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).
206 207 208 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 206 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.
220 221 222 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 220 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).
213 214 215 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 213 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. If no argument is given, returns the simulation at point.
124 125 126 127 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 124 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.
150 151 152 153 154 |
# File 'lib/y_petri/agent/simulation_aspect.rb', line 150 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_aspect.rb', line 116 def state pp pm return nil end |