-
Notifications
You must be signed in to change notification settings - Fork 3
/
generator.py
153 lines (140 loc) · 4.78 KB
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from __future__ import division
from scipy import stats
import numpy as np
import random
from scipy.stats import exponweib
import math
import sys, getopt
import json
ofile = "taskset-p.txt"
USet=[]
class task (dict):
def __init__(self, sharedR, period, deadline, execlusiveR, resource, block):
dict.__setitem__(self, "shared-R", float (sharedR))
dict.__setitem__(self, "period", float (period))
dict.__setitem__(self, "deadline", float (deadline))
dict.__setitem__(self, "exclusive-R", float (execlusiveR))
dict.__setitem__(self, "resource", int (resource))
dict.__setitem__(self, "block", float (block))
def UUniFast(n,U_avg):
global USet
sumU=U_avg
for i in range(n-1):
nextSumU=sumU*math.pow(random.random(), 1/(n-i))
USet.append(sumU-nextSumU)
sumU=nextSumU
USet.append(sumU)
def UUniFast_Discard(n,U_avg, sstype):
while 1:
sumU=U_avg
for i in range(n-1):
nextSumU=sumU*math.pow(random.random(), 1/(n-i))
if sstype == 'S':
if sumU-nextSumU < 1:
USet.append(sumU-nextSumU)
else:
break
elif sstype == 'M':
if sumU-nextSumU < 0.9:
USet.append(sumU-nextSumU)
else:
break
elif sstype == 'L':
if sumU-nextSumU < 0.7:
USet.append(sumU-nextSumU)
else:
break
sumU=nextSumU
USet.append(sumU)
if len(USet) == n:
break
del USet[:]
def UniDist(n,U_min,U_max):
for i in range(n-1):
uBkt=random.uniform(U_min, U_max)
USet.append(uBkt)
def CSet_generate_sss_z(Pmin,numLog, sstype="S", btype="N"):
global USet,PSet
j=0
# the number of SSS
res = []
for i in USet:
thN=j%numLog
p=random.uniform(Pmin*math.pow(10, thN), Pmin*math.pow(10, thN+1))
#generate the blocking time for \sigma*B
block = 0.0
if btype == 'N':
block = 0
elif btype == "S":
nb = random.sample([1,2], 1)
block = 0.01 * nb[0]
elif btype == "M": #M
nb = random.sample([1,2,4], 1)
block = 0.01 * nb[0]
elif btype == "L": #L
nb = random.sample([1,2,4,6,8], 1)
block = 0.01 * nb[0]
#generate the suspention time e_i
if sstype == "S": #S
suspension = random.uniform(0.01*(p-i*p-block), 0.1*(p-i*p-block))
elif sstype == "M": #M
suspension = random.uniform(0.1*(p-i*p-block), 0.3*(p-i*p-block))
else: #L
suspension = random.uniform(0.3*(p-i*p-block), 0.45*(p-i*p-block))
#generate the number of required resources
requiredres = random.sample([1,2,4,6,8,10],1)
PSet.append(task(i*p, p, p, suspension, requiredres[0], block))
res.append((i*p+suspension)/p)
j=j+1;
return res
def CSet_generate_sss(Pmin,numLog, sstype="S", btype="N"):
global USet,PSet
j=0
# the number of SSS
res = []
for i in USet:
thN=j%numLog
p=random.uniform(Pmin*math.pow(10, thN), Pmin*math.pow(10, thN+1))
#generate the blocking time for \sigma*B
block = 0.0
if btype == 'N':
block = 0
elif btype == "S":
nb = random.sample([1,2], 1)
block = 0.01 * nb[0]
elif btype == "M": #M
nb = random.sample([1,2,4], 1)
block = 0.01 * nb[0]
elif btype == "L": #L
nb = random.sample([1,2,4,6,8], 1)
block = 0.01 * nb[0]
#generate the suspention time e_i
if sstype == "S": #S
suspension = random.uniform(0.01*(p-i*p-block), 0.1*(p-i*p-block))
elif sstype == "M": #M
suspension = random.uniform(0.1*(p-i*p-block), 0.3*(p-i*p-block))
else: #L
suspension = random.uniform(0.3*(p-i*p-block), 0.45*(p-i*p-block))
PSet.append(task(i*p, p, p, suspension, 0, block))
res.append((i*p+suspension)/p)
j=j+1;
return res
def init():
global USet,PSet
USet=[]
PSet=[]
def taskGeneration(numTasks, uTotal, sstype, resource, btype):
random.seed()
while 1:
init()
UUniFast_Discard(numTasks,uTotal/100, sstype)
if resource == 0:
res = CSet_generate_sss(1,2,sstype, btype)
else:
res = CSet_generate_sss_z(1,2,sstype, btype)
if max(res) <1:
#print numTasks, uTotal
break
fo = open(ofile, "wb")
print >>fo, json.dumps(PSet)
return PSet