/
Main.py
130 lines (111 loc) · 3.31 KB
/
Main.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
import numpy as np
from scipy import optimize
from scipy.optimize import fsolve
import matplotlib.pyplot as plt
#import unNormalizedMUB as umub
import unNormalizedMUB as nmub
reload(nmub)
#omega(hvac,dc,bk)
omega=np.array([15.0,1.0, 0.3*1e-3]) #0.3$/KWh
#omega=np.array([0,1.0, 0.3*1e-3]) #set baseline1
#wear and tear cost
omega_wat=np.array([0.1,0.3,0.5])
#sla weight
omega_sla=np.array([0.7,0.5,0.6])
hvac= nmub.HVAC(25,omega[0])
Tnhat=[2.0,4.0,5.0,2.0,5.0]
hvac.setTn(Tnhat)
bk=nmub.bkGen(omega[2])
rho=1
Q=1e6 #Wh ( 1MWh)
n=3 #number of offices
I=3 # number of DCs
nmub.omega_wat=omega_wat
nmub.Q=Q
nmub.n=n
nmub.I=I
nmub.rho=rho
#hvac.userComfCost()
#hvac.enReduc()
#hvac.optimizeOfficei(1,5)
#initialize the datacenter with services rate of each tenant per s and max server
#nmub.DC(mu,S,omega)
dc =nmub.DC([3.0, 3.0, 3.0,3.5, 4.5],[2000,2000,2000,2000,2000],omega[1],omega_sla)
#arrival rate
dc.setlamb([1100.0,1200.0,1300.0,1500.0,1600.0])
#dc.setSwitchSever([200,100,100,200,100])
#dc.minServer()
#dc.solx()
#def __init__(self,sigmai,sigman,e_i,e_n,e_z):
mub=nmub.operator([1,2,3,4,5],[1,2,3,4,5],100,[1,2,3,4,5],[1,2,3,4,5],200)
#mub.calv()
# def updateEn(self,sigman,en_):
runTime = 200
#
#
#
#
bk_totalcost= np.zeros(runTime)
T=np.ones((3,runTime))
s=np.ones((3,runTime))
energy = np.ones((7,runTime))
sigma = np.ones((7,runTime))
cost = np.ones((7,runTime))
Tnhat1=np.zeros(runTime)
Totalcost=np.zeros(runTime)
for i in range(runTime):
pre=sum(mub.sigmai)+sum(mub.sigman)+mub.sigmaz
#print('pre',pre)
hvac.updateEn(mub.sigman,mub.e_n)
# def updateEi(self,sigmai,ei_):
#print ("Ti",hvac.Tn)
energy[0][i] = hvac.e[0]
energy[1][i] = hvac.e[1]
energy[2][i] = hvac.e[2]
T[0][i]=hvac.Tn[0]
T[1][i]=hvac.Tn[1]
T[2][i]=hvac.Tn[2]
dc.updateEi(mub.sigmai,mub.e_i)
s[0][i]=dc.s[0]
s[1][i]=dc.s[1]
s[2][i]=dc.s[2]
energy[3][i] = dc.e[0]
energy[4][i] = dc.e[1]
energy[5][i] = dc.e[2]
#print(sum(hvac.e)+sum(dc.e)+bk.ez)
# def updateEz(self,sigmaz,ez_):
bk.updateEz(mub.sigmaz,mub.e_z)
energy[6][i] = bk.ez
mub.updateehat(hvac.e,dc.e,bk.ez)
mub.updateSigma(hvac.e,dc.e,bk.ez)
sigma[0][i] = mub.sigman[0]
sigma[1][i] = mub.sigman[1]
sigma[2][i] = mub.sigman[2]
sigma[3][i] = mub.sigmai[0]
sigma[4][i] = mub.sigmai[1]
sigma[5][i] = mub.sigmai[2]
sigma[6][i] = mub.sigmaz
cost[0][i]=hvac.userComfCosti(0)
cost[1][i]=hvac.userComfCosti(1)
cost[2][i]=hvac.userComfCosti(2)
cost[3][i]=dc.dcCosti(0)
cost[4][i]=dc.dcCosti(1)
cost[5][i]=dc.dcCosti(2)
cost[6][i]=bk.bgCost()
curr=sum(mub.sigmai)+sum(mub.sigman)+mub.sigmaz
x=np.arange(runTime)
def plot_lines(datas, numb_of_line, markerstyle, labels, title ):
for line in range(numb_of_line):
plt.plot(datas[line], marker = markerstyle, markersize=4, label=labels[line])
plt.legend(loc=1)
plt.title(title)
plt.show()
labels = ['Office 1','Office 2','Office 3','DC 1','DC 2','DC 3','BK']
plot_lines(energy,7,".",labels,"Energy")
plot_lines(sigma,7,"+",labels,"Sigma")
labels = ['Office 1','Office 2','Office 3','DC 1','DC 2','DC 3','BK']
plot_lines(cost,7,"+",labels,"Cost")
labels = ['Office 1','Office 2','Office 3']
plot_lines(T,3,"+",labels,"Temperature")
labels = ['DC 1','DC 2','DC 3']
plot_lines(s,3,"+",labels,"s")