Skip to content

Commit cd0c7af

Browse files
committed
refine
1 parent f1a1835 commit cd0c7af

File tree

3 files changed

+47
-39
lines changed

3 files changed

+47
-39
lines changed

README.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
>* 混部集群时刻处于复杂的干扰环境中,所以我们需要满足一些规避干扰约束,一条规避干扰约束被描述为<APP_A, APP_B, k>,代表若一台宿主机上存在APP_A类型的实例,则最多能部署k个APP_B类型的实例。注意,k可能为0。APP_A和APP_B也可能代表同一个APP(e.g. <APP_A, APP_A, k>),代表同一台机器上最多可以部署的该APP的实例的数目.
1111
1212
> 目标函数: (用整数规划的时候对该目标函数进行了线性转换,近似拟合)
13-
>* ![](https://github.com/brucefeng10/CloudResourceScheduling/blob/master/resources/score-criteria.jpg)
13+
![](https://github.com/brucefeng10/CloudResourceScheduling/blob/master/resources/score-criteria.jpg)
1414

1515

16-
数据观察(a版):
17-
instance: 总共68219个,分为9338类,相同类的instance属性一样;
18-
app: 总共9338个(类),每种类型app有若干个instance,总共68219个instance;
19-
machine: 总共6000台,可分为大小两种型号,每种型号各一半;
16+
## 数据观察(a版):
17+
>* instance: 总共68219个,分为9338类,相同类的instance属性一样;
18+
>* app: 总共9338个(类),每种类型app有若干个instance,总共68219个instance;
19+
>* machine: 总共6000台,可分为大小两种型号,每种型号各一半;
20+
21+
## 测试结果:
22+
>* 100个app,初始解用一个单位矩阵,使用一种类型的machine(大),迭代439次后子问题找不到reduced cost为负(<-1e-3)的列,原问题有整数解,总耗时1074s;实际上迭代次数达到100后,松弛主问题目标函数下降幅度就非常小了,下降曲线如下:
23+
![](https://github.com/brucefeng10/CloudResourceScheduling/blob/master/resources/cost_descend_100.png)
24+
2025

resources/cost_descend_100.png

15.1 KB
Loading

tianchiOR_CG_20180722.py

+37-34
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from gurobipy import *
55
import time
66
import csv
7+
import matplotlib.pyplot as plt
78

89
input_file = 'C:\Bee\ProjectFile\Tianchi_scheduling_20180614\Inputdata\\'
910

@@ -92,7 +93,8 @@ def sche_rlmp_int(patt):
9293
"""Using column generation to solve cutting stock problem -- restricted linear master problem"""
9394
print('*******Start real master problem!********')
9495
patt_num = int(patt.shape[1])
95-
print(('Found pattern number: ', patt_num))
96+
print('Found pattern number: ', patt_num)
97+
9698
try:
9799
rlmp = Model('master-problem')
98100
# y[j] denotes the number of pattern0[j] to be used
@@ -106,7 +108,7 @@ def sche_rlmp_int(patt):
106108

107109
rlmp.optimize()
108110

109-
print(('Objective: ', rlmp.objVal))
111+
print('Objective: ', rlmp.objVal)
110112
rlmp.printAttr('X')
111113

112114
if rlmp.status == GRB.OPTIMAL:
@@ -121,7 +123,8 @@ def sche_rlmp(patt):
121123
"""Using column generation to solve cutting stock problem -- restricted linear master problem"""
122124
print('*******Start rlmp problem!********')
123125
patt_num = int(patt.shape[1])
124-
print(('Found pattern number: ', patt_num))
126+
print('Found pattern number: ', patt_num)
127+
objval, shadow_price = None, None
125128
try:
126129
rlmp = Model('master-problem')
127130
# y[j] denotes the number of pattern0[j] to be used
@@ -132,24 +135,24 @@ def sche_rlmp(patt):
132135
for i in range(app_num):
133136
rlmp.addConstr(quicksum(patt[i, j] * y[j] for j in range(patt_num)) >= len(app_inst['app_' + str(i + 1)]))
134137

138+
rlmp.Params.OutputFlag = 0
135139
rlmp.optimize()
136140

137-
print(('Objective: ', rlmp.objVal))
141+
objval = rlmp.objVal
142+
print('Objective: ', objval)
138143
rlmp.printAttr('X')
139144

140145
if rlmp.status == GRB.OPTIMAL:
141146
# shadow_price = rlmp.getAttr('Pi', rlmp.getConstrs())
142147
shadow_price = rlmp.getAttr(GRB.Attr.Pi)
143-
print(('Shadow price of constraints: ', shadow_price, '\n'))
148+
# print('Shadow price of constraints: ', shadow_price, '\n')
144149

145150
except GurobiError as e:
146151
print('Error of master-problem reported: ')
147152
print(e)
148153

149-
return shadow_price
150-
154+
return objval, shadow_price
151155

152-
# cutstock_rlmp()
153156

154157
def sche_subp(pi):
155158
'''Using column generation to solve cutting stock problem -- sub-problem'''
@@ -172,14 +175,15 @@ def sche_subp(pi):
172175
subp.addConstr(quicksum(app_att[k, 2] * x[k] for k in range(app_num)) <= machine_att[5000, 4])
173176
subp.addConstr(quicksum(app_att[k, 3] * x[k] for k in range(app_num)) <= machine_att[5000, 5])
174177

178+
subp.Params.OutputFlag = 0
175179
subp.optimize()
176180

177-
print(('Objective: ', subp.objVal))
181+
print('Objective: ', subp.objVal)
178182
subp.printAttr('X')
179183

180184
for i in range(app_num):
181185
new_pat[i][0] = x[i].x
182-
print(('new pattern: ', new_pat.T))
186+
# print('new pattern: ', new_pat.T)
183187
if subp.status == GRB.OPTIMAL:
184188
# shadow_price = subp.getAttr('Pi', subp.getConstrs())
185189
# print 'Shadow price of constraints: ', shadow_price
@@ -203,53 +207,46 @@ def sche_subp(pi):
203207
time_num = 98
204208

205209
machine_att = read_data_mach()
206-
machine_att[:50, 0] = 32 # app_30 has 4 instances with cpu 92
207-
machine_att[:50, 1] = 64 # app_30 has 4 instances with memory 288
208-
machine_att[:50, 2] = 1024 # app_30 has 4 instances with disk 1024
209-
print('machine')
210+
# machine_att[:50, 0] = 32 # app_30 has 4 instances with cpu 92
211+
# machine_att[:50, 1] = 64 # app_30 has 4 instances with memory 288
212+
# machine_att[:50, 2] = 1024 # app_30 has 4 instances with disk 1024
213+
# print('machine')
210214

211215
app_att, cpu_t, mem_t, cpu_sort = read_data_app()
212216
cpu_max, mem_max = np.max(cpu_t, 1), np.max(mem_t, 1)
213-
print(('app number', len(cpu_max)))
214-
print(('t number', len(cpu_sort[0])))
215-
# print cpu_t[19,:]
216-
# print cpu_sort[19]
217+
print('app number', len(cpu_max))
218+
print('t number', len(cpu_sort[0]))
217219

218220
# inst_app=read_data_inst()
219221
app_inst = read_data_inst2()
220-
# app1_app2, app_app = read_data_app_inter()
221-
# print 'app-app'
222-
# print 'app1_app2 ', len(app1_app2)
223-
# print 'app_app ', len(app_app)
222+
224223
inst_num = 600
225224
machine_num = 150
226225
app_num = 100
227-
print((app_num, machine_num))
226+
print(app_num, machine_num)
228227

229228
pattern0 = np.eye(app_num, app_num)
230229
pattern = pattern0
231-
# pt = [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 2.0, 0.0, 2.0, 2.0, 0.0, 0.0, 2.0, 0.0, 2.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,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, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0, 0.0, 4.0, 0.0, 2.0, 0.0, 2.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 2.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]]
232-
# pattern = np.array(pt)
230+
233231
stop_ind = True
234-
max_itr = 100
232+
max_itr = 1000
233+
rlmp_objval = [] # objective value of rlmp in each iteration
235234
itr = 0
236235
while itr < max_itr and stop_ind:
237-
pi = sche_rlmp(pattern)
236+
objv, pi = sche_rlmp(pattern)
237+
rlmp_objval.append(objv)
238238
new_pat = sche_subp(pi)
239239
prof = 0
240240
for ii in range(app_num):
241241
prof += pi[ii] * new_pat[ii][0]
242-
print(('checking parameter: ', 1 - prof))
243-
if 1 - prof >= 0:
242+
print('checking parameter: ', 1 - prof)
243+
if 1 - prof >= -1e-3:
244244
stop_ind = False
245245
else:
246246
pattern = np.concatenate((pattern, new_pat), axis=1)
247247

248248
itr += 1
249-
print(('current iteration time: ', itr))
250-
251-
t1 = time.time()
252-
print(('Total elapsed time: ', t1 - t0))
249+
print('current iteration time: ', itr)
253250

254251
print('\n')
255252
print(' **************************************** ')
@@ -258,4 +255,10 @@ def sche_subp(pi):
258255

259256
sche_rlmp_int(pattern)
260257

261-
print(('Total iteration: ', itr))
258+
print('Total iteration: ', itr)
259+
t1 = time.time()
260+
print('Total elapsed time: ', t1 - t0)
261+
262+
plt.plot(rlmp_objval)
263+
plt.show()
264+

0 commit comments

Comments
 (0)