Commit f4d99470 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Ioannis Papagiannopoulos

changes to create random numbers based on the new format

parent 38044eb6
......@@ -70,7 +70,7 @@ class Machine(CoreObject):
# sets the repairman resource of the Machine
self.repairman=repairman
# Sets the attributes of the processing (and failure) time(s)
self.rng=RandomNumberGenerator(self, **processingTime)
self.rng=RandomNumberGenerator(self, processingTime)
# check whether the operators are provided with a skills set
# check whether the operators are provided with a skills set
self.dedicatedOperator=self.checkForDedicatedOperators()
......@@ -102,11 +102,11 @@ class Machine(CoreObject):
# boolean to check whether the machine is being operated
self.toBeOperated = False
# define the load times
self.loadRng = RandomNumberGenerator(self, **loadTime)
self.loadRng = RandomNumberGenerator(self, loadTime)
# XX variable that informs on the need for setup
self.setUp=True
# define the setup times
self.stpRng = RandomNumberGenerator(self, **setupTime)
self.stpRng = RandomNumberGenerator(self, setupTime)
# examine if there are multiple operation types performed by the operator
# there can be Setup/Processing operationType
# or the combination of both (MT-Load-Setup-Processing)
......@@ -192,25 +192,13 @@ class Machine(CoreObject):
@staticmethod
def getOperationTime(time):
def refactorTime(time):
if time:
if time["distribution"]:
time["distributionType"] = time["distribution"]
for key in time[time["distribution"]]:
time[key] = time[time["distribution"]][key]
del time[time["distribution"]]
del time["distribution"]
return time
# XXX update time to comply with old definition
time = refactorTime(time)
'''returns the dictionary updated'''
if not time:
time = { 'distributionType': 'Fixed',
'mean': 0 }
if time['distributionType'] == 'Normal' and\
time.get('max', None) is None:
time['max'] = float(time['mean']) + 5 * float(time['stdev'])
time = {'Fixed':{'mean': 0 }}
if 'Normal' in time.keys() and\
time['Normal'].get('max', None) is None:
time['Normal']['max'] = float(time['Normal']['mean']) + 5 * float(time['Normal']['stdev'])
return time
#===========================================================================
......
......@@ -29,22 +29,24 @@ holds methods for generations of numbers from different distributions
import math
class RandomNumberGenerator(object):
def __init__(self, obj, distributionType, mean=0, stdev=0, min=0, max=0, alpha=0, beta=0,
def __init__(self, obj, distribution, mean=0, stdev=0, min=0, max=0, alpha=0, beta=0,
logmean=0,logsd=0, probability=0, shape=0, scale=0, location=0, rate=0,**kw):
self.distributionType = distributionType
self.mean = float(mean or 0)
self.stdev = float(stdev or 0)
self.min = float(min or 0)
self.max = float(max or 0)
self.alpha = float(alpha or 0)
self.beta = float(beta or 0)
self.logmean=float(logmean or 0)
self.logsd=float(logsd or 0)
self.probability=float(probability or 0)
self.shape=float(shape or 0)
self.scale=float(scale or 0)
self.location=float(location or 0)
self.rate=float(rate or 0)
self.distribution=distribution
self.distributionType = distribution.keys()[0]
parameters=distribution[self.distributionType]
self.mean = float(parameters.get('mean', 0))
self.stdev = float(parameters.get('stdev', 0))
self.min = float(parameters.get('min',0))
self.max = float(parameters.get('max',0))
self.alpha = float(parameters.get('alpha',0))
self.beta = float(parameters.get('beta',0))
self.logmean=float(parameters.get('logmean',0))
self.logsd=float(parameters.get('logsd',0))
self.probability=float(parameters.get('probability',0))
self.shape=float(parameters.get('shape',0))
self.scale=float(parameters.get('scale',0))
self.location=float(parameters.get('location',0))
self.rate=float(parameters.get('rate',0))
self.obj = obj
def generateNumber(self):
......
......@@ -72,7 +72,7 @@ class EntityGenerator(object):
entityCounter=G.numberOfEntities+len(self.victim.scheduledEntities) # this is used just ot output the trace correctly
self.victim.scheduledEntities.append(self.env.now)
self.victim.outputTrace(self.victim.item.type+str(entityCounter), "generated") # output the trace
yield self.env.timeout(self.victim.calculateInterarrivalTime()) # wait until the next arrival
yield self.env.timeout(self.victim.calculateInterArrivalTime()) # wait until the next arrival
#============================================================================
# The Source object is a Process
......@@ -81,22 +81,21 @@ class Source(CoreObject):
#===========================================================================
# the __init__method of the Source class
#===========================================================================
def __init__(self, id, name, interarrivalTime=None, entity='Dream.Part',**kw):
def __init__(self, id, name, interArrivalTime=None, entity='Dream.Part',**kw):
# Default values
if not interarrivalTime:
interarrivalTime = {'distributionType': 'Fixed', 'mean': 1}
if interarrivalTime['distributionType'] == 'Normal' and\
interarrivalTime.get('max', None) is None:
interarrivalTime['max'] = interarrivalTime['mean'] + 5 * interarrivalTime['stdev']
if not interArrivalTime:
interArrivalTime = {'distributionType': 'Fixed', 'mean': 1}
if 'Normal' in interArrivalTime.keys() and\
interArrivalTime['Normal'].get('max', None) is None:
interArrivalTime['Normal']['max'] = interArrivalTime['Normal']['mean'] + 5 * interArrivalTime['Normal']['stdev']
CoreObject.__init__(self, id, name)
# properties used for statistics
self.totalInterArrivalTime = 0 # the total interarrival time
self.totalinterArrivalTime = 0 # the total interarrival time
self.numberOfArrivals = 0 # the number of entities that were created
self.type="Source" #String that shows the type of object
self.rng = RandomNumberGenerator(self, **interarrivalTime)
self.rng = RandomNumberGenerator(self, interArrivalTime)
self.item=Globals.getClassFromName(entity) #the type of object that the Source will generate
......@@ -186,7 +185,7 @@ class Source(CoreObject):
#============================================================================
# calculates the processing time
#============================================================================
def calculateInterarrivalTime(self):
def calculateInterArrivalTime(self):
return self.rng.generateNumber() #this is if we have a default interarrival time for all the entities
# =======================================================================
......
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