-
Notifications
You must be signed in to change notification settings - Fork 0
/
opt_1.py
64 lines (52 loc) · 1.7 KB
/
opt_1.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
import argparse
import networkx as nx
import algorithm
import graph_utils
parser = argparse.ArgumentParser(description='OPT 1 and OPT 2 library')
parser.add_argument('--input',
action='store',
type=str,
help='input dot file',
default='example.dot')
parser.add_argument('--verbose',
action='store',
type=bool,
help='if enable, it will be verbose',
default=True)
parser.add_argument('--output',
action='store',
type=str,
help='output dot file',
default='output.dot')
args = parser.parse_args()
input_file = args.input
verbose = args.verbose
output_file = args.output
if verbose:
print("Reading input graph...")
G = nx.nx_agraph.read_dot(input_file)
if verbose:
nodes, edges, clock = graph_utils.graph_stats(G)
print(f"The input graph has {nodes} nodes, {edges} edges.")
print(f"The clock of the input graph is {clock} cycles.")
if verbose:
print("Starting graph preprocessing...")
G = graph_utils.preprocess(G)
if verbose:
print("Computing matrix W and D...")
W, D = algorithm.WD(G)
if verbose:
print("D is:")
# print(f"{D}")
print("W is:")
# print(f"{W}")
if verbose:
print("Running OPT 1...")
Gr = algorithm.OPT_1(G, W, D)
nodes, edges, clock = graph_utils.graph_stats(G)
if verbose:
print(f"OPT 1 COMPLETED.")
print(f"The OPT 1 optimized graph has {nodes} nodes, {edges} edges.")
print(f"The clock of the OPT 1 optimized graph is {clock} cycles.")
graph_utils.save_graph(Gr, output_file)
print(f"The retimed graph has been saved.")