Re: Pausing a simulation
<RCRamsdell <at> gldd.com>
2007-07-09 19:25:58 GMT
Hi Felipe,
I had to do something like this. What I came up with was a simpy
Process (CheckStatus shown below) that updates the gui (visualization)
at a given simulation time period. In my gui class, I instantiate and
activate this process before calling simulate(). As Klaus suggested, I
use SimulationRT and give the user the option to run in real-time or
flat-out. The simulation does not exactly pause, but nothing else
happens while the CheckStatus is active, during which time it calls the
function(s) to update the gui.
from SimPy.SimulationRT import *
class CheckStatus(Process):
"""CheckStatus - perodically update the gui with the status of the
simulation.
"""
def __init__(self, args, updateFunc, resultsFunc):
Process.__init__(self, name='StatusChecker')
self.updateRate = 1 #How often the gui is updated in sim
time
self.updateFunc = updateFunc #A function that shows the status
of the sims
self.resultsFunc = resultsFunc#A function that shows the results
to date
def updater(self):
self.updateFunc(time=0)
while True:
yield hold, self, self.updateRate
self.updateFunc(time=now())
self.resultsFunc()
class HopperDisplay(wx.Frame):
def __init__(self, title='OBOSim Controls', setup=None, stats=None,
argv=None):
...
def mnuRunSimulation(self, e):
"""
mnuRunSimulation - Run the simulation and display results
"""
self.simObjects = self.setupSim(self.args)
Dredges, riser, project = self.simObjects
if self.args['real_time']:
cs = CheckStatus(self.args, self.showDredgeStatus,
self.showSimulationResults)
activate(cs, cs.updater())
simulate(until=1440*10000, real_time=self.args['real_time'],
rel_speed=self.args['rel_speed'])
self.showSimulationResults()
Robert
________________________________
From: simpy-users-bounces <at> lists.sourceforge.net
[mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Felipe
Sent: Saturday, July 07, 2007 6:05 PM
To: simpy-users <at> lists.sourceforge.net
Subject: [Simpy-users] Pausing a simulation
Hello,
being new to this list I would first like to say hi to everyone
and a few words to explain what I am looking for .
I started using SimPy to simulate and compare two Business
Processes.
I want to do a visualization as the simulation unfolds, but for
this I would need the Simulation to pause while I render the situation,
and then resume again.
In effect, pausing the Simulation time.
How can I achieve this? I was looking for a method pause() or
something like that, but to no avail.
Thanks in advance for your input.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/