Commit f181a2c0 authored by Georgios Dagkakis's avatar Georgios Dagkakis

several changes. Model that uses only Source-Queue-Exit runs for 1 replication

parent 302452f4
......@@ -258,7 +258,7 @@ class CoreObject(ManPyObject):
if self.checkForDedicatedOperators():
allocationNeeded=False
from Globals import ManPyEnvironment
for obj in G.MachineList:
for obj in self.environment.MachineList:
if obj.operatorPool!='None':
if obj.operatorPool.operators:
allocationNeeded=False
......@@ -291,7 +291,7 @@ class CoreObject(ManPyObject):
self.offShiftTimeTryingToReleaseCurrentEntity=0
self.timeLastEntityLeft=self.env.now
self.outputTrace(entity.name, "released "+self.objName)
self.outputTrace(self.environment,entity.name, "released "+self.objName)
#append the time to schedule so that it can be read in the result
#remember that every entity has it's schedule which is supposed to be updated every time
......@@ -380,8 +380,8 @@ class CoreObject(ManPyObject):
self.nameLastEntityEntered=activeEntity.name # this holds the name of the last entity that got into object
# update the next list of the object
self.updateNext(activeEntity)
self.outputTrace(activeEntity.name, "got into "+self.objName)
self.printTrace(activeEntity.name, enter=self.id)
self.outputTrace(self.environment,activeEntity.name, "got into "+self.objName)
self.printTrace(self.environment,activeEntity.name, enter=self.id)
# # if there are entities with requiredParts then check whether the requirements are fulfilled for them to proceed
# # ass soon as a "buffer" receives an entity it controls if the entity is requested elsewhere,
# # then it checks if there other requested entities by the same requesting entity.
......@@ -389,7 +389,7 @@ class CoreObject(ManPyObject):
# # their sequences for the requesting entity
# from Globals import ManPyEnvironment
# # for all the entities in the EntityList
# for entity in G.EntityList:
# for entity in self.environment.EntityList:
# requiredParts=entity.getRequiredParts()
# if requiredParts:
# # if the activeEntity is in the requierdParts of the entity
......@@ -493,7 +493,7 @@ class CoreObject(ManPyObject):
def signalReceiver(self):
possibleReceivers=self.findReceiversFor(self)
if possibleReceivers:
receiver=self.selectReceiver(possibleReceivers)
receiver=self.selectReceiver(self.environment,possibleReceivers)
receiversGiver=self
# perform the checks that canAcceptAndIsRequested used to perform and update activeCallersList or assignExit and operatorPool
while not receiver.canAcceptAndIsRequested(receiversGiver):
......@@ -514,7 +514,7 @@ class CoreObject(ManPyObject):
self.receiver=receiver
self.receiver.giver=self
self.printTrace(self.id, signalReceiver=self.receiver.id)
self.printTrace(self.environment,self.id, signalReceiver=self.receiver.id)
# assign the entry of the receiver
self.receiver.assignEntryTo()
# assign the exit of the current object to the receiver
......@@ -530,14 +530,14 @@ class CoreObject(ManPyObject):
# select a receiver Object
# =======================================================================
@staticmethod
def selectReceiver(possibleReceivers=[]):
def selectReceiver(environment,possibleReceivers=[]):
candidates=possibleReceivers
# dummy variables that help prioritize the objects requesting to give objects to the object (activeObject)
maxTimeWaiting=0 # dummy variable counting the time a successor is waiting
receiver=None
from Globals import ManPyEnvironment
for object in candidates:
timeWaiting=G.env.now-object.timeLastEntityLeft # the time it has been waiting is updated and stored in dummy variable timeWaiting
timeWaiting=environment.env.now-object.timeLastEntityLeft # the time it has been waiting is updated and stored in dummy variable timeWaiting
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# if the timeWaiting is the maximum among the ones of the successors
maxTimeWaiting=timeWaiting
receiver=object # set the receiver as the longest waiting possible receiver
......@@ -602,7 +602,7 @@ class CoreObject(ManPyObject):
# loop through the possible givers to see which have to dispose and which is the one blocked for longer
for object in candidates:
# calculate how much the giver is waiting
timeWaiting=G.env.now-object.timeLastEntityEnded
timeWaiting=self.environment.env.now-object.timeLastEntityEnded
if(timeWaiting>=maxTimeWaiting):
giver=object # the object to deliver the Entity to the activeObject is set to the ith member of the previous list
maxTimeWaiting=timeWaiting
......@@ -670,7 +670,7 @@ class CoreObject(ManPyObject):
if now==float('inf'):
now=0
lastExits=[]
for object in G.ExitList:
for object in self.environment.ExitList:
lastExits.append(object.timeLastEntityEntered)
if lastExits:
now=max(lastExits)
......
......@@ -105,14 +105,14 @@ class Exit(CoreObject):
# =======================================================================
def getEntity(self):
activeEntity = CoreObject.getEntity(self) #run the default method
# if the entity is in the G.pendingEntities list then remove it from there
# if the entity is in the self.environment.pendingEntities list then remove it from there
from Globals import ManPyEnvironment
# G.pendingEntities[:]=(entity for entity in G.pendingEntities if not entity is activeEntity)
if G.RouterList:
if activeEntity in G.pendingEntities:
G.pendingEntities.remove(activeEntity)
# if activeEntity in G.EntityList:
# G.EntityList.remove(activeEntity)
# self.environment.pendingEntities[:]=(entity for entity in self.environment.pendingEntities if not entity is activeEntity)
if self.environment.RouterList:
if activeEntity in self.environment.pendingEntities:
self.environment.pendingEntities.remove(activeEntity)
# if activeEntity in self.environment.EntityList:
# self.environment.EntityList.remove(activeEntity)
# self.clear(activeEntity)
self.totalLifespan+=self.env.now-activeEntity.startTime #Add the entity's lifespan to the total one.
self.numOfExits+=1 # increase the exits by one
......@@ -135,10 +135,10 @@ class Exit(CoreObject):
def deleteEntityfromlist(entity, list):
if entity in list:
list.remove(entity)
lists=(G.EntityList, G.PartList, G.pendingEntities, G.WipList)
# lists=(G.EntityList, G.PartList, G.BatchList, G.SubBatchList,
# G.JobList, G.OrderList, G.OrderComponentList, G.MouldList,
# G.pendingEntities, G.WipList)
lists=(self.environment.EntityList, self.environment.PartList, self.environment.pendingEntities, self.environment.WipList)
# lists=(self.environment.EntityList, self.environment.PartList, self.environment.BatchList, self.environment.SubBatchList,
# self.environment.JobList, self.environment.OrderList, self.environment.OrderComponentList, self.environment.MouldList,
# self.environment.pendingEntities, self.environment.WipList)
for list in lists:
deleteEntityfromlist(entity,list)
......@@ -158,11 +158,11 @@ class Exit(CoreObject):
self.Exits.append(self.numOfExits)
self.UnitExits.append(self.totalNumberOfUnitsExited)
try: # throw exception in case the numOfExits is zero
self.Lifespan.append(((self.totalLifespan)/self.numOfExits)/G.Base)
self.Lifespan.append(((self.totalLifespan)/self.numOfExits)/self.environment.Base)
except ZeroDivisionError: # the lifespan in this case is zero
self.Lifespan.append(0)
try: # throw exception in case of zero division
self.TaktTime.append(((self.totalTaktTime)/self.numOfExits)/G.Base)
self.TaktTime.append(((self.totalTaktTime)/self.numOfExits)/self.environment.Base)
except ZeroDivisionError: # the average time between exits is zero if no Entity exited
self.TaktTime.append(0)
......
......@@ -113,11 +113,10 @@ class ManPyEnvironment(object):
self.SubBatchList=[]
# entities that just finished processing in a station
# and have to enter the next machine
self.pendingEntities=[]
self.env=simpy.Environment()
self.pendingEntities=[]
self.totalPulpTime=0 # temporary to track how much time PuLP needs to run
self.SimPyEnvironment=simpy.Environment()
self.env=self.SimPyEnvironment
# =======================================================================
# method to move entities exceeding a certain safety stock
......
{
"graph": {
"node": {
"E1": {
"interruptions": {},
"top": 0.10215053763440862,
"_class": "Dream.Exit",
"name": "Stock",
"left": 0.5
},
"S1": {
"name": "Raw Material",
"top": 0.8978494623655914,
"entity": "Dream.Part",
"interArrivalTime": {
"Fixed": {
"distributionType": "Fixed",
"mean": 0.5
}
},
"interruptions": {},
"_class": "Dream.Source",
"left": 0.5
},
"Q1": {
"name": "Queue",
"top": 0.5,
"interruptions": {},
"_class": "Dream.Queue",
"left": 0.5
}
},
"edge": {
"1": {
"source": "Q1",
"destination": "E1",
"data": {},
"_class": "Dream.Edge"
},
"0": {
"source": "S1",
"destination": "Q1",
"data": {},
"_class": "Dream.Edge"
}
}
},
"_class": "Dream.Simulation",
"general": {
"maxSimTime": "10",
"_class": "Dream.Configuration",
"confidenceLevel": "0.95",
"trace": "No",
"numberOfReplications": "1"
}
}
\ No newline at end of file
......@@ -600,9 +600,9 @@ def initializeObjects(environment):
# ===========================================================================
def activateObjects(environment):
for element in environment.ObjectInterruptionList:
environment.env.process(element.run())
environment.SimPyEnvironment.process(element.run())
for element in environment.ObjList:
environment.env.process(element.run())
environment.SimPyEnvironment.process(element.run())
# ===========================================================================
# the main script that is ran
......@@ -637,7 +637,7 @@ def main(argv=[], input_data=None):
#run the experiment (replications)
for i in xrange(environment.numberOfReplications):
environment.env=simpy.Environment() # initialize the environment
# environment.env=simpy.Environment() # initialize the environment
environment.maxSimTime=float(JSONData['general'].get('maxSimTime', '100')) # read the maxSimTime in each replication
# since it may be changed for infinite ones
if environment.RouterList:
......@@ -659,7 +659,7 @@ def main(argv=[], input_data=None):
# then we have to find the end time as the time the last entity ended.
if environment.maxSimTime==-1:
# If someone does it for a model that has always events, then it will run forever!
environment.env.run(until=float('inf'))
environment.SimPyEnvironment.run(until=float('inf'))
# identify from the exits what is the time that the last entity has ended.
endList=[]
......@@ -667,14 +667,14 @@ def main(argv=[], input_data=None):
endList.append(exit.timeLastEntityLeft)
# identify the time of the last event
if float(max(endList))!=0 and G.env.now==float('inf'): #do not let G.maxSimTime=0 so that there will be no crash
if float(max(endList))!=0 and environment.SimPyEnvironment.now==float('inf'): #do not let G.maxSimTime=0 so that there will be no crash
environment.maxSimTime=float(max(endList))
else:
print "simulation ran for 0 time, something may have gone wrong"
logger.info("simulation ran for 0 time, something may have gone wrong")
#else we simulate until the given maxSimTime
else:
environment.env.run(until=environment.maxSimTime)
environment.SimPyEnvironment.run(until=environment.maxSimTime)
#carry on the post processing operations for every object in the topology
for element in environment.ObjList+environment.ObjectResourceList+environment.RouterList:
......
......@@ -133,19 +133,19 @@ class ManPyObject(object):
# outputs message to the trace.xls. Format is (Simulation Time | Entity or Frame Name | message)
# =======================================================================
@staticmethod
def outputTrace(entityName, message):
def outputTrace(environment,entityName, message):
from Globals import ManPyEnvironment
if(G.trace=="Yes"): #output only if the user has selected to
if(environment.trace=="Yes"): #output only if the user has selected to
#handle the 3 columns
G.traceSheet.write(G.traceIndex,0,str(G.env.now))
G.traceSheet.write(G.traceIndex,1,entityName)
G.traceSheet.write(G.traceIndex,2,message)
G.traceIndex+=1 #increment the row
environment.traceSheet.write(environment.traceIndex,0,str(environment.env.now))
environment.traceSheet.write(environment.traceIndex,1,entityName)
environment.traceSheet.write(environment.traceIndex,2,message)
environment.traceIndex+=1 #increment the row
#if we reach row 65536 we need to create a new sheet (excel limitation)
if(G.traceIndex==65536):
G.traceIndex=0
G.sheetIndex+=1
G.traceSheet=G.traceFile.add_sheet('sheet '+str(G.sheetIndex), cell_overwrite_ok=True)
if(environment.traceIndex==65536):
environment.traceIndex=0
environment.sheetIndex+=1
environment.traceSheet=environment.traceFile.add_sheet('sheet '+str(environment.sheetIndex), cell_overwrite_ok=True)
#===========================================================================
# sends a signal
......
......@@ -104,11 +104,11 @@ class Queue(CoreObject):
self.expectedSignals['isRequested']=1
self.expectedSignals['loadOperatorAvailable']=1
receivedEvent=yield self.env.any_of([self.isRequested, self.canDispose, self.loadOperatorAvailable])
self.printTrace(self.id, received='')
self.printTrace(self.environment,self.id, received='')
# if the event that activated the thread is isRequested then getEntity
if self.isRequested in receivedEvent:
transmitter, eventTime=self.isRequested.value
self.printTrace(self.id, isRequested=transmitter.id)
self.printTrace(self.environment,self.id, isRequested=transmitter.id)
# reset the isRequested signal parameter
self.isRequested=self.env.event()
self.getEntity()
......
......@@ -44,6 +44,7 @@ class EntityGenerator(object):
def __init__(self, victim=None):
self.type="EntityGenerator" #String that shows the type of object
self.victim=victim
self.environment=victim.environment
self.env=victim.environment.SimPyEnvironment
#===========================================================================
......@@ -57,11 +58,11 @@ class EntityGenerator(object):
entity.creationTime=self.env.now # assign the current simulation time as the Entity's creation time
entity.startTime=self.env.now # assign the current simulation time as the Entity's start time
entity.currentStation=self.victim # update the current station of the Entity
G.EntityList.append(entity)
self.victim.outputTrace(entity.name, "generated") # output the trace
self.environment.EntityList.append(entity)
self.victim.outputTrace(self.environment,entity.name, "generated") # output the trace
self.victim.getActiveObjectQueue().append(entity) # append the entity to the resource
self.victim.numberOfArrivals+=1 # we have one new arrival
G.numberOfEntities+=1
self.environment.numberOfEntities+=1
self.victim.appendEntity(entity)
if self.victim.expectedSignals['entityCreated']:
succeedTupple=(entity,self.env.now)
......@@ -69,7 +70,7 @@ class EntityGenerator(object):
self.victim.expectedSignals['entityCreated']=0
# else put it on the time list for scheduled Entities
else:
entityCounter=G.numberOfEntities+len(self.victim.scheduledEntities) # this is used just ot output the trace correctly
entityCounter=self.environment.numberOfEntities+len(self.victim.scheduledEntities) # this is used just ot output the trace correctly
self.victim.scheduledEntities.append(self.env.now)
self.victim.outputTrace(self.victim.item.type+str(entityCounter), "generated") # output the trace
yield self.env.timeout(self.victim.calculateInterArrivalTime()) # wait until the next arrival
......@@ -117,13 +118,9 @@ class Source(CoreObject):
self.entityGenerator=EntityGenerator(victim=self) # the EntityGenerator of the Source
self.numberOfArrivals = 0
# self.entityGenerator.initialize()
# activate(self.entityGenerator,self.entityGenerator.run())
self.env.process(self.entityGenerator.run())
# self.entityCreated=SimEvent('an entity is created')
self.entityCreated=self.env.event()
# event used by router
# self.loadOperatorAvailable=SimEvent('loadOperatorAvailable')
self.loadOperatorAvailable=self.env.event()
self.scheduledEntities=[] # list of creations that are scheduled
......@@ -144,7 +141,7 @@ class Source(CoreObject):
self.expectedSignals['entityCreated']=1
self.expectedSignals['loadOperatorAvailable']=1
receivedEvent=yield self.env.any_of([self.entityCreated, self.canDispose, self.loadOperatorAvailable])
self.printTrace(self.id, received='')
self.printTrace(self.environment,self.id, received='')
# if an entity is created try to signal the receiver and continue
if self.entityCreated in receivedEvent:
transmitter, eventTime=self.entityCreated.value
......@@ -167,9 +164,9 @@ class Source(CoreObject):
from Globals import ManPyEnvironment
assert entity, 'cannot append None entity'
activeEntity=entity
if G.RouterList:
if self.environment.RouterList:
# at the newly created entity to the pendingEntities
G.pendingEntities.append(activeEntity)
self.environment.pendingEntities.append(activeEntity)
#============================================================================
# sets the routing out element for the Source
......@@ -180,8 +177,9 @@ class Source(CoreObject):
# creates an Entity
#============================================================================
def createEntity(self):
self.printTrace(self.id, create='')
return self.item(id = self.item.type+str(G.numberOfEntities), name = self.item.type+str(self.numberOfArrivals)) #return the newly created Entity
self.printTrace(self.environment,self.id, create='')
return self.item(id = self.item.type+str(self.environment.numberOfEntities),
name = self.item.type+str(self.numberOfArrivals)) #return the newly created Entity
#============================================================================
# calculates the processing time
#============================================================================
......@@ -198,10 +196,10 @@ class Source(CoreObject):
newEntity.startTime=newEntity.creationTime # assign the current simulation time as the Entity's start time
#print self.env.now, 'getting from the list. StartTime=',newEntity.startTime
newEntity.currentStation=self # update the current station of the Entity
G.EntityList.append(newEntity)
self.environment.EntityList.append(newEntity)
self.getActiveObjectQueue().append(newEntity) # append the entity to the resource
self.numberOfArrivals+=1 # we have one new arrival
G.numberOfEntities+=1
self.environment.numberOfEntities+=1
self.appendEntity(newEntity)
activeEntity=CoreObject.removeEntity(self, entity) # run the default method
if len(self.getActiveObjectQueue())==1:
......
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