Commit 7f78637f authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

very first version of an event generator object. This can be called in fixed...

very first version of an event generator object. This can be called in fixed intervals and generate some events
parent 1d3bec52
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 4 Dec 2013
@author: George
'''
'''
models a generator that runs a method at specified intervals
'''
from SimPy.Simulation import now, hold, Process
from ObjectInterruption import ObjectInterruption
class EventGenerator(ObjectInterruption):
def __init__(self, start=None, stop=None, interval=None, duration=None, method=None):
ObjectInterruption.__init__(self)
self.start=start
self.stop=stop
self.interval=interval
self.duration=duration
self.method=method
def run(self):
yield hold,self,self.start
while 1:
if self.stop:
if now()>self.stop:
break
self.method()
yield hold,self,self.interval
\ No newline at end of file
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 4 Dec 2013
@author: George
'''
'''
test script to test the generator
'''
from SimPy.Simulation import now, activate,simulate
from EventGenerator import EventGenerator
def myMethod():
print "I was invoked at", now()
EG=EventGenerator(start=60, interval=60, method=myMethod)
activate(EG, EG.run())
simulate(until=480) #run the simulation
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment