new attributes added to entity. Entity now has receiver

parent a69741e2
...@@ -25,6 +25,8 @@ Created on 18 Aug 2013 ...@@ -25,6 +25,8 @@ Created on 18 Aug 2013
Class that acts as an abstract. It should have no instances. All the Entities should inherit from it Class that acts as an abstract. It should have no instances. All the Entities should inherit from it
''' '''
from SimPy.Simulation import now
# =========================================================================== # ===========================================================================
# The entity object # The entity object
# =========================================================================== # ===========================================================================
...@@ -66,6 +68,28 @@ class Entity(object): ...@@ -66,6 +68,28 @@ class Entity(object):
self.candidateReceivers=[] # list of candidateReceivers of the entity (those stations that can receive the entity self.candidateReceivers=[] # list of candidateReceivers of the entity (those stations that can receive the entity
self.candidateReceiver=None # the station that is finaly chosen to receive the entity self.candidateReceiver=None # the station that is finaly chosen to receive the entity
# variables used to avoid signalling the same object twice before it receives an entity
self.receiver=None
self.timeOfAssignement=0
#===========================================================================
# assign the entity to a station
#===========================================================================
def assignTo(self, object=None):
self.receiver=object
self.timeOfAssignement=now()
#===========================================================================
# unassign the entity from the object it is currently assigned to
#===========================================================================
def unassign(self):
self.receiver=None
self.timeOfAssignement=0
#===========================================================================
# returns the object the entity is currently assigned to
#===========================================================================
def isAssignedTo(self):
return self.receiver
# ======================================================================= # =======================================================================
# outputs results to JSON File # outputs results to JSON File
# ======================================================================= # =======================================================================
......
...@@ -135,7 +135,7 @@ class Queue(CoreObject): ...@@ -135,7 +135,7 @@ class Queue(CoreObject):
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
#if we have only one possible receiver just check if the Queue holds one or more entities #if we have only one possible receiver just check if the Queue holds one or more entities
if(len(activeObject.next)==1 or callerObject==None): if(callerObject==None):
return len(activeObjectQueue)>0 return len(activeObjectQueue)>0
thecaller=callerObject thecaller=callerObject
...@@ -144,8 +144,8 @@ class Queue(CoreObject): ...@@ -144,8 +144,8 @@ class Queue(CoreObject):
# ======================================================================= # =======================================================================
# removes an entity from the Object # removes an entity from the Object
# ======================================================================= # =======================================================================
def removeEntity(self, entity=None): def removeEntity(self, entity=None):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeEntity=CoreObject.removeEntity(self, entity) #run the default method activeEntity=CoreObject.removeEntity(self, entity) #run the default method
if self.canAccept(): if self.canAccept():
self.signalGiver() self.signalGiver()
......
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