Steven,
yes, I agree, in large programs, SimPy script sections
often reside in separate files. I have thought about this and suggest
e.g. the following structures:
Case A: The model components, a model and experiment data
are defined in a script (say, centralserver.py). An experiment with the same
model, but different experiment data is to be executed. I would then write a
script with the following structure:
"""centralserverExtend.py
Run central server model with
different parameters"""
## Model components, model ----------
import
centralserver as cs
## Experiment data
-------------------------
cs.cpu = cs.Resource(name='cpu')
cs.disk =
cs.Resource(name='disk')
cs.Nterminals =
9 ## Number of terminals =
Tasks
cs.pDisk = 0.8 ##
prob. of going to disk
cs.MeanThinkTime = 10.0 ## seconds
cs.MeanCPUTime =
1.0 ## seconds
cs.MeanDiskTime = 1.39 ##
seconds
cs.ran.seed(123)
cs.MaxrunTime =
20000.0
cs.MaxCompletions = 100
## Experiment
result=cs.main()
## Analysis/output
-------------------------
print '%7.4f: CPU rate = %7.4f tasks per
second'%result
Variations are possible where additional or different model
components and a new model would be defined in the importing script.
Case B: The model components, a model, an experiment,
analysis and output are programmed in a script. The experiment data is contained
in a Python script, given as a parameter to the script call. Then the structure
could look like this:
""" centralserverExtend1.py
"""
from SimPy.Simulation import *
## from SimPy.SimulationTrace
import *
import random as ran
## Model components
------------------------
class Task(Process):
""" A
computer task requires at least
one use of the
CPU and possibly accesses to a
disk
drive."""
completed = 0
rate =
0.0
def
execute(self,maxCompletions):
while Task.completed <
maxCompletions:
thinktime =
ran.expovariate(1.0/MeanThinkTime)
yield
hold,self,thinktime
yield
request,self,cpu
CPUtime=ran.expovariate(1.0/MeanCPUTime)
yield
hold,self,CPUtime
yield
release,self,cpu
while ran.random() <
pDisk:
yield
request,self,disk
disktime=ran.expovariate(1.0/MeanDiskTime)
yield
hold,self,disktime
yield
release,self,disk
yield
request,self,cpu
CPUtime=ran.expovariate(1.0/MeanCPUTime)
yield
hold,self,CPUtime
yield
release,self,cpu
Task.completed +=
1
Task.rate =
Task.completed/float(now())
## Model ------------------------------
def
main():
initialize()
for i in
range(Nterminals):
t =
Task(name="task"+`i`)
activate(t,t.execute(MaxCompletions))
simulate(until =
MaxrunTime)
return (now(),Task.rate)
##
Experiment data -------------------------
execfile(sys.argv[1])
##
Experiment
result=main()
## Analysis/output
-------------------------
print '%7.4f: CPU rate = %7.4f tasks per
second'%result
with the data file being e.g.
"""centralserver.dat
Experiment data file for centralserverExtend1.py
model"""
cpu = Resource(name='cpu')
disk =
Resource(name='disk')
Nterminals = 3 ##
Number of terminals = Tasks
pDisk =
0.8 ## prob. of going to
disk
MeanThinkTime = 10.0 ## seconds
MeanCPUTime = 1.0
## seconds
MeanDiskTime = 1.39 ## seconds
ran.seed(111113333)
MaxrunTime =
20000.0
MaxCompletions = 100
So, I believe, the proposed structure can also deal
with larger models where the various parts are split over different
files.
Tony,
your thoughts re Literate Programming sound very
interesting. I have no experience in that area (does that make me illiterate?).
Could you give us an example, even if it is not in
SimPy/Python?
Klaus Muller
And we could also use Literate Programming (noweb, for example).
The sections would fit in very well. I have used noweb a couple of times for
simulation programs (mainly Simscript and ModSim but currently I am writing
only small SimPy programs.
Tony
On 11/3/06, Steven H.
Rogers <steve <at> shrogers.com>
wrote:
G'day
Klaus:
I think this is a good organization and it would work for
we. For
large/complex models/experiments some sections might
be separate files.
Regards,
Steve
Klaus Muller
wrote:
> All,
> I have found it very useful to have the same
structure with six sections for
> all my SimPy simulation
programs:
> ## Model components
> (Put
all model classes/methods here)
> ## Model
> (Put the model function here)
> ##
Experiment data
> (Give all model variables
values here)
> ## Experiment
> (Call the
model function)
> ## Analysis
> (Analyze
the data collected in experiment)
> ##
Output
> (Output the analysis results in
textual or graphical form)
>
> If a simulation program has model
runs (experiments) using several data
> sets, the last four sections
are repeated as many times as there are data
> sets.
> Such
canonical structure makes it easy for the program developer to find
his
> way in his own programs or those of others.
> I also find
that it is advisable to keep function model free of literal data
>
and just use variables which are assigned their values in a set of
>
experiment data. This keeps the model general and allows it to be used
for
> any number of experiments (simulation runs), based on different
experiment
> data sets.
> Similarly, all model components
should be kept free of data by using
> variables which get their
values from the experiment data, either directly
> or by parameter
transmission from the model function.
>
> What do you think?
Would this work for you? Does such structure help?
>
Counter-proposals?
>
> I am looking forward to your
feedback!
>
> Klaus
>
>
>
------------------------------------------------------------------------
>
>
-------------------------------------------------------------------------
>
Using Tomcat but need to do more? Need to support web services,
security?
> Get stuff done quickly with pre-integrated technology to
make your job easier
> Download IBM WebSphere Application Server
v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>
>
>
------------------------------------------------------------------------
>
>
_______________________________________________
> Simpy-users mailing
list
> Simpy-users <at> lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/simpy-users
--
Steven
H. Rogers, Ph.D., steve <at> shrogers.com
Weblog: http://shrogers.com/weblog
"He who
refuses to do arithmetic is doomed to talk nonsense."
-- John
McCarthy
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make
your job easier
Download IBM WebSphere Application Server v.1.0.1 based
on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
--
Prof
Tony Vignaux
Victoria University of Wellington