module YPetri::Agent::SimulationAspect
Simulation aspect of YPetri::Agent
: initial marking collections, clamp collections, initial marking collections, management of simulations…
Constants
- CcPoint
Pointer to a clamp collection.
- CcSelection
Clamp collection selection class.
- ImcPoint
Pointer to a collection of initial markings.
- ImcSelection
Initial marking collection selection class.
- SimulationSelection
Simulation selection class.
- SscPoint
Pointer to a collection of simulation settings.
- SscSelection
Simulation settings collection selection class.
Attributes
Public Class Methods
Agent
initialziation method.
# 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
Public Instance Methods
FIXME: This is not tested yet.
# 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
Returns identified clamp collection, or (if no argument given) one corresponding to cc_point.
# 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
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.
# File lib/y_petri/agent/simulation_aspect.rb, line 177 def initial_marking *args; oo = args.extract_options! 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
Returns identified initial marking collection, or (if no argument given) one corresponding to imc_point.
# 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
Load a file
# 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
Create a new timed simulation and make it available in the simulations table.
# 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 the recording reduced into the given feature set.
# 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 history of selected places with respect to a set of transitions.
# File lib/y_petri/agent/simulation_aspect.rb, line 317 def plot_delta( places=nil, except: [], transitions: nil, title: "Delta plot", ylabel: "Delta [µM]", **options ) options.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: options[:delta_time] ) .plot( title: title, ylabel: ylabel, **options ) end
Plot firing history of tS transitions.
# File lib/y_petri/agent/simulation_aspect.rb, line 294 def plot_firing( transitions=nil, except: [], title: "Firing plot", ylabel: "Firing [µM]", **options ) rec = simulation.recording tt = simulation.tS_tt( *transitions ) - simulation.Tt( except ) rec.Firing( tt ).plot( title: title, ylabel: ylabel, **options ) end
Plot flux history of TS transitions.
# File lib/y_petri/agent/simulation_aspect.rb, line 284 def plot_flux( transitions=nil, except: [], title: "Flux plot", ylabel: "Flux [µM.s⁻¹]", **options ) rec = simulation.recording tt = simulation.TS_tt( *transitions ) - simulation.Tt( except ) rec.Flux( tt ).plot( title: title, ylabel: ylabel, **options ) end
Plot gradient history of selected places with respect to a set of T transitions.
# 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⁻¹]", **options ) 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, **options ) end
Plot system state history.
# File lib/y_petri/agent/simulation_aspect.rb, line 273 def plot_marking( places=nil, except: [], title: "State plot", ylabel: "Marking [µM]", **options ) rec = simulation.recording pp = simulation.pp( *places ) - simulation.Pp( except ) rec.Marking( pp ).plot( title: title, ylabel: ylabel, **options ) end
Write the recorded samples in a file (csv).
# 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
Create a new timed simulation and run it.
# File lib/y_petri/agent/simulation_aspect.rb, line 250 def run! *args new_simulation.run! *args end
Save a file.
# File lib/y_petri/agent/simulation_aspect.rb, line 330 def save_file f, txt File.open( f, 'w' ) { |f| f.write "txt" } end
Changes the sampling period of the current ssc (ssc = simulation settings collection).
# File lib/y_petri/agent/simulation_aspect.rb, line 227 def set_sampling Δt ssc.update sampling: Δt end
Changes the simulation method of the current ssc (ssc = simulation settings collection).
# File lib/y_petri/agent/simulation_aspect.rb, line 234 def set_simulation_method m ssc.update method: m end
Changes the time step of the current ssc (ssc = simulation settings collection).
# File lib/y_petri/agent/simulation_aspect.rb, line 206 def set_step Δt ssc.update step: Δt end
Sets the time frame of the current ssc to run from zero to the time supplied as the argument.
# File lib/y_petri/agent/simulation_aspect.rb, line 220 def set_target_time time set_time time * 0 .. time end
Sets the time frame of the current ssc (sim. settings collection).
# 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
Returns the simulation identified by the argument. If no argument is given, returns the simulation at point.
# 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
Returns identified simulation settings collection, or (if no argument given) one corresponding to ssc_point.
# 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
Pretty print the state.
# File lib/y_petri/agent/simulation_aspect.rb, line 116 def state pp pm return nil end