Commit fd62846b authored by Jérome Perrin's avatar Jérome Perrin

update source to receive interarrivalTime as dict

parent adfbf696
......@@ -30,10 +30,10 @@ from SimPy.Simulation import Process
from RandomNumberGenerator import RandomNumberGenerator
class BatchSource(Source):
def __init__(self, id, name, distribution='Fixed', mean=1,
def __init__(self, id, name, interarrivalTime=None,
item='Dream.Batch', batchNumberOfUnits=1, **kw):
Source.__init__(self, id=id, name=name, distribution=distribution,
mean=mean, item=item, **kw)
Source.__init__(self, id=id, name=name,
interarrivalTime=interarrivalTime, item=item, **kw)
self.numberOfUnits = batchNumberOfUnits
......
......@@ -265,29 +265,14 @@ def createObjects():
element['id'] = element_id
objClass=element.get('_class', 'not found')
if objClass=='Dream.Source':
id=element.get('id', 'not found')
name=element.get('name', 'not found')
interarrivalTime=element.get('interarrivalTime',{})
distributionType=interarrivalTime.get('distributionType', 'not found')
mean=float(interarrivalTime.get('mean') or 0)
#entity=str_to_class(element['entity']) # initialize entity
entity=element['entity']
S=Source(id, name, distributionType, mean, entity) # initialize Source
S.nextIds=getSuccessorList(id)
S=Source(**element)
S.nextIds=getSuccessorList(element['id'])
G.SourceList.append(S)
G.ObjList.append(S)
if objClass=='Dream.BatchSource':
id=element.get('id', 'not found')
name=element.get('name', 'not found')
interarrivalTime=element.get('interarrivalTime',{})
distributionType=interarrivalTime.get('distributionType', 'not found')
mean=float(interarrivalTime.get('mean') or 0)
#entity=str_to_class(element['entity'])
entity=(element['entity'])
batchNumberOfUnits=int(element.get('batchNumberOfUnits', 'not found'))
S=BatchSource(id, name, distributionType, mean, entity, batchNumberOfUnits)
S.nextIds=getSuccessorList(id)
S = BatchSource(**element)
S.nextIds=getSuccessorList(element['id'])
G.BatchSourceList.append(S)
G.SourceList.append(S)
G.ObjList.append(S)
......
......@@ -35,21 +35,28 @@ import Globals
# The Source object is a Process
#============================================================================
class Source(CoreObject):
def __init__(self, id, name, distribution='Fixed', mean=1, item='Dream.Part', **kw):
CoreObject.__init__(self, id, name)
def __init__(self, id, name, interarrivalTime=None, item='Dream.Part', **kw):
# Default values
if not interarrivalTime:
interarrivalTime = {'distributionType': 'Fixed', 'mean': 1}
self.distType=distribution # label that sets the distribution type
CoreObject.__init__(self, id, name)
self.distType = interarrivalTime['distributionType'] # label that sets the distribution type
# properties used for statistics
self.totalInterArrivalTime=0 # the total interarrival time
self.numberOfArrivals=0 # the number of entities that were created
self.totalInterArrivalTime = 0 # the total interarrival time
self.numberOfArrivals = 0 # the number of entities that were created
# # list containing objects that follow in the routing
# self.next=[] # list with the next objects in the flow
# self.nextIds=[] # list with the ids of the next objects in the flow
# self.previousIds=[] # list with the ids of the previous objects in the flow.
# # For the source it is always empty!
self.type="Source" #String that shows the type of object
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=mean
# XXX we could just initialize RandomNumberGenerator by passing
# interarrivalTime dict
self.rng = RandomNumberGenerator(self, self.distType)
self.rng.avg = interarrivalTime['mean']
self.item=Globals.getClassFromName(item) #the type of object that the Source will generate
def initialize(self):
......
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