-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple_test.py
More file actions
115 lines (103 loc) · 2.71 KB
/
Copy pathsimple_test.py
File metadata and controls
115 lines (103 loc) · 2.71 KB
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
'''
Author: Kuan-Hsun Chen
'''
#import timing
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import math
import random
import sys, getopt
import json
from scipy.optimize import *
from sympy import *
n = 3
PSet = []
Tpoints = []
overT = []
t=[]
maxS = 50
delta = 0.5
def selectedpoints(targetIdx):
# math.ceil()
tarT=PSet[targetIdx]
for i in range(targetIdx):
checkT = PSet[i]
t = math.floor(tarT['period']/checkT['period'])*checkT['period']
Tpoints.append(t)
Tpoints.append(tarT['period'])
def taskInit():
#task 1
pair = {}
pair['period'] = 10
# pair['NWCET'] = 6
# pair['AWCET'] = 8
pair['NWCET'] = 4
pair['AWCET'] = 6
pair['prob'] = 0.000001
PSet.append(pair)
#task 2
pair = {}
pair['period'] = 45
pair['NWCET'] = 10
pair['AWCET'] = 15
# pair['NWCET'] = 2
# pair['AWCET'] = 3
pair['prob'] = 0.000001
PSet.append(pair)
#task 3
pair = {}
pair['period'] = 75
pair['NWCET'] = 10
pair['AWCET'] = 30
pair['prob'] = 0.000001
PSet.append(pair)
def Chernoff_bounds(a, t):
#timing.log("Chernoff bound starts")
'''
return the probability, input the targeted time point a and t
1. first calculate the total number of jobs among all tasks
2. calculate mgf function for each task with their corresponding number jobs in nlist
3. using input t \in {0, b} to find the minimal result
'''
#input a is the selected point
prob = np.float128(1.0)
prob = prob/exp(t*a)
count = 0
#now sumN is the total number of jobs among all the tasks.
c1, c2, x, p = symbols("c1, c2, x, p")
expr = exp(c1*x)*(1-p)+exp(c2*x)*p
mgf = lambdify((c1, c2, x, p), expr)
nlist=[]
for i in range(n):
nlist.append(np.ceil(a/PSet[i]['period']))
for i in nlist:
prob = prob * np.float128(mgf(PSet[count]['NWCET'], PSet[count]['AWCET'], t, PSet[count]['prob']))**int(i)
count += 1
#timing.log("Chernoff bound ends")
return prob
taskInit()
#timing.log("Task init")
selectedpoints(n-1)#3 tasks use 2, 2 tasks use 1
#timing.log("Select k points")
pResult = .0
minP=1.
plt.title('Probability of P(S>=a)')
plt.xlabel('t')
plt.ylabel('Probability')
for y in Tpoints:
fy=float(y)
tmplist = []
for x in np.arange(0, maxS, delta):
tmplist.append(Chernoff_bounds(fy, x))
probRes=min(tmplist)
print "On time point "+str(fy)+" the minimal probability is "+str(probRes)
if minP > probRes:
minP = probRes
print "Among all the selected points, the minimal upper bound is:"+str(minP)
#plt.axis([0.1, 0.3, 0, 1])
#plt.axis([0.5, 2, 0, 0.05])
#plt.plot(t, overT,'ro')
#plt.plot(t, overT)
#plt.show()