Skip to content

Commit 771901a

Browse files
committed
cleaned
1 parent 95ce190 commit 771901a

File tree

5 files changed

+81
-290
lines changed

5 files changed

+81
-290
lines changed

Src/FlowScheduler.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,16 @@ def UpdateFlow2(self, curFlow, flag):
126126
for flow in current_flows:
127127
flow.remainSize -= flow.bw * (curTime - flow.updateTime)
128128
flow.bw = 0.0
129-
while current_flows != []:
130-
bottleneck_rate = 10.0e100
129+
while current_flows:
130+
bottleneck_rate = link.linkCap
131131
for link_id in current_links:
132132
if len(residual_flowIds[link_id]) != 0:
133133
if bottleneck_rate >= residual_cap[link_id] / len(residual_flowIds[link_id]):
134134
bottleneck_rate = residual_cap[link_id] / len(residual_flowIds[link_id])
135-
if bottleneck_rate == 10.0e100:
136-
print "Error......"
135+
bottleneck_rate = max([min([bottleneck_rate, link.linkCap]), 0.001])
137136
links_to_remove = []
138137
for link_id in current_links:
139-
residual_cap[link_id] = residual_cap[link_id] - (bottleneck_rate * len(residual_flowIds[link_id]))
138+
residual_cap[link_id] -= bottleneck_rate * len(residual_flowIds[link_id])
140139
if residual_cap[link_id] <= 1.0e-20:
141140
links_to_remove.append(link_id)
142141
for link_id in links_to_remove:
@@ -168,7 +167,7 @@ def UpdateFlow2(self, curFlow, flag):
168167
elif flag == "insert":
169168
node.flowIds.append(curFlow.flowId)
170169

171-
def PrintFlows(self):
170+
def PrintFlows(self, outname=None):
172171
"""
173172
print finishedFlows
174173
"""

Src/Simulator.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from TestHuawei.Input.make_trace import *
33
import time
44

5+
56
# from Src.Flow import *
67
# import sys
78
# sys.path.append("..")
@@ -133,7 +134,7 @@ def Run(self):
133134
Fire up the simulator. The function calculates the transferring time for each flow.
134135
"""
135136
# start all the flows along with updating related flow transfer time
136-
self.AssignScheduler(FlowScheduler=self.schedType, args=self.TraceFName)
137+
# self.AssignScheduler(FlowScheduler=self.schedType, args=self.TraceFName)
137138
if self.Qlearning_enable == 1:
138139
self.logfname = "Reward_QLearning" + self.setting + ".csv"
139140
self.logfname2 = "FCT_QLearning" + self.setting + ".csv"
@@ -156,7 +157,7 @@ def Run(self):
156157
for episode in range(self.max_episodes):
157158
# print "episode number ", episode+1
158159
# generate_trace()
159-
# self.AssignScheduler(FlowScheduler=self.schedType, args=self.TraceFName)
160+
self.AssignScheduler(FlowScheduler=self.schedType, args=self.TraceFName)
160161
self.sched.toStartFlows = self.sched.flows[:]
161162
self.sched.toStartFlows.sort(key=lambda x: x.startTime)
162163
self.sched.runningFlows = []
@@ -191,6 +192,7 @@ def Run(self):
191192
self.sched.finishedFlows.append(toFinishFlow)
192193
# Update related flow's transfer time in removing a flow
193194
self.sched.UpdateFlow2(toFinishFlow, "remove")
195+
print "flow finishes at {}".format(toFinishFlow.finishTime)
194196
# Resort runningFlows by endTime
195197
self.sched.runningFlows.sort(key=lambda x: x.finishTime)
196198

@@ -203,7 +205,6 @@ def Run(self):
203205
self.pre_ActiveFlowRemainSize = self.ActiveFlowRemainSize[:]
204206
self.Update(toFinishFlow)
205207
# self.printQlearningLog()
206-
207208
else:
208209
break
209210

@@ -305,7 +306,7 @@ def Run(self):
305306
# remove this flow from start list
306307
self.sched.toStartFlows.remove(curStartFlow)
307308

308-
# print "Now, all the flows are started"
309+
print "Now, all the flows are started"
309310
# Iteratively update flow's transfer time in running list until all the flows are finished
310311
while self.sched.runningFlows:
311312
# the first flow is always with earliest finish Time
@@ -317,6 +318,7 @@ def Run(self):
317318
# Update related flow's transfer time in removing a flow
318319
self.sched.UpdateFlow2(curFinishFlow, "remove")
319320
# Resort runningFlows by endTime
321+
print "flow finishes at {}".format(curFinishFlow.finishTime)
320322
self.sched.runningFlows.sort(key=lambda x: x.finishTime)
321323

322324
# update state and reward for Qlearning algorithm
@@ -331,7 +333,8 @@ def Run(self):
331333
# self.printQlearningLog()
332334

333335
# print "Finally, all the flows are finished"
334-
self.sched.PrintFlows()
336+
namesp = self.logfname.split('_')
337+
self.sched.PrintFlows(outname=namesp[1])
335338
# self.printQlearningLog()
336339
# if self.Qlearning_enable == 1:
337340
# self.logf.close()
@@ -364,7 +367,7 @@ def printQlearningLog(self):
364367
logf = open("{0}{1}".format(self.logDir, self.logfname), "a")
365368
# TODO: Everything it needs is not available. Variable Scope is not set properly.
366369
print >> logf, "%d,%d,%d,%f,%f" % (
367-
self.stateId, self.stateId + 1, self.action[2], self.reward[0], self.reward[1])
370+
self.stateId, self.stateId + 1, self.action[2], self.reward[0], self.reward[1])
368371
logf.close()
369372
# flag = 0
370373
statename_list = ["LinkUtilization", "ActiveFlowNum", "ActiveElephantFlowNum", "ActiveFlowRemainSize"]

TestHuawei/Input/coflow_in.csv

+4-244
Original file line numberDiff line numberDiff line change
@@ -1,245 +1,5 @@
11
id,volume,count
2-
0,28290.11948832999,463
3-
515,44777.17791,56
4-
517,120307.49906,55
5-
8,34604.7416,56
6-
524,57364.75536000001,56
7-
525,21100.719079999995,54
8-
532,23542.885889999998,56
9-
536,42785.0682,56
10-
541,44777.17791,56
11-
548,98418.55839999995,55
12-
551,21100.719079999995,54
13-
41,44950.071200000006,56
14-
562,42785.0682,56
15-
52,81392.630574,55
16-
55,38048.06151400001,52
17-
59,72286.02268399997,53
18-
62,34604.7416,56
19-
63,2.80372,7
20-
64,159710.46364399994,56
21-
69,4.81934,7
22-
70,49548.84117000001,56
23-
72,124540.241324,56
24-
75,105710.60866400001,56
25-
76,8.42578,7
26-
77,33203.687048000014,52
27-
79,48432.59969000002,55
28-
84,124426.94239999999,55
29-
85,45548.589479999995,55
30-
90,120307.49906,55
31-
93,14.2129,7
32-
94,119232.76036999999,55
33-
97,57364.75536000001,56
34-
100,81392.630574,55
35-
102,44950.071200000006,56
36-
103,38065.31061400001,59
37-
104,54631.927370000005,53
38-
105,23542.885889999998,56
39-
107,72286.02268399997,53
40-
111,2.80372,7
41-
112,159710.46364399994,56
42-
114,44777.17791,56
43-
115,132202.48033999998,55
44-
117,4.81934,7
45-
118,49548.84117000001,56
46-
124,21109.144859999993,61
47-
125,33203.687048000014,52
48-
127,83017.31318,54
49-
128,81392.630574,55
50-
131,38048.06151400001,52
51-
132,81392.630574,55
52-
133,45548.589479999995,55
53-
134,81392.630574,55
54-
135,153119.15239799992,161
55-
137,38048.06151400001,52
56-
139,72316.29890399997,67
57-
140,159710.46364399994,56
58-
141,72300.23558399997,60
59-
142,119232.76036999999,55
60-
143,2.80372,7
61-
144,159710.46364399994,56
62-
24,44950.071200000006,56
63-
146,209259.30481400006,112
64-
147,98418.55839999995,55
65-
149,4.81934,7
66-
150,49548.84117000001,56
67-
151,22.068440000000002,14
68-
152,104189.19432000004,116
69-
153,33203.687048000014,52
70-
154,124540.241324,56
71-
156,8.42578,7
72-
157,138914.29571199993,108
73-
158,8.42578,7
74-
159,33203.687048000014,52
75-
161,93981.18917000003,110
76-
163,132202.48033999998,55
77-
164,81392.630574,55
78-
165,45548.589479999995,55
79-
166,124426.94239999999,55
80-
167,83596.65099400001,107
81-
169,14.2129,7
82-
170,119232.76036999999,55
83-
171,72286.02268399997,53
84-
172,120307.49906,55
85-
173,14.2129,7
86-
174,119232.76036999999,55
87-
175,83034.32979999999,68
88-
176,278943.2240140001,111
89-
179,57382.00446000001,63
90-
180,54631.927370000005,53
91-
181,4.81934,7
92-
182,49548.84117000001,56
93-
183,17.249100000000002,7
94-
184,54631.927370000005,53
95-
185,17.249100000000002,7
96-
186,54631.927370000005,53
97-
187,23570.358389999994,63
98-
188,44958.49698,63
99-
189,33203.687048000014,52
100-
190,124540.241324,56
101-
191,132202.48033999998,55
102-
193,105710.60866400001,56
103-
195,132202.48033999998,55
104-
196,44777.17791,56
105-
197,226183.66950999998,165
106-
202,124426.94239999999,55
107-
203,83017.31318,54
108-
205,14.2129,7
109-
206,140333.47945,109
110-
207,127967.38437999997,110
111-
208,120307.49906,55
112-
209,83017.31318,54
113-
215,57409.47696,70
114-
216,54631.927370000005,53
115-
217,42785.0682,56
116-
219,27.472500000000004,7
117-
221,27.472500000000004,7
118-
223,23542.885889999998,56
119-
224,44950.071200000006,56
120-
227,132202.48033999998,55
121-
229,98418.55839999995,55
122-
232,44777.17791,56
123-
239,83017.31318,54
124-
242,21100.719079999995,54
125-
251,27.472500000000004,7
126-
253,87735.13940000001,112
127-
256,124540.241324,56
128-
259,105710.60866400001,56
129-
263,48432.59969000002,55
130-
265,98418.55839999995,55
131-
268,124426.94239999999,55
132-
274,120307.49906,55
133-
281,57364.75536000001,56
134-
282,81392.630574,55
135-
283,81392.630574,55
136-
285,38048.06151400001,52
137-
286,38048.06151400001,52
138-
289,95828.90857399996,109
139-
290,72286.02268399997,53
140-
293,2.80372,7
141-
294,159713.26736399997,63
142-
295,159710.46364399994,56
143-
298,44777.17791,56
144-
299,4.81934,7
145-
300,49553.66051,63
146-
301,49548.84117000001,56
147-
306,34613.16738,63
148-
307,33212.11282800001,59
149-
308,54304.40612799998,106
150-
312,34604.7416,56
151-
315,45548.589479999995,55
152-
316,45548.589479999995,55
153-
319,42785.0682,56
154-
320,81392.630574,55
155-
323,38062.27441400001,59
156-
324,119246.97326999999,62
157-
325,119232.76036999999,55
158-
327,72286.02268399997,53
159-
331,98421.36211999995,62
160-
332,159710.46364399994,56
161-
333,17.249100000000002,7
162-
334,54649.17647,60
163-
335,54631.927370000005,53
164-
337,4.81934,7
165-
338,49548.84117000001,56
166-
344,8.42578,7
167-
345,165406.167388,107
168-
346,132202.48033999998,55
169-
574,98418.55839999995,55
170-
353,45548.589479999995,55
171-
357,83017.31318,54
172-
358,164409.943754,109
173-
145,7.6230600000000015,14
174-
361,38062.27441400001,59
175-
362,119232.76036999999,55
176-
365,72286.02268399997,53
177-
367,44950.071200000006,56
178-
369,30.276220000000006,14
179-
370,159737.93614399998,63
180-
371,17.249100000000002,7
181-
372,54631.927370000005,53
182-
373,124540.241324,56
183-
375,4.81934,7
184-
376,279799.6911580002,168
185-
379,105710.60866400001,56
186-
380,93382.67088999996,111
187-
382,8.42578,7
188-
383,213838.76707800006,162
189-
385,124426.94239999999,55
190-
386,44950.071200000006,56
191-
388,124426.94239999999,55
192-
391,165856.08853999988,110
193-
393,124540.241324,56
194-
394,120307.49906,55
195-
395,83017.31318,54
196-
396,105710.60866400001,56
197-
398,57364.75536000001,56
198-
399,14.2129,7
199-
400,167665.36006000006,110
200-
401,57364.75536000001,56
201-
405,124426.94239999999,55
202-
406,23542.885889999998,56
203-
407,44977.5437,63
204-
409,23560.13499,63
205-
410,54631.927370000005,53
206-
411,120307.49906,55
207-
415,44777.17791,56
208-
417,124540.241324,56
209-
418,102141.93327000005,112
210-
420,105710.60866400001,56
211-
421,132202.48033999998,55
212-
424,48432.59969000002,55
213-
425,21100.719079999995,54
214-
426,148083.127214,112
215-
428,21100.719079999995,54
216-
429,230137.55106399997,111
217-
433,131449.91287000003,109
218-
435,165084.67696999994,111
219-
436,42785.0682,56
220-
438,124426.94239999999,55
221-
439,42785.0682,56
222-
442,57364.75536000001,56
223-
444,120307.49906,55
224-
445,21128.19157999999,61
225-
448,98418.55839999995,55
226-
450,23542.885889999998,56
227-
451,155783.31376,111
228-
456,42785.0682,56
229-
459,68320.06379999999,112
230-
468,143195.73630999998,111
231-
469,21100.719079999995,54
232-
473,124540.241324,56
233-
476,150660.67986399998,112
234-
478,21100.719079999995,54
235-
480,91217.66789,111
236-
485,124426.94239999999,55
237-
489,42785.0682,56
238-
491,120307.49906,55
239-
492,98418.55839999995,55
240-
498,57364.75536000001,56
241-
499,124540.241324,56
242-
501,98418.55839999995,55
243-
502,105710.60866400001,56
244-
506,71975.48558,111
245-
511,124426.94239999999,55
2+
1,0.0820512820513,1
3+
2,3.93846153846,2
4+
3,0.328205128206,2
5+
4,8.861538461544999,4

0 commit comments

Comments
 (0)