Commit 11247272 authored by Georgios Dagkakis's avatar Georgios Dagkakis

clean up and comments

parent 601abebe
......@@ -4,38 +4,49 @@ import random
from random import Random
Rnd = Random(3)
# transition probabilities
p=0.01
g=0.01
r=0.1
f=0.2
# the capacity of B123
capacity=35
class OpQueue(Queue):
# allow to be locked between the time periods
def canAccept(self, callerObject=None):
if self.locked:
return False
return Queue.canAccept(self, callerObject)
class OpExit(Exit):
# set numGoodParts=0 at every replication
def initialize(self):
self.numGoodParts=0
Exit.initialize(self)
# allow to be locked between the time periods
def canAccept(self, callerObject=None):
if self.locked:
return False
return True
# if the status of the entity is 'Good' update numGoodParts
def getEntity(self):
activeEntity=Exit.getEntity(self)
if activeEntity.status=='Good':
self.numGoodParts+=1
return activeEntity
# update the GoodExits list
def postProcessing(self):
Exit.postProcessing(self, MaxSimtime=1000.1)
self.GoodExits.append(self.numGoodParts)
class OpMachine(Machine):
# allow to be locked between the time periods
# also if there is failure (state=0) do not get new work
def canAccept(self, callerObject=None):
if self.locked:
return False
......@@ -43,17 +54,22 @@ class OpMachine(Machine):
return False
return Machine.canAccept(self, callerObject)
# set state=1 at the start of each replication
def initialize(self):
Machine.initialize(self)
self.state=1
# if the state is -1 set that the disposed Entity is 'Bad'
def removeEntity(self, entity):
activeEntity=Machine.removeEntity(self, entity)
if self.state==-1:
activeEntity.status='Bad'
return activeEntity
# method invoked by the generator at every time period
def controllerMethod():
# for every machine calculate the state (based on transition probabilities)
for M in [M1,M2,M3]:
rn1=createRandomNumber()
rn2=createRandomNumber()
......@@ -68,21 +84,22 @@ def controllerMethod():
elif M.state==-1:
if rn1<f:
M.state=0
# unlock E and let part get from M3 to E
E.locked=False
if len(M3.getActiveObjectQueue()) and (not M3.state==0):
# print '----> M3->E'
Controller.sendSignal(sender=M3, receiver=E,signal=E.isRequested)
yield G.env.timeout(0)
E.locked=True
# unlock M3 and let part get from B123 to M3
M3.locked=False
if len(B123.getActiveObjectQueue()) and (not M3.state==0):
# print '----> B123->M3'
Controller.sendSignal(sender=B123, receiver=M3,signal=M3.isRequested)
yield G.env.timeout(0)
M3.locked=True
# unlock B123 and let parts get from M1 and M2 to B123
B123.locked=False
if ((len(M1.getActiveObjectQueue())) and (not M1.state==0) \
or ((len(M2.getActiveObjectQueue())) and not M2.state==0))\
......@@ -96,7 +113,8 @@ def controllerMethod():
if len(B123.getActiveObjectQueue())==B123.capacity:
break
B123.locked=True
# unlock M1 and M2 and let parts get from NS1 to M1 and from NS2 to M2
M1.locked=False
M2.locked=False
if len(M1.getActiveObjectQueue())==0:
......@@ -105,13 +123,13 @@ def controllerMethod():
Controller.sendSignal(sender=NS2, receiver=M2,signal=M2.isRequested)
while 1:
yield G.env.timeout(0)
# print G.env.now, len(M1.getActiveObjectQueue()), M1.state, len(M2.getActiveObjectQueue()), M2.state
if (len(M1.getActiveObjectQueue()) or M1.state==0) \
and (len(M2.getActiveObjectQueue()) or M2.state==0):
M1.locked=True
M2.locked=True
break
# returns a number from the uniform distribution (0,1)
def createRandomNumber():
return Rnd.uniform(0,1)
......@@ -122,7 +140,7 @@ NS2=NonStarvingEntry('NS2','Entry2',entityData={'_class':'Dream.Part','status':'
M1=OpMachine('M1','Machine1', processingTime={'Fixed':{'mean':0.1}})
M2=OpMachine('M2','Machine2', processingTime={'Fixed':{'mean':0.1}})
M3=OpMachine('M3','Machine3', processingTime={'Fixed':{'mean':0.1}})
B123=OpQueue('B123','Queue', capacity=10)
B123=OpQueue('B123','Queue', capacity=capacity)
E=OpExit('E1','Exit')
Controller=EventGenerator('EV','Controller',start=0,interval=1,method=controllerMethod)
......@@ -138,9 +156,11 @@ E.defineRouting(predecessorList=[M3])
# add all the objects to a list
objectList=[NS1,NS2,M1,M2,M3,B123,E,Controller]
# set all objects locked at beginning
for obj in objectList:
obj.locked=True
# GoodExits will keep the number of good parts produced in every replication
E.GoodExits=[]
# call the runSimulation giving the objects and the length of the experiment
......
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