Commit 88f8b57e authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

source, exit and CoreObject objects also updated so that they use the new methods

parent e24f9ba5
......@@ -71,8 +71,9 @@ class CoreObject(Process):
self.previous=p
#removes an entity from the Object
def removeEntity(self):
self.Res.activeQ.pop(0)
def removeEntity(self):
activeObjectQueue=self.getActiveObjectQueue()
activeObjectQueue.pop(0) #remove the Entity from the queue
#gets an entity from the predecessor that the predecessor index points to
def getEntity(self):
......@@ -106,7 +107,8 @@ class CoreObject(Process):
#checks if the Object can dispose an entity to the following object
def haveToDispose(self, callerObject=None):
return len(self.Res.activeQ)>0
activeObjectQueue=self.getActiveObjectQueue()
return len(activeObjectQueue)>0
#checks if the Object can accept an entity and there is an entity in some predecessor waiting for it
def canAcceptAndIsRequested(self):
......
......@@ -102,22 +102,40 @@ class Exit(CoreObject):
#checks if the Exit can accept an entity and there is an entity waiting for it
def canAcceptAndIsRequested(self):
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
result = None
if(len(self.previous)==1):
return self.previous[0].haveToDispose(self)
if(len(activeObject.previous)==1):
object=activeObject.previous[0]
return object.haveToDispose(self)
isRequested=False
for i in range(len(self.previous)):
if(self.previous[i].haveToDispose(self)):
i=0
for object in self.previous:
if(object.haveToDispose(activeObject)):
isRequested=True
self.predecessorIndex=i
i+=1
return isRequested
#gets an entity from the predecessor
def getEntity(self):
name=self.previous[self.predecessorIndex].Res.activeQ[0].name #get the name of the entity for the trace
self.totalLifespan+=now()-self.previous[self.predecessorIndex].Res.activeQ[0].startTime #Add the entity's lifespan to the total one.
self.previous[self.predecessorIndex].removeEntity() #remove the entity from the previous object
giverObject=self.getGiverObject()
giverObject.sortEntities() #sort the Entities of the giver according to the scheduling rule if applied
activeObject=self.getActiveObject()
giverObjectQueue=self.getGiverObjectQueue()
activeEntity=giverObjectQueue[0]
activeObjectQueue=self.getActiveObjectQueue()
name=activeEntity.name #get the name of the entity for the trace
activeObjectQueue.append(activeEntity) #get the entity from the previous object
#and put it in front of the activeQ
giverObject.removeEntity() #remove the entity from the previous object
activeEntity.schedule.append([activeObject.id,now()]) #append the time to schedule so that it can be read in the result
self.totalLifespan+=now()-activeEntity.startTime #Add the entity's lifespan to the total one.
self.outputTrace(name)
#actions to be taken after the simulation ends
......
......@@ -85,40 +85,37 @@ class Source(CoreObject):
self.waitToDispose=False #shows if the object waits to dispose an entity
def run(self):
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
i=0
if(self.distType=="Fixed"): #if the distribution type is fixed
from Globals import G
while 1:
#self.waitToDispose=True
self.numberOfArrivals+=1 #we have one new arrival
#entity=Entity("Ent"+str(i))
self.numberOfArrivals+=1 #we have one new arrival
entity=self.item(self.item.type+"_"+self.objName+"_"+str(i)) #create the Entity object and assign its name
entity.creationTime=now() #assign the current simulation time as the Entity's creation time
entity.startTime=now() #assign the current simulation time as the Entity's start time
self.outputTrace(self.item.type+"_"+self.objName+"_"+str(i)) #output the trace
self.Res.activeQ.append(entity) #append the entity to the resource
activeObjectQueue.append(entity) #append the entity to the resource
i+=1
#yield hold,self,self.interArrivalTime #one entity at every interArrivalTime
yield hold,self,self.rng.generateNumber()
elif(self.distType=="Exp"): #if the distribution type is exponential
from Globals import G
while 1:
#self.waitToDispose=True
self.numberOfArrivals+=1 #we have one new arrival
#entity=Entity("Ent"+str(i)) #create the Entity object and assign its name
entity=self.item(self.item.type+str(i)) #create the Entity object and assign its name
entity.creationTime=now() #assign the current simulation time as the Entity's creation time
entity.startTime=now() #assign the current simulation time as the Entity's start time
self.outputTrace(self.item.type+str(i)) #output the trace
i+=1
self.Res.activeQ.append(entity) #append the entity to the resource
activeObjectQueue.append(entity) #append the entity to the resource
timeTillNextArrival=G.Rnd.expovariate(1.0/(self.interArrivalTime)) #create a random number that follows the
#exponential distribution
#yield hold,self,timeTillNextArrival #one entity at every interArrivalTime
yield hold,self,self.rng.generateNumber()
self.totalInterArrivalTime+=timeTillNextArrival
else: #if the distribution type is something else it is an error
print "Distribution Error in Source "+str(self.id)
print "Distribution Error in "+str(self.objName)
#sets the routing out element for the Source
def defineRouting(self, n):
......
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