Commit 17605d1d authored by Georgios Dagkakis's avatar Georgios Dagkakis

RandomNumberGenerator changed to work with mean and no avg

parent 85b7051e
......@@ -36,7 +36,7 @@
"name": "M1",
"processingTime": {
"distributionType": "Exp",
"avg": 1.5
"mean": 1.5
}
},
"S1": {
......@@ -44,7 +44,8 @@
"element_id": "DreamNode_1",
"entity": "Dream.Part",
"interarrivalTime": {
"distributionType": "Normal",
"distributionType": "Normal",
"mean": 1,
"max": 2,
"min": 1,
"stdev": 0.5
......
......@@ -26,9 +26,8 @@ Created on 14 Feb 2013
holds methods for generations of numbers from different distributions
'''
class RandomNumberGenerator(object):
def __init__(self, obj, distributionType, mean=0, avg=0, stdev=0, min=0, max=0, alpha=0, beta=0):
def __init__(self, obj, distributionType, mean=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
......@@ -42,14 +41,14 @@ class RandomNumberGenerator(object):
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))
return G.Rnd.expovariate(1.0/(self.mean))
elif(self.distributionType=="Normal"): #if the distribution is Normal
if self.max < self.min:
raise ValueError("Normal distribution for %s uses wrong "
"parameters. max (%s) > min (%s)" % (
self.obj.id, self.max, self.min))
while 1:
number=G.Rnd.normalvariate(self.avg, self.stdev)
number=G.Rnd.normalvariate(self.mean, 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
......
......@@ -30,7 +30,7 @@ class RandomNumberGeneratorTestCase(TestCase):
self.assertEquals(rng.generateNumber(), 32)
def testExp(self):
rng = RandomNumberGenerator(obj, distributionType='Exp', avg=10)
rng = RandomNumberGenerator(obj, distributionType='Exp', mean=10)
number = rng.generateNumber()
# at least we make sure we generate a number
self.assertTrue(number >= 0)
......@@ -48,7 +48,7 @@ class RandomNumberGeneratorTestCase(TestCase):
min=0,
max=3,
stdev=.5,
avg=2)
mean=2)
for i in range(10):
number = rng.generateNumber()
self.assertTrue(number >= 0)
......@@ -60,7 +60,7 @@ class RandomNumberGeneratorTestCase(TestCase):
min=3,
max=0, # here min > max
stdev=.5,
avg=2)
mean=2)
self.assertRaises(ValueError, rng.generateNumber)
def testUnkonwnDistribution(self):
......
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