def selectReceiver(self, possibleReceivers=[]): #if all the possibleReceivers have the same priority work as cycle priorityList = [] for element in possibleReceivers: priorityList.append(element.priority) if len(priorityList): if priorityList.count(priorityList[0]) == len(priorityList): return Queue.selectReceiver(possibleReceivers) # else sort the receivers according to their priority possibleReceivers.sort(key=lambda x: x.priority, reverse=True) if possibleReceivers[0].canAccept(): return possibleReceivers[0] elif possibleReceivers[1].canAccept(): return possibleReceivers[1] return None
def selectReceiver(self,possibleReceivers=[]): #if all the possibleReceivers have the same priority work as cycle priorityList=[] for element in possibleReceivers: priorityList.append(element.priority) if len(priorityList): if priorityList.count(priorityList[0]) == len(priorityList): return Queue.selectReceiver(possibleReceivers) # else sort the receivers according to their priority possibleReceivers.sort(key=lambda x: x.priority, reverse=True) if possibleReceivers[0].canAccept(): return possibleReceivers[0] elif possibleReceivers[1].canAccept(): return possibleReceivers[1] return None
from dream.simulation.imports import Machine, Source, Exit, Part, Queue, NonStarvingEntry from dream.simulation.Globals import runSimulation #define the objects of the model NS=NonStarvingEntry('NS1','Entry',entityData={'_class':'Dream.Part'}) M1=Machine('M1','Machine1', processingTime={'Exp':{'mean':1}}) Q2=Queue('Q2','Queue2') M2=Machine('M2','Machine2', processingTime={'Exp':{'mean':3}}) Q3=Queue('Q3','Queue3') M3=Machine('M3','Machine3', processingTime={'Exp':{'mean':5}}) E=Exit('E1','Exit') #define predecessors and successors for the objects NS.defineRouting(successorList=[M1]) M1.defineRouting(predecessorList=[NS],successorList=[Q2]) Q2.defineRouting(predecessorList=[M1],successorList=[M2]) M2.defineRouting(predecessorList=[Q2],successorList=[Q3]) Q3.defineRouting(predecessorList=[M2],successorList=[M3]) M3.defineRouting(predecessorList=[Q3],successorList=[E]) E.defineRouting(predecessorList=[M3]) def main(test=0): # add all the objects in a list objectList=[NS,M1,M2,M3,Q2,Q3,E] # set the length of the experiment maxSimTime=480 solutionList=[] for i in range(1,10):
# This is the baby step to building a complicated model of the behavior # of a fleet of systems with multiple stakeholders. # The baby step includes: # A source to generate students # A Queue for students to wait for a flight # A machine (aircraft) to give students time # An exit for graduated students # The source is API for Aviation Preflight Indocrination API = Source('API', 'Source', interArrivalTime={'Fixed': { 'mean': 0.5 }}, entity='Dream.Part') RR = Queue('ReadyRoom', 'Queue', capacity=1) AC = Machine('AC1', 'Machine', processingTime={'Fixed': {'mean': 0.25}}) E = Exit('The Fleet', 'The Fleet') # The predecessors and successors for the objects API.defineRouting(successorList=[RR]) RR.defineRouting(predecessorList=[API], successorList=[AC]) AC.defineRouting(predecessorList=[RR], successorList=[E]) E.defineRouting(predecessorList=[AC]) def main(test=0): # add all the objects in a list objectList = [API, RR, AC, E] # set the length of the experiment maxSimTime = 1440.0
from dream.simulation.imports import Machine, Queue, Exit, Part, ExcelHandler from dream.simulation.Globals import runSimulation, G #define the objects of the model Q=Queue('Q1','Queue', capacity=1) M=Machine('M1','Machine', processingTime={'Fixed':{'mean':0.25}}) E=Exit('E1','Exit') P1=Part('P1', 'Part1', currentStation=Q) #define predecessors and successors for the objects Q.defineRouting(successorList=[M]) M.defineRouting(predecessorList=[Q],successorList=[E]) E.defineRouting(predecessorList=[M]) def main(test=0): # add all the objects in a list objectList=[Q,M,E,P1] # set the length of the experiment maxSimTime=float('inf') # call the runSimulation giving the objects and the length of the experiment runSimulation(objectList, maxSimTime, trace='Yes') # calculate metrics working_ratio = (M.totalWorkingTime/G.maxSimTime)*100 # return results for the test if test: return {"parts": E.numOfExits, "simulationTime":E.timeLastEntityLeft, "working_ratio": working_ratio}
from dream.simulation.imports import Machine, Source, Exit, Batch, BatchDecomposition,\ BatchSource, BatchReassembly, Queue, LineClearance, ExcelHandler, ExcelHandler from dream.simulation.Globals import runSimulation # define the objects of the model S=BatchSource('S','Source',interArrivalTime={'Fixed':{'mean':1.5}}, entity='Dream.Batch', batchNumberOfUnits=100) Q=Queue('Q','StartQueue',capacity=100000) BD=BatchDecomposition('BC', 'BatchDecomposition', numberOfSubBatches=4, processingTime={'Fixed':{'mean':1}}) M1=Machine('M1','Machine1',processingTime={'Fixed':{'mean':0.5}}) Q1=LineClearance('Q1','Queue1',capacity=2) M2=Machine('M2','Machine2',processingTime={'Fixed':{'mean':4}}) BRA=BatchReassembly('BRA', 'BatchReassembly', numberOfSubBatches=4, processingTime={'Fixed':{'mean':0}}) M3=Machine('M3','Machine3',processingTime={'Fixed':{'mean':1}}) E=Exit('E','Exit') # define the predecessors and successors for the objects S.defineRouting([Q]) Q.defineRouting([S],[BD]) BD.defineRouting([Q],[M1]) M1.defineRouting([BD],[Q1]) Q1.defineRouting([M1],[M2]) M2.defineRouting([Q1],[BRA]) BRA.defineRouting([M2],[M3]) M3.defineRouting([BRA],[E]) E.defineRouting([M3]) def main(test=0): # add all the objects in a list objectList=[S,Q,BD,M1,Q1,M2,BRA,M3,E] # set the length of the experiment
def canAccept(self, callerObject=None): # if the next machine holds a part return false if len(self.next[0].getActiveObjectQueue()): return False # else use the default Queue logic return Queue.canAccept(self, callerObject)
from dream.simulation.imports import Machine, Source, Exit, Part, Queue, NonStarvingEntry from dream.simulation.Globals import runSimulation #define the objects of the model NS = NonStarvingEntry('NS1', 'Entry', entityData={'_class': 'Dream.Part'}) M1 = Machine('M1', 'Machine1', processingTime={'Exp': {'mean': 1}}) Q2 = Queue('Q2', 'Queue2') M2 = Machine('M2', 'Machine2', processingTime={'Exp': {'mean': 3}}) Q3 = Queue('Q3', 'Queue3') M3 = Machine('M3', 'Machine3', processingTime={'Exp': {'mean': 5}}) E = Exit('E1', 'Exit') #define predecessors and successors for the objects NS.defineRouting(successorList=[M1]) M1.defineRouting(predecessorList=[NS], successorList=[Q2]) Q2.defineRouting(predecessorList=[M1], successorList=[M2]) M2.defineRouting(predecessorList=[Q2], successorList=[Q3]) Q3.defineRouting(predecessorList=[M2], successorList=[M3]) M3.defineRouting(predecessorList=[Q3], successorList=[E]) E.defineRouting(predecessorList=[M3]) def main(test=0): # add all the objects in a list objectList = [NS, M1, M2, M3, Q2, Q3, E] # set the length of the experiment maxSimTime = 480 solutionList = [] for i in range(1, 10):
def canAccept(self, callerObject=None): if self.locked: return False return Queue.canAccept(self, callerObject)
activeEntity = Machine.removeEntity(self, entity) # count the number of parts in the server. # If it is empty have one internal queue to signal the queue before the compound object if not self.countInternalParts(): self.sendSignal(receiver=QB, signal=QB.canDispose, sender=Q1) return activeEntity # returns the number of internal parts in the server def countInternalParts(self): totalParts = 0 for object in G.InternalProcessList + G.InternalQueueList: totalParts += len(object.getActiveObjectQueue()) return totalParts QB = Queue('QB', 'QueueBefore', capacity=float("inf")) Q1 = InternalQueue('Q1', 'Q1', capacity=1) M1 = InternalProcess('M1', 'M1', processingTime={'Exp': {'mean': 1}}) Q2 = InternalQueue('Q2', 'Q2', capacity=1) M2 = InternalProcess('M2', 'M2', processingTime={'Exp': {'mean': 1}}) Q3 = InternalQueue('Q3', 'Q3', capacity=1) M3 = InternalProcess('M3', 'M3', processingTime={'Exp': {'mean': 1}}) QA = Queue('QA', 'QueueAfter', capacity=float("inf")) MA = Machine('MA', 'MachineAfter', processingTime={'Exp': {'mean': 1}}) E = Exit('E', 'Exit') QB.defineRouting(successorList=[Q1, Q2, Q3]) Q1.defineRouting(predecessorList=[QB], successorList=[M1]) Q2.defineRouting(predecessorList=[QB], successorList=[M2]) Q3.defineRouting(predecessorList=[QB], successorList=[M3]) M1.defineRouting(predecessorList=[Q1], successorList=[QA])
from dream.simulation.imports import Machine, Source, Exit, Part, Queue, Failure from dream.simulation.Globals import runSimulation #define the objects of the model S = Source('S', 'Source', interArrivalTime={'Fixed': { 'mean': 0.5 }}, entity='Dream.Part') Q = Queue('Q', 'Queue', capacity=float("inf")) M1 = Machine('M1', 'Milling1', processingTime={'Fixed': {'mean': 0.25}}) M2 = Machine('M2', 'Milling2', processingTime={'Fixed': {'mean': 0.25}}) E = Exit('E1', 'Exit') F = Failure(victim=M1, distribution={ 'TTF': { 'Fixed': { 'mean': 60.0 } }, 'TTR': { 'Fixed': { 'mean': 5.0 } } }) #define predecessors and successors for the objects S.defineRouting([Q]) Q.defineRouting([S], [M1, M2])
from dream.simulation.imports import Machine, BatchSource, Exit, Batch, BatchDecomposition, BatchReassembly, Queue from dream.simulation.Globals import runSimulation # define the objects of the model S=BatchSource('S','Source',interarrivalTime={'distributionType':'Fixed','mean':1.5}, entity='Dream.Batch', batchNumberOfUnits=100) Q=Queue('Q','StartQueue',capacity=100000) BD=BatchDecomposition('BC', 'BatchDecomposition', numberOfSubBatches=4, processingTime={'distributionType':'Fixed','mean':1}) M1=Machine('M1','Machine1',processingTime={'distributionType':'Fixed','mean':0.5}) Q1=Queue('Q1','Queue1',capacity=2) M2=Machine('M2','Machine2',processingTime={'distributionType':'Fixed','mean':1}) BRA=BatchReassembly('BRA', 'BatchReassembly', numberOfSubBatches=4, processingTime={'distributionType':'Fixed','mean':0}) M3=Machine('M3','Machine3',processingTime={'distributionType':'Fixed','mean':1}) E=Exit('E','Exit') # define the predecessors and successors for the objects S.defineRouting([Q]) Q.defineRouting([S],[BD]) BD.defineRouting([Q],[M1]) M1.defineRouting([BD],[Q1]) Q1.defineRouting([M1],[M2]) M2.defineRouting([Q1],[BRA]) BRA.defineRouting([M2],[M3]) M3.defineRouting([BRA],[E]) E.defineRouting([M3]) def main(test=0): # add all the objects in a list objectList=[S,Q,BD,M1,Q1,M2,BRA,M3,E] # set the length of the experiment maxSimTime=1440.0 # call the runSimulation giving the objects and the length of the experiment
from dream.simulation.imports import Machine, BatchSource, Exit, Batch, BatchDecomposition, BatchReassembly, Queue from dream.simulation.Globals import runSimulation # define the objects of the model S = BatchSource('S', 'Source', interArrivalTime={'Fixed': { 'mean': 1.5 }}, entity='Dream.Batch', batchNumberOfUnits=100) Q = Queue('Q', 'StartQueue', capacity=100000) BD = BatchDecomposition('BC', 'BatchDecomposition', numberOfSubBatches=4, processingTime={'Fixed': { 'mean': 1 }}) M1 = Machine('M1', 'Machine1', processingTime={'Fixed': {'mean': 0.5}}) Q1 = Queue('Q1', 'Queue1', capacity=2) M2 = Machine('M2', 'Machine2', processingTime={'Fixed': {'mean': 1}}) BRA = BatchReassembly('BRA', 'BatchReassembly', numberOfSubBatches=4, processingTime={'Fixed': { 'mean': 0 }}) M3 = Machine('M3', 'Machine3', processingTime={'Fixed': {'mean': 1}}) E = Exit('E', 'Exit') # define the predecessors and successors for the objects
from dream.simulation.imports import Source, Queue, Machine, Exit from dream.simulation.Globals import runSimulation #define the objects of the model S=Source('S1','Source',interArrivalTime={'Fixed':{'mean':0.5}}, entity='Dream.Part') Q=Queue('Q1','Queue', capacity=1) M=Machine('M1','Machine', processingTime={'Fixed':{'mean':0.25}}) E=Exit('E1','Exit') #define predecessors and successors for the objects S.defineRouting(successorList=[Q]) Q.defineRouting(predecessorList=[S],successorList=[M]) M.defineRouting(predecessorList=[Q],successorList=[E]) E.defineRouting(predecessorList=[M]) def main(test=0): # add all the objects in a list objectList=[S,Q,M,E] # set the length of the experiment maxSimTime=1440.0 # call the runSimulation giving the objects and the length of the experiment runSimulation(objectList, maxSimTime) # calculate metrics working_ratio = (M.totalWorkingTime/maxSimTime)*100 # return results for the test if test: return {"parts": E.numOfExits, "working_ratio": working_ratio}
from dream.simulation.imports import Machine, Source, Exit, Batch, BatchDecomposition,\ BatchSource, BatchReassembly, Queue, LineClearance, ExcelHandler, ExcelHandler from dream.simulation.Globals import runSimulation # define the objects of the model S = BatchSource('S', 'Source', interArrivalTime={'Fixed': { 'mean': 1.5 }}, entity='Dream.Batch', batchNumberOfUnits=100) Q = Queue('Q', 'StartQueue', capacity=100000) BD = BatchDecomposition('BC', 'BatchDecomposition', numberOfSubBatches=4, processingTime={'Fixed': { 'mean': 1 }}) M1 = Machine('M1', 'Machine1', processingTime={'Fixed': {'mean': 0.5}}) Q1 = LineClearance('Q1', 'Queue1', capacity=2) M2 = Machine('M2', 'Machine2', processingTime={'Fixed': {'mean': 4}}) BRA = BatchReassembly('BRA', 'BatchReassembly', numberOfSubBatches=4, processingTime={'Fixed': { 'mean': 0 }}) M3 = Machine('M3', 'Machine3', processingTime={'Fixed': {'mean': 1}}) E = Exit('E', 'Exit')
from dream.simulation.imports import Source, Queue, Machine, Exit from dream.simulation.Globals import runSimulation # This is the baby step to building a complicated model of the behavior # of a fleet of systems with multiple stakeholders. # The baby step includes: # A source to generate students # A Queue for students to wait for a flight # A machine (aircraft) to give students time # An exit for graduated students # The source is API for Aviation Preflight Indocrination API = Source('API', 'Source', interArrivalTime={'Fixed': {'mean': 0.5}}, entity='Dream.Part') RR = Queue('ReadyRoom', 'Queue', capacity=1) AC = Machine('AC1', 'Machine', processingTime={'Fixed': {'mean': 0.25}}) E = Exit('The Fleet', 'The Fleet') # The predecessors and successors for the objects API.defineRouting(successorList=[RR]) RR.defineRouting(predecessorList=[API], successorList=[AC]) AC.defineRouting(predecessorList=[RR], successorList=[E]) E.defineRouting(predecessorList=[AC]) def main(test=0): # add all the objects in a list objectList=[API, RR, AC, E] # set the length of the experiment maxSimTime = 1440.0 # call the runSimulation giving the objects and the length of the # experiment
# run the default method activeEntity=Machine.removeEntity(self, entity) # count the number of parts in the server. # If it is empty have one internal queue to signal the queue before the compound object if not self.countInternalParts(): self.sendSignal(receiver=QB, signal=QB.canDispose, sender=Q1) return activeEntity # returns the number of internal parts in the server def countInternalParts(self): totalParts=0 for object in G.InternalProcessList+G.InternalQueueList: totalParts+=len(object.getActiveObjectQueue()) return totalParts QB=Queue('QB','QueueBefore', capacity=float("inf")) Q1=InternalQueue('Q1','Q1', capacity=1) M1=InternalProcess('M1','M1',processingTime={'Exp':{'mean':1}}) Q2=InternalQueue('Q2','Q2', capacity=1) M2=InternalProcess('M2','M2',processingTime={'Exp':{'mean':1}}) Q3=InternalQueue('Q3','Q3', capacity=1) M3=InternalProcess('M3','M3',processingTime={'Exp':{'mean':1}}) QA=Queue('QA','QueueAfter', capacity=float("inf")) MA=Machine('MA','MachineAfter',processingTime={'Exp':{'mean':1}}) E=Exit('E','Exit') QB.defineRouting(successorList=[Q1,Q2,Q3]) Q1.defineRouting(predecessorList=[QB],successorList=[M1]) Q2.defineRouting(predecessorList=[QB],successorList=[M2]) Q3.defineRouting(predecessorList=[QB],successorList=[M3]) M1.defineRouting(predecessorList=[Q1],successorList=[QA])
else: for buffer in possiblePredecessors: if not buffer == machine.previous[0]: machine.previous[0] = buffer break # if canDispose is not triggered in the predecessor send it if not machine.previous[0].canDispose.triggered: # a succeed function on an event must always take attributes the transmitter and the time of the event succeedTuple = (machine, G.env.now) machine.previous[0].canDispose.succeed(succeedTuple) print G.env.now, 'from now on the machine will take from', machine.previous[ 0].id #define the objects of the model Q1 = Queue('Q1', 'Queue1', capacity=float('inf')) Q2 = Queue('Q2', 'Queue2', capacity=float('inf')) M = Machine('M1', 'Machine', processingTime={'Fixed': {'mean': 3}}) E = Exit('E1', 'Exit') P1 = Part('P1', 'Part1', currentStation=Q1) entityList = [] for i in range(5): # create the WIP in a loop Q1PartId = 'Q1_P' + str(i) Q1PartName = 'Q1_Part' + str(i) PQ1 = Part(Q1PartId, Q1PartName, currentStation=Q1) entityList.append(PQ1) Q2PartId = 'Q2_P' + str(i) Q2PartName = 'Q2_Part' + str(i) PQ2 = Part(Q2PartId, Q2PartName, currentStation=Q2) entityList.append(PQ2)
from dream.simulation.imports import Machine, Source, Exit, Part, Repairman, Queue, Failure from dream.simulation.Globals import runSimulation #define the objects of the model R = Repairman('R1', 'Bob') S = Source('S1', 'Source', interArrivalTime={'Fixed': { 'mean': 0.5 }}, entity='Dream.Part') M1 = Machine('M1', 'Machine1', processingTime={'Fixed': {'mean': 0.25}}) Q = Queue('Q1', 'Queue') M2 = Machine('M2', 'Machine2', processingTime={'Fixed': {'mean': 1.5}}) E = Exit('E1', 'Exit') #create failures F1 = Failure(victim=M1, distribution={ 'TTF': { 'Fixed': { 'mean': 60.0 } }, 'TTR': { 'Fixed': { 'mean': 5.0 } } }, repairman=R) F2 = Failure(victim=M2,
from dream.simulation.imports import Machine, Source, Exit, Part, G, Repairman, Queue, Failure from dream.simulation.imports import simulate, activate, initialize #define the objects of the model R=Repairman('R1', 'Bob') S=Source('S1','Source', interarrivalTime={'distributionType':'Fixed','mean':0.5}, entity='Dream.Part') M1=Machine('M1','Machine1', processingTime={'distributionType':'Fixed','mean':0.25}) Q=Queue('Q1','Queue') M2=Machine('M2','Machine2', processingTime={'distributionType':'Fixed','mean':1.5}) E=Exit('E1','Exit') #create failures F1=Failure(victim=M1, distribution={'distributionType':'Fixed','MTTF':60,'MTTR':5}, repairman=R) F2=Failure(victim=M2, distribution={'distributionType':'Fixed','MTTF':40,'MTTR':10}, repairman=R) G.ObjList=[S,M1,M2,E,Q] #add all the objects in G.ObjList so that they can be easier accessed later G.MachineList=[M1,M2] G.ObjectInterruptionList=[F1,F2] #add all the objects in G.ObjList so that they can be easier accessed later #define predecessors and successors for the objects S.defineRouting([M1]) M1.defineRouting([S],[Q]) Q.defineRouting([M1],[M2]) M2.defineRouting([Q],[E]) E.defineRouting([M2]) def main(): initialize() #initialize the simulation (SimPy method) #initialize all the objects
from dream.simulation.imports import Machine, Source, Exit, Part, Queue, G, Failure from dream.simulation.imports import simulate, activate, initialize, infinity #define the objects of the model S=Source('S','Source', interarrivalTime={'distributionType':'Fixed','mean':0.5}, entity='Dream.Part') Q=Queue('Q','Queue', capacity=infinity) M1=Machine('M1','Milling1', processingTime={'distributionType':'Fixed','mean':0.25}) M2=Machine('M2','Milling2', processingTime={'distributionType':'Fixed','mean':0.25}) E=Exit('E1','Exit') F=Failure(victim=M1, distribution={'distributionType':'Fixed','MTTF':60,'MTTR':5}) G.ObjList=[S,Q,M1,M2,E] #add all the objects in G.ObjList so that they can be easier accessed later G.ObjectInterruptionList=[F] #add all the objects in G.ObjList so that they can be easier accessed later #define predecessors and successors for the objects S.defineRouting([Q]) Q.defineRouting([S],[M1,M2]) M1.defineRouting([Q],[E]) M2.defineRouting([Q],[E]) E.defineRouting([M1,M2]) def main(): initialize() #initialize the simulation (SimPy method) for object in G.ObjList: object.initialize() for objectInterruption in G.ObjectInterruptionList:
# else loop through the possible predecessors and if one is not the current # set this as predecessor and break else: for buffer in possiblePredecessors: if not buffer==machine.previous[0]: machine.previous[0]=buffer break # if canDispose is not triggered in the predecessor send it if not machine.previous[0].canDispose.triggered: # a succeed function on an event must always take attributes the transmitter and the time of the event succeedTuple=(machine, G.env.now) machine.previous[0].canDispose.succeed(succeedTuple) print G.env.now, 'from now on the machine will take from', machine.previous[0].id #define the objects of the model Q1=Queue('Q1','Queue1', capacity=float('inf')) Q2=Queue('Q2','Queue2', capacity=float('inf')) M=Machine('M1','Machine', processingTime={'Fixed':{'mean':3}}) E=Exit('E1','Exit') P1=Part('P1', 'Part1', currentStation=Q1) entityList=[] for i in range(5): # create the WIP in a loop Q1PartId='Q1_P'+str(i) Q1PartName='Q1_Part'+str(i) PQ1=Part(Q1PartId, Q1PartName, currentStation=Q1) entityList.append(PQ1) Q2PartId='Q2_P'+str(i) Q2PartName='Q2_Part'+str(i) PQ2=Part(Q2PartId, Q2PartName, currentStation=Q2) entityList.append(PQ2)
for i in range(refillLevel): # calculate the id and name of the new part partId = 'P' + str(G.numOfParts) partName = 'Part' + str(G.numOfParts) # create the Part P = Part(partId, partName, currentStation=buffer) # set the part as WIP setWIP([P]) G.numOfParts += 1 # else do nothing else: print 'buffer has', numInQueue, 'parts. No need to bring more' # define the objects of the model Q = Queue('Q1', 'Queue', capacity=float('inf')) M = Machine('M1', 'Machine', processingTime={'Fixed': {'mean': 6}}) E = Exit('E1', 'Exit') EV = EventGenerator('EV', 'EntityCreator', start=0, stop=float('inf'), interval=20, method=balanceQueue, argumentDict={ 'buffer': Q, 'refillLevel': 5 }) # counter used in order to give parts meaningful ids (e.g P1, P2...) and names (e.g. Part1, Part2...) G.numOfParts = 0