Commit 17c96432 authored by Jérome Perrin's avatar Jérome Perrin

simplify initialisation of random numbers for core objects

parent 6fbe0fbf
......@@ -42,7 +42,7 @@ class Assembly(CoreObject):
self.type="Assembly" #String that shows the type of object
self.distType=distribution #the distribution that the procTime follows
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=mean
self.rng.mean=mean
self.rng.stdev=stdev
self.rng.min=min
self.rng.max=max
......
......@@ -56,7 +56,7 @@ class BatchDecomposition(CoreObject):
self.operator=operator
# Sets the attributes of the processing (and failure) time(s)
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=mean
self.rng.mean=mean
self.rng.stdev=stdev
self.rng.min=min
self.rng.max=max
......
......@@ -60,7 +60,7 @@ class BatchReassembly(CoreObject):
self.operator=operator
# Sets the attributes of the processing (and failure) time(s)
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=mean
self.rng.mean=mean
self.rng.stdev=stdev
self.rng.min=min
self.rng.max=max
......
......@@ -39,15 +39,18 @@ class BatchScrapMachine(Machine):
#initialize the id, the capacity of the resource and the distribution
# have to find which distribution returns random integers - Discrete distribution
def __init__(self, id, name, capacity=1, \
processingTime=None,
distribution='Fixed', mean=1, stdev=0, min=0, max=10,\
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None',\
scrapDistribution='Fixed',scrMean=1,scrStdev=0,scrMin=0,scrMax=10,
**kw):
if not processingTime:
print "TODO"
# initialize using the default method of the object
Machine.__init__(self,id=id,name=name,\
capacity=capacity,\
distribution=distribution,\
mean=mean,stdev=stdev,min=min,max=max,\
processingTime=dict(distributionType=distribution,
mean=mean,stdev=stdev,min=min,max=max,),
failureDistribution=failureDistribution,MTTF=MTTF,MTTR=MTTR,\
availability=availability,
repairman=repairman, **kw)
......@@ -55,7 +58,7 @@ class BatchScrapMachine(Machine):
self.scrapDistType=scrapDistribution #the distribution that the failure follows
# Sets the attributes of the scrap quantity distribution
self.scrapRng=RandomNumberGenerator(self, self.scrapDistType)
self.scrapRng.avg=scrMean
self.scrapRng.mean=scrMean
self.scrapRng.stdev=scrStdev
self.scrapRng.min=scrMin
self.scrapRng.max=scrMax
......
......@@ -47,7 +47,7 @@ class Dismantle(CoreObject):
self.type="Dismantle" #String that shows the type of object
self.distType=distribution #the distribution that the procTime follows
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=mean
self.rng.mean=mean
self.rng.stdev=stdev
self.rng.min=min
self.rng.max=max
......
......@@ -73,9 +73,9 @@ class Failure(ObjectInterruption):
# if the distribution is fixed
# --------------------------------------------------------------
self.rngTTF=RandomNumberGenerator(self, self.distType)
self.rngTTF.avg=MTTF
self.rngTTF.mean=MTTF
self.rngTTR=RandomNumberGenerator(self, self.distType)
self.rngTTR.avg=MTTR
self.rngTTR.mean=MTTR
# =======================================================================
# The run method for the failure which has to served by a repairman
......
......@@ -7,7 +7,7 @@ schema = {
"id": "entity",
"type": "string",
"_class": "Dream.Property",
"_default": "Part"
"_default": "Dream.Part"
},
"mean": {
"id": "mean",
......
......@@ -312,9 +312,8 @@ def createObjects():
for repairman in G.RepairmanList: # check which repairman in the G.RepairmanList
if(id in repairman.coreObjectIds): # (if any) is assigned to repair
r=repairman # the machine with ID equal to id
M=Machine(id, name, 1, distribution=distributionType, failureDistribution=failureDistribution,
M=Machine(id, name, 1, processingTime, failureDistribution=failureDistribution,
MTTF=MTTF, MTTR=MTTR, availability=availability, #repairman=r,
mean=mean,stdev=stdev,min=min,max=max,
operatorPool=machineOperatorPoolList, operationType=operationType,
loadDistribution=loadDistribution, setupDistribution=setupDistribution,
setupMean=setupMean,setupStdev=setupStdev,setupMin=setupMin,setupMax=setupMax,
......
......@@ -44,27 +44,30 @@ class Machine(CoreObject):
# =======================================================================
# initialise the id the capacity, of the resource and the distribution
# =======================================================================
def __init__(self, id, name, capacity=1, distribution='Fixed', mean=1, stdev=0, min=0, max=10,\
def __init__(self, id, name, capacity=1, processingTime=None,
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None',\
operatorPool='None',operationType='None',\
loadDistribution="No",loadMean=0, loadStdev=0, loadMin=0, loadMax=10,
setupDistribution="No",setupMean=0, setupStdev=0, setupMin=0, setupMax=10,
isPreemptive=False, resetOnPreemption=False, **kw):
CoreObject.__init__(self, id, name)
self.type="Machine" #String that shows the type of object
if not processingTime:
processingTime = {'distributionType': 'Fixed',
'mean': 1,
'stdev': 0,
'min': 0,
'max': 10}
# holds the capacity of the machine
self.capacity=capacity
# define the distribution types of the processing and failure times respectively
self.distType=distribution #the distribution that the procTime follows
self.failureDistType=failureDistribution #the distribution that the failure follows
# sets the repairman resource of the Machine
self.repairman=repairman
# Sets the attributes of the processing (and failure) time(s)
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=mean
self.rng.stdev=stdev
self.rng.min=min
self.rng.max=max
self.rng=RandomNumberGenerator(self, **processingTime)
self.MTTF=MTTF
self.MTTR=MTTR
self.availability=availability
......@@ -97,7 +100,7 @@ class Machine(CoreObject):
# define the load times
self.loadDistType=loadDistribution
self.loadRng=RandomNumberGenerator(self, self.loadDistType)
self.loadRng.avg=loadMean
self.loadRng.mean=loadMean
self.loadRng.stdev=loadStdev
self.loadRng.min=loadMin
self.loadRng.max=loadMax
......@@ -106,7 +109,7 @@ class Machine(CoreObject):
# define the setup times
self.setupDistType=setupDistribution
self.stpRng=RandomNumberGenerator(self, self.setupDistType)
self.stpRng.avg=setupMean
self.stpRng.mean=setupMean
self.stpRng.stdev=setupStdev
self.stpRng.min=setupMin
self.stpRng.max=setupMax
......
......@@ -80,7 +80,7 @@ class OperatedMachine(Machine):
# define the load times
self.loadDistType=loadDistribution
self.loadRng=RandomNumberGenerator(self, self.loadDistType)
self.loadRng.avg=loadMean
self.loadRng.mean=loadMean
self.loadRng.stdev=loadStdev
self.loadRng.min=loadMin
self.loadRng.max=loadMax
......@@ -89,7 +89,7 @@ class OperatedMachine(Machine):
# define the setup times
self.setupDistType=setupDistribution
self.stpRng=RandomNumberGenerator(self, self.setupDistType)
self.stpRng.avg=setupMean
self.stpRng.mean=setupMean
self.stpRng.stdev=setupStdev
self.stpRng.min=setupMin
self.stpRng.max=setupMax
......
......@@ -26,36 +26,33 @@ Created on 14 Feb 2013
holds methods for generations of numbers from different distributions
'''
class RandomNumberGenerator(object):
def __init__(self, obj, type):
self.distType=type
self.avg=0
self.stdev=0
self.min=0
self.max=0
#self.availability=0
self.alpha=0
self.beta=0
self.object=obj
def __init__(self, obj, distributionType, mean=0, avg=0, stdev=0, min=0, max=0, alpha=0, beta=0):
self.distributionType = distributionType
self.avg = avg
self.mean = mean
self.stdev = stdev
self.min = min
self.max = max
self.alpha = alpha
self.beta = beta
self.obj = obj
def generateNumber(self):
from Globals import G
number=0
if(self.distType=="Fixed"): #if the distribution is Fixed
number=self.avg
elif(self.distType=="Exp"): #if the distribution is Exponential
number=G.Rnd.expovariate(1.0/(self.avg))
elif(self.distType=="Normal"): #if the distribution is Normal
if(self.distributionType=="Fixed"): #if the distribution is Fixed
return self.mean
elif(self.distributionType=="Exp"): #if the distribution is Exponential
return G.Rnd.expovariate(1.0/(self.avg))
elif(self.distributionType=="Normal"): #if the distribution is Normal
while 1:
number=G.Rnd.normalvariate(self.avg, self.stdev)
if number>self.max or number<self.min and max!=0: #if the number is out of bounds repeat the process #if max=0 this means that we did not have time "time" bounds
continue
else: #if the number is in the limits stop the process
break
elif self.distType=="Erlang": #if the distribution is erlang
number=G.Rnd.gammavariate(self.alpha,self.beta)
return number
elif self.distributionType=="Erlang": #if the distribution is erlang
return G.Rnd.gammavariate(self.alpha, self.beta)
else:
raise ValueError("Unknown distribution %r used in %s %s" %
(self.distType, self.object.type, self.object.id))
return number
(self.distributionType, self.obj.__class__, self.obj.id))
......@@ -41,7 +41,6 @@ class Source(CoreObject):
interarrivalTime = {'distributionType': 'Fixed', 'mean': 1}
CoreObject.__init__(self, id, name)
self.distType = interarrivalTime['distributionType'] # label that sets the distribution type
# properties used for statistics
self.totalInterArrivalTime = 0 # the total interarrival time
self.numberOfArrivals = 0 # the number of entities that were created
......@@ -52,10 +51,7 @@ class Source(CoreObject):
# # For the source it is always empty!
self.type="Source" #String that shows the type of object
# XXX we could just initialize RandomNumberGenerator by passing
# interarrivalTime dict
self.rng = RandomNumberGenerator(self, self.distType)
self.rng.avg = interarrivalTime['mean']
self.rng = RandomNumberGenerator(self, **interarrivalTime)
self.item=Globals.getClassFromName(item) #the type of object that the Source will generate
......
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