Commit 2f17b9a9 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Examples rearranged

parent fcdb080a
......@@ -3,44 +3,27 @@ from dream.simulation.Globals import runSimulation
#the custom queue
class SelectiveQueue(Queue):
# override so that it first chooses M1 and then M2
#override so that it chooses receiver according to priority
def selectReceiver(self,possibleReceivers=[]):
if M1.canAccept():
return M1
elif M2.canAccept():
return M2
# 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
#the custom machine
class Milling(Machine):
def getEntity(self):
activeEntity=Machine.getEntity(self) #call the parent method to get the entity
part=self.getActiveObjectQueue()[0] #retrieve the obtained part
part.machineId=self.id #create an attribute to the obtained part and give it the value of the object's id
return activeEntity #return the entity obtained
#the custom exit
class CountingExit(Exit):
def getEntity(self):
activeEntity=Exit.getEntity(self) #call the parent method to get the entity
#check the attribute and update the counters accordingly
if activeEntity.machineId=='M1':
G.NumM1+=1
elif activeEntity.machineId=='M2':
G.NumM2+=1
return activeEntity #return the entity obtained
#define the objects of the model
S=Source('S','Source', interarrivalTime={'distributionType':'Fixed','mean':0.5}, entity='Dream.Part')
Q=SelectiveQueue('Q','Queue', capacity=float("inf"))
M1=Milling('M1','Milling1', processingTime={'distributionType':'Fixed','mean':0.25})
M2=Milling('M2','Milling2', processingTime={'distributionType':'Fixed','mean':0.25})
E=CountingExit('E1','Exit')
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})
#create the global counter variables
G.NumM1=0
G.NumM2=0
#create priority attribute in the Machines
M1.priority=10
M2.priority=0
#define predecessors and successors for the objects
S.defineRouting([Q])
......@@ -64,13 +47,10 @@ def main():
working_ratio_M2=(M2.totalWorkingTime/maxSimTime)*100
print "the working ratio of", M1.objName, "is", working_ratio_M1, "%"
print "the working ratio of", M2.objName, "is", working_ratio_M2, "%"
print M1.objName, "produced", G.NumM1, "parts"
print M2.objName, "produced", G.NumM2, "parts"
return {"parts": E.numOfExits,
"working_ratio_M1": working_ratio_M1,
"working_ratio_M2": working_ratio_M2,
"NumM1":G.NumM1,
"NumM2":G.NumM2}
}
if __name__ == '__main__':
main()
......@@ -3,7 +3,7 @@ from dream.simulation.Globals import runSimulation
#the custom queue
class SelectiveQueue(Queue):
#override so that it first chooses M1 and then M2
#override so that it chooses receiver according to priority
def selectReceiver(self,possibleReceivers=[]):
# sort the receivers according to their priority
possibleReceivers.sort(key=lambda x: x.priority, reverse=True)
......@@ -48,7 +48,6 @@ G.NumM2=0
M1.priority=10
M2.priority=0
#define predecessors and successors for the objects
S.defineRouting([Q])
Q.defineRouting([S],[M1,M2])
......
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