• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlanticwave-sdx / pce / 3680947894

pending completion
3680947894

Pull #81

github

GitHub
Merge a6cd61918 into b40be3bdd
Pull Request #81: Updates coveralls.io configuration

845 of 1796 relevant lines covered (47.05%)

0.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Utility/simulation.py
1
import argparse
×
2

3
import numpy as np
×
4

5
import Utility.global_name as global_name
×
6
from Heuristic.Heur import TE_Group_Solver
×
7
from LoadBalancing.TE_Solver import TE_Solver
×
8
from Utility.randomConnectionGenerator import RandomConnectionGenerator
×
9
from Utility.randomTopologyGenerator import RandomTopologyGenerator
×
10

11

12
def random_graph(n, p, m):
×
13

14
    graph_generator = RandomTopologyGenerator(n, p)
×
15
    graph = graph_generator.generate_graph()
×
16

17
    tm_generator = RandomConnectionGenerator(n)
×
18
    tm = tm_generator.randomConnectionGenerator(m, 500, 1000, 80, 100)
×
19

20
    return graph, tm
×
21

22

23
def dot_file(g_file, tm_file):
×
24
    pass
×
25

26

27
def bw_stat(g):
×
28
    total_weight = 0.0
×
29
    total_util = 0.0
×
30
    max_util = 0.0
×
31
    util_list = []
×
32
    for (u, v, w) in g.edges(data=True):
×
33
        avail_bw = w[global_name.bandwidth]
×
34
        bw = w[global_name.original_bandwidth]
×
35
        weight = global_name.alpha * (1.0 / (avail_bw + 0.1))
×
36
        total_weight = total_weight + weight
×
37
        util = 1.0 - avail_bw / bw
×
38
        total_util = total_util + util
×
39
        if util > max_util:
×
40
            max_util = util
×
41
        util_list.append(util)
×
42
    util_array = np.array(util_list)
×
43
    mean_util = np.mean(util_array)
×
44
    std_util = np.std(util_array)
×
45
    ninetypercetile_util = np.percentile(util_array, 90)
×
46
    # print(util_array)
47
    print(
×
48
        "mean_util="
49
        + str(mean_util)
50
        + ";std_util="
51
        + str(std_util)
52
        + ";ninetypercetile_util="
53
        + str(ninetypercetile_util)
54
    )
55
    print(
×
56
        "total_weight="
57
        + str(total_weight)
58
        + ";total_util="
59
        + str(total_util)
60
        + ";max_util="
61
        + str(max_util)
62
    )
63

64

65
if __name__ == "__main__":
×
66
    parse = argparse.ArgumentParser()
×
67

68
    parse.add_argument(
×
69
        "-n",
70
        dest="n",
71
        required=False,
72
        help="Number of nodes when creating random topology",
73
        type=int,
74
    )
75
    parse.add_argument(
×
76
        "-p",
77
        dest="p",
78
        required=False,
79
        help="Probability of links when random topology",
80
        type=float,
81
    )
82
    parse.add_argument(
×
83
        "-m",
84
        dest="m",
85
        required=False,
86
        help="Number of connections in the random TE",
87
        type=int,
88
    )
89
    parse.add_argument(
×
90
        "-c", dest="c", required=False, default=0, help="Link cost definition", type=int
91
    )
92
    parse.add_argument(
×
93
        "-b",
94
        dest="b",
95
        required=False,
96
        default=0,
97
        help="Objective: MinCost or Load balancing",
98
        type=int,
99
    )
100
    parse.add_argument(
×
101
        "-l", dest="l", required=False, help="Static link cost input", type=str
102
    )
103
    parse.add_argument(
×
104
        "-t",
105
        dest="te_file",
106
        required=False,
107
        help="Input file for the connections or traiffc matrix, e.g. c connection.json. Required.",
108
        type=str,
109
    )
110
    parse.add_argument(
×
111
        "-g",
112
        dest="topology_file",
113
        required=False,
114
        help="Input file for the network topology, e.g. t topology.json. Required.",
115
        type=str,
116
    )
117
    parse.add_argument(
×
118
        "-heur",
119
        dest="heur",
120
        default=0,
121
        help="Heuristic = 1, Default = 0 for the optimal. ",
122
        type=int,
123
    )
124
    parse.add_argument(
×
125
        "-k", dest="k", default=2, help="Group Heuristic  -- Number of groups", type=int
126
    )
127
    parse.add_argument(
×
128
        "-a",
129
        dest="alg",
130
        default=0,
131
        help="Flag for different grouping heuristic algorithms, default is the linear partition",
132
        type=int,
133
    )
134
    parse.add_argument(
×
135
        "-o",
136
        dest="result",
137
        default="OUTPUT.txt",
138
        help="Output file, e.g. o result.txt. If this option is not given, assume standard output.",
139
        type=str,
140
    )
141

142
    parse.print_help()
×
143
    args = parse.parse_args()
×
144

145
    if args.topology_file is not None:
×
146
        if args.te_file is not None:
×
147
            graph, tm = dot_file(args.topology_file, args.te_file)
×
148
        else:
149
            print("Missing the TE file!")
×
150
            exit()
×
151
    else:
152
        if args.n is None:
×
153
            args.n = 25
×
154
        if args.p is None:
×
155
            args.p = 0.2
×
156
        if args.m is None:
×
157
            args.m = 3
×
158
        print("n=" + str(args.n) + ";p=" + str(args.p) + ";m=" + str(args.m))
×
159
        graph, tm = random_graph(args.n, args.p, args.m)
×
160

161
    if args.c == global_name.COST_FLAG_STATIC:  # 4
×
162
        if args.l is None:
×
163
            print("Error: Static cost file is needed!")
×
164
            exit(1)
×
165

166
    if args.heur == 0:
×
167
        print("Optimal solver")
×
168
        solver = TE_Solver(graph, tm, args.c, args.b)
×
169
        path, result = solver.solve()
×
170
        ordered_paths = solver.solution_translator(path, result)
×
171
        graph = solver.update_graph(graph, ordered_paths)
×
172
    else:
173
        print("Heuristic solver")
×
174
        solver = TE_Group_Solver(graph, tm, args.c, args.b)
×
175
        partition_tm = solver.ConnectionSplit(args.alg, args.k)
×
176
        solver.solve(partition_tm)
×
177

178
    bw_stat(graph)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc