Commit 11247272 authored by Georgios Dagkakis's avatar Georgios Dagkakis

clean up and comments

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