Simulation 1.4alpha
__version__ = $Revision: 1.3 $ $Date: 2003-12-13 12:22:58+01 $ kgm
LICENSE:
Copyright (C) 2002 Klaus G. Muller, Tony Vignaux
mailto: kgmuller@xs4all.nl and Tony.Vignaux@vuw.ac.nz
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
END OF LICENSE
Implements SimPy Processes, resources, and the backbone simulation scheduling
by coroutine calls.
Based on generators (Python 2.2 and later)
Change history:
Started out as SiPy 0.9
5/9/2002: SiPy 0.9.1
12/9/2002:
15/9/2002: moved into SimPy package
16/9/2002:
- Resource attributes fully implemented (resources can now have more
than 1 shareable resource units)
17/9/2002:
17/9/2002:
26/9/02: Version 0.2.0
cleaned up code; more consistent naming
prefixed all Simulation-private variable names with "_".
prefixed all class-private variable names with "__".
made normal exit quiet (but return message from scheduler()
28/9/02:
15/10/02: Simulation version 0.3
Version printout now only if __TESTING
"_stop" initialized to True by module load, and set to False in
initialize()
Introduced simulate(until=0) instead of scheduler(till=0) .
Left scheduler() in for backward compatibility, but marked
as deprecated.
Added attribute "name" to class Process; default=="a_process"
Changed Resource constructor to
def __init__(self,capacity=1,name="a_resource",unitName="units" .
13/11/02: Simulation version 0.6
19/11/02: Simulation version 0.6.1
- Changed priority schemes so that higher values of Process
attribute "priority" represent higher priority.
20/11/02: Simulation version 0.7
- Major change of priority approach:
Priority set by "yield request,self,res,priority"
Priority of a Process instance associated with a specific
resource
25/11/02: Simulation version 0.7.1
11/12/2002: First process interrupt implementation
20/12/2002: Changes to "interrupt"; addition of boolean methods to show
process states
16/3/2003: Changed hold (allowing posting events past _endtime)
18/3/2003: Changed _nextev to prevent _t going past _endtime
23/3/2003: Introduced new interrupt construct; deleted resume method
25/3/2003: Expanded interrupt construct:
Made interrupt a method of Process
Added interruptCause as an attribute of an interrupted process
Changed definition of active to
self._nextTime <> None and not self._inInterrupt
Cleaned up test_interrupt function
30/3/2003: Modification of 'simulate':
error message if initialize not called (fatal)
error message if no process scheduled (warning)
Ensured that upon exit from simulate , now() == _endtime is
always valid
2/04/2003:
3/04/2003: Made priority private (_priority )
4/04/2003: Catch activation of non-generator error
5/04/2003: Added interruptReset() function to Process.
7/04/2003: Changed _unpost to ensure that process has
_nextTime == None (is passive) afterwards.
8/04/2003: Changed _hold to allow for yield hold,self
(equiv to yield hold,self,0 )
10/04/2003: Changed cancel syntax to Process().cancel(victim)
12/5/2003: Changed eventlist handling from dictionary to bisect
9/6/2003: - Changed eventlist handling from pure dictionary to bisect-
sorted "timestamps" list of keys, resulting in greatly
improved performance for models with large
numbers of event notices with differing event times.
=========================================================
This great change was suggested by Prof. Simon Frost.
Thank you, Simon! This version 1.3 is dedicated to you!
=========================================================
- Added import of Lister which supports well-structured
printing of all attributes of Process and Resource instances.
Nov 2003: Added capability to step through simulation event by event.
November 2003: Brought up to Simulation 1.4alpha
Dec 2003: Merged in Monitor and Histogram
Imported modules
|
|
from SimPy.Lister import *
from __future__ import generators
import bisect
import types
|
Functions
|
|
|
|
activate
|
activate (
object,
process,
at="undefined",
delay="undefined",
prior=False,
)
Application function to activate passive process.
Exceptions
|
|
Simerror( "Fatal SimPy error: activating function which" + " is not a generator (contains no 'yield')" )
|
|
|
askCancel
|
askCancel ()
|
|
holdfunc
|
holdfunc ( a )
|
|
initialize
|
initialize ()
|
|
now
|
now ()
|
|
passivatefunc
|
passivatefunc ( a )
|
|
reactivate
|
reactivate (
object,
at="undefined",
delay="undefined",
prior=False,
)
Application function to reactivate a process which is active,
suspended or passive.
|
|
releasefunc
|
releasefunc ( a )
|
|
requestfunc
|
requestfunc ( a )
|
|
scheduler
|
scheduler ( till=0 )
Schedules Processes/semi-coroutines until time till .
Deprecated since version 0.5.
|
|
showEvents
|
showEvents ()
Returns string with eventlist as list of tuples (eventtime,action)
|
|
simulate
|
simulate ( callback=None, until=0 )
Schedules Processes/semi-coroutines until time until
Exceptions
|
|
Simerror( "Fatal SimPy error: Simulation not initialized" )
|
|
|
simulateStep
|
simulateStep ( callback=None, until=0 )
Schedules Processes/semi-coroutines until next event
Exceptions
|
|
Simerror( "Fatal SimPy error: Simulation not initialized" )
|
|
|
startStepping
|
startStepping ()
Application function to start stepping through simulation.
|
|
stopSimulation
|
stopSimulation ()
Application function to stop simulation run
|
|
stopStepping
|
stopStepping ()
Application function to stop stepping through simulation.
|
|
test_demo
|
test_demo ()
|
|
test_interrupt
|
test_interrupt ()
|
Classes
|
|
FIFO | |
Monitor |
Monitored variables
|
PriorityQ |
Queue is always ordered according to priority.
|
Process |
Superclass of classes which may use generator functions
|
Queue | |
Resource |
Models shared, limited capacity resources with queuing;
|
Simerror | |
_Action |
Structure (who=process owner, generator=process)
|
__Evlist |
Defines event list and operations on it
|
|
|