• 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

60.42
/src/Utility/randomConnectionGenerator.py
1
import json
1✔
2

3
import numpy as np
1✔
4

5

6
class RandomConnectionGenerator:
1✔
7
    def __init__(self, N):
1✔
8
        """
9
        init
10
        @param N number of nodes of the topology
11
        """
12
        self.num_nodes = N
1✔
13

14
    # Output: list of tuples of request
15
    def randomConnectionGenerator(self, querynum, l_bw, u_bw, l_lat, u_lat, seed=2022):
1✔
16
        """
17
        Create a random TM
18
        @param querynum number of connections
19
        @return a list of connections, each of which is a list [src, des, bw, lat]
20
        """
21
        np.random.seed(seed)
1✔
22
        connection = []
1✔
23
        bw = self.lognormal((l_bw + u_bw) / 2.0, 1, querynum)
1✔
24
        if querynum <= self.num_nodes:
1✔
25
            for i in range(querynum):
1✔
26
                query = []
1✔
27
                query.append(np.random.randint(1, (self.num_nodes + 1) / 2.0))
1✔
28
                query.append(
1✔
29
                    np.random.randint((self.num_nodes + 1) / 2.0, self.num_nodes)
30
                )
31
                # query.append(np.random.randint(l_bw, u_bw))
32
                query.append(bw[i])
1✔
33
                query.append(np.random.randint(l_lat, u_lat))
1✔
34
                connection.append(tuple(query))
1✔
35
        else:
36
            for i in range(querynum):
×
37
                query = []
×
38
                src = np.random.randint(0, self.num_nodes)
×
39
                query.append(src)
×
40
                dest = np.random.randint(0, self.num_nodes)
×
41
                while dest == src:
×
42
                    dest = np.random.randint(0, self.num_nodes)
×
43
                query.append(dest)
×
44
                # query.append(np.random.randint(l_bw, u_bw))
45
                query.append(bw[i])
×
46
                query.append(np.random.randint(l_lat, u_lat))
×
47
                connection.append(tuple(query))
×
48

49
        with open("connection.json", "w") as json_file:
1✔
50
            data = connection
1✔
51
            json.dump(data, json_file, indent=4)
1✔
52

53
        return connection
1✔
54

55
    def lognormal(self, mu, sigma, size):
1✔
56
        normal_std = 0.5
1✔
57
        # normal_std = np.sqrt(np.log(1 + (sigma/mu)**2))
58
        normal_mean = np.log(mu) - normal_std**2 / 2
1✔
59
        return np.random.lognormal(normal_mean, normal_std, size)
1✔
60

61
    def random(self, min, mx, size):
1✔
62
        return np.random.randint(min, max, 1000)
×
63

64
    def linearGrouping(self, tm, k):
1✔
65
        if len(tm) > 20:
×
66
            tm.sort(key=lambda x: x[2])
×
67

68
        group_list = [tm[x : x + k] for x in range(0, len(tm), k)]
×
69

70
        # with open('splittedconnection.json', 'w') as json_file:
71
        #    data = splitted_list
72
        #    json.dump(data, json_file, indent=4)
73

74
        print(group_list)
×
75

76
        return group_list
×
77

78
    def geometricGrouping(self, tm, k):
1✔
79
        pass
×
80

81
    def altGeometricGrouping(self, tm, k):
1✔
82
        pass
×
83

84

85
# tm = RandomConnectionGenerator(20)
86
# connection = tm.randomConnectionGenerator(3, 100, 1000, 1000, 1500, 2022)
87
# split_connection = tm.connectionSplitter(5)
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