-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_heuristic.py
More file actions
50 lines (41 loc) · 2.21 KB
/
Copy pathrun_heuristic.py
File metadata and controls
50 lines (41 loc) · 2.21 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
import logging, json, os
from model.problem import CFSProblem
from model.solution import CFSSolution
from solver.pulp import PuLPSolver
from solver.dispatching_rule import PriorityDispatchSolver
def print_intermediate_solution(solution:CFSSolution):
logging.info(f'Makespan: {solution.makespan}')
# benchmark path
script_path = os.path.abspath(__file__)
prj_path = os.path.dirname(script_path)
benchmark_path = os.path.join(prj_path, 'benchmark')
if __name__=='__main__':
topo_ids = ['dag301', 'dag302', 'dag303']
traffic_scale = [10, 20, 40, 60, 80, 100, 120, 140, 160, 320, 640, 1280]
# traffic_scale = [10 * 2 ** i for i in range(8)] # [10, 20, 40, 80, 160, 320, 640, 1280]
for topo_id in topo_ids:
for flow_nums in traffic_scale:
instance_file = f'{topo_id}_{str(flow_nums)}_h'
# ----------------------------------------
# solve cfs problem by PriorityDispatchSolver
# ----------------------------------------
rules = ['spt', 'lpt', 'sps', 'lps', 'stpt', 'ltpt',
'ect', 'lct', 'swt', 'lwt', 'ltwr', 'mtwr',
'est', 'lst', 'hh', 'ihh']
for rule in rules:
problem = CFSProblem(benchmark=f'{topo_id}_{str(flow_nums)}')
s = PriorityDispatchSolver(rule=rule)
s.solve(problem=problem, interval=2000, callback=print_intermediate_solution)
s.wait()
# ----------------------------------------
# save simulation result
# ----------------------------------------
result_path = os.path.join(benchmark_path, f'results_h/{instance_file}_{rule}')
with open(result_path, 'w') as f:
if s.status:
print(f'Problem: {len(problem.flows)} flows, {len(problem.edges)} edges', file=f)
print(f'Optimum: {problem.optimum}', file=f)
print(f'Solution: {problem.solution.makespan}', file=f)
print(f'Terminate successfully in {s.user_time} sec.', file=f)
else:
print(f'Solving process failed in {s.user_time} sec.', file=f)