topolib 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of topolib might be problematic. Click here for more details.

analysis/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .metrics import Metrics
2
+
3
+ __all__ = ["Metrics"]
analysis/metrics.py ADDED
@@ -0,0 +1,80 @@
1
+ """
2
+ Metrics module for network topology analysis.
3
+ """
4
+
5
+ from typing import List, Any, Dict, Optional
6
+
7
+
8
+ from topolib.topology import Topology
9
+
10
+
11
+ class Metrics:
12
+ """
13
+ Provides static methods for computing metrics on network topologies.
14
+
15
+ Todos los métodos reciben una instancia de Topology.
16
+
17
+ Métodos
18
+ -------
19
+ node_degree(topology)
20
+ Calcula el grado de cada nodo.
21
+ link_length_stats(topology)
22
+ Calcula estadísticas (min, max, avg) de las longitudes de los enlaces.
23
+ connection_matrix(topology)
24
+ Construye la matriz de adyacencia.
25
+ """
26
+
27
+ @staticmethod
28
+ def node_degree(topology: "Topology") -> Dict[int, int]:
29
+ """
30
+ Calculates the degree of each node in the topology.
31
+
32
+ :param topology: Instance of topolib.topology.topology.Topology.
33
+ :type topology: topolib.topology.topology.Topology
34
+ :return: Dictionary {node_id: degree}
35
+ :rtype: dict[int, int]
36
+ """
37
+ degree = {n.id: 0 for n in topology.nodes}
38
+ for link in topology.links:
39
+ degree[link.source.id] += 1
40
+ degree[link.target.id] += 1
41
+ return degree
42
+
43
+ @staticmethod
44
+ def link_length_stats(topology: "Topology") -> Dict[str, Optional[float]]:
45
+ """
46
+ Calculates the minimum, maximum, and average link lengths.
47
+
48
+ :param topology: Instance of topolib.topology.topology.Topology.
49
+ :type topology: topolib.topology.topology.Topology
50
+ :return: Dictionary with keys 'min', 'max', 'avg'.
51
+ :rtype: dict[str, float | None]
52
+ """
53
+ lengths = [l.length for l in topology.links]
54
+ if not lengths:
55
+ return {"min": None, "max": None, "avg": None}
56
+ return {
57
+ "min": min(lengths),
58
+ "max": max(lengths),
59
+ "avg": sum(lengths) / len(lengths),
60
+ }
61
+
62
+ @staticmethod
63
+ def connection_matrix(topology: "Topology") -> List[List[int]]:
64
+ """
65
+ Builds the adjacency matrix of the topology.
66
+
67
+ :param topology: Instance of topolib.topology.topology.Topology.
68
+ :type topology: topolib.topology.topology.Topology
69
+ :return: Adjacency matrix (1 if connected, 0 otherwise).
70
+ :rtype: list[list[int]]
71
+ """
72
+ id_to_idx = {n.id: i for i, n in enumerate(topology.nodes)}
73
+ size = len(topology.nodes)
74
+ matrix = [[0] * size for _ in range(size)]
75
+ for link in topology.links:
76
+ i = id_to_idx[link.source.id]
77
+ j = id_to_idx[link.target.id]
78
+ matrix[i][j] = 1
79
+ matrix[j][i] = 1
80
+ return matrix
assets/DT14.json ADDED
@@ -0,0 +1,386 @@
1
+ {
2
+ "alias": "DT14",
3
+ "links": [
4
+ {
5
+ "dst": 1,
6
+ "id": 0,
7
+ "length": 306.3,
8
+ "slots": 344,
9
+ "src": 0
10
+ },
11
+ {
12
+ "dst": 2,
13
+ "id": 1,
14
+ "length": 160.9,
15
+ "slots": 344,
16
+ "src": 0
17
+ },
18
+ {
19
+ "dst": 3,
20
+ "id": 2,
21
+ "length": 114.7,
22
+ "slots": 344,
23
+ "src": 0
24
+ },
25
+ {
26
+ "dst": 0,
27
+ "id": 3,
28
+ "length": 306.3,
29
+ "slots": 344,
30
+ "src": 1
31
+ },
32
+ {
33
+ "dst": 2,
34
+ "id": 4,
35
+ "length": 294.9,
36
+ "slots": 344,
37
+ "src": 1
38
+ },
39
+ {
40
+ "dst": 4,
41
+ "id": 5,
42
+ "length": 173.3,
43
+ "slots": 344,
44
+ "src": 1
45
+ },
46
+ {
47
+ "dst": 0,
48
+ "id": 6,
49
+ "length": 160.9,
50
+ "slots": 344,
51
+ "src": 2
52
+ },
53
+ {
54
+ "dst": 1,
55
+ "id": 7,
56
+ "length": 294.9,
57
+ "slots": 344,
58
+ "src": 2
59
+ },
60
+ {
61
+ "dst": 3,
62
+ "id": 8,
63
+ "length": 121.3,
64
+ "slots": 344,
65
+ "src": 2
66
+ },
67
+ {
68
+ "dst": 4,
69
+ "id": 9,
70
+ "length": 257.2,
71
+ "slots": 344,
72
+ "src": 2
73
+ },
74
+ {
75
+ "dst": 5,
76
+ "id": 10,
77
+ "length": 220.4,
78
+ "slots": 344,
79
+ "src": 2
80
+ },
81
+ {
82
+ "dst": 9,
83
+ "id": 11,
84
+ "length": 313.9,
85
+ "slots": 344,
86
+ "src": 2
87
+ },
88
+ {
89
+ "dst": 0,
90
+ "id": 12,
91
+ "length": 114.7,
92
+ "slots": 344,
93
+ "src": 3
94
+ },
95
+ {
96
+ "dst": 2,
97
+ "id": 13,
98
+ "length": 121.3,
99
+ "slots": 344,
100
+ "src": 3
101
+ },
102
+ {
103
+ "dst": 6,
104
+ "id": 14,
105
+ "length": 278.5,
106
+ "slots": 344,
107
+ "src": 3
108
+ },
109
+ {
110
+ "dst": 1,
111
+ "id": 15,
112
+ "length": 173.3,
113
+ "slots": 344,
114
+ "src": 4
115
+ },
116
+ {
117
+ "dst": 2,
118
+ "id": 16,
119
+ "length": 257.2,
120
+ "slots": 344,
121
+ "src": 4
122
+ },
123
+ {
124
+ "dst": 9,
125
+ "id": 17,
126
+ "length": 352.6,
127
+ "slots": 344,
128
+ "src": 4
129
+ },
130
+ {
131
+ "dst": 10,
132
+ "id": 18,
133
+ "length": 274.7,
134
+ "slots": 344,
135
+ "src": 4
136
+ },
137
+ {
138
+ "dst": 2,
139
+ "id": 19,
140
+ "length": 220.4,
141
+ "slots": 344,
142
+ "src": 5
143
+ },
144
+ {
145
+ "dst": 6,
146
+ "id": 20,
147
+ "length": 37.4,
148
+ "slots": 344,
149
+ "src": 5
150
+ },
151
+ {
152
+ "dst": 8,
153
+ "id": 21,
154
+ "length": 84.3,
155
+ "slots": 344,
156
+ "src": 5
157
+ },
158
+ {
159
+ "dst": 2,
160
+ "id": 22,
161
+ "length": 313.9,
162
+ "slots": 344,
163
+ "src": 9
164
+ },
165
+ {
166
+ "dst": 4,
167
+ "id": 23,
168
+ "length": 352.6,
169
+ "slots": 344,
170
+ "src": 9
171
+ },
172
+ {
173
+ "dst": 8,
174
+ "id": 24,
175
+ "length": 182.0,
176
+ "slots": 344,
177
+ "src": 9
178
+ },
179
+ {
180
+ "dst": 10,
181
+ "id": 25,
182
+ "length": 224.1,
183
+ "slots": 344,
184
+ "src": 9
185
+ },
186
+ {
187
+ "dst": 11,
188
+ "id": 26,
189
+ "length": 207.4,
190
+ "slots": 344,
191
+ "src": 9
192
+ },
193
+ {
194
+ "dst": 3,
195
+ "id": 27,
196
+ "length": 278.5,
197
+ "slots": 344,
198
+ "src": 6
199
+ },
200
+ {
201
+ "dst": 5,
202
+ "id": 28,
203
+ "length": 37.4,
204
+ "slots": 344,
205
+ "src": 6
206
+ },
207
+ {
208
+ "dst": 7,
209
+ "id": 29,
210
+ "length": 36.9,
211
+ "slots": 344,
212
+ "src": 6
213
+ },
214
+ {
215
+ "dst": 4,
216
+ "id": 30,
217
+ "length": 274.7,
218
+ "slots": 344,
219
+ "src": 10
220
+ },
221
+ {
222
+ "dst": 9,
223
+ "id": 31,
224
+ "length": 224.1,
225
+ "slots": 344,
226
+ "src": 10
227
+ },
228
+ {
229
+ "dst": 11,
230
+ "id": 32,
231
+ "length": 188.7,
232
+ "slots": 344,
233
+ "src": 10
234
+ },
235
+ {
236
+ "dst": 13,
237
+ "id": 33,
238
+ "length": 180.8,
239
+ "slots": 344,
240
+ "src": 10
241
+ },
242
+ {
243
+ "dst": 5,
244
+ "id": 34,
245
+ "length": 84.3,
246
+ "slots": 344,
247
+ "src": 8
248
+ },
249
+ {
250
+ "dst": 9,
251
+ "id": 35,
252
+ "length": 182.0,
253
+ "slots": 344,
254
+ "src": 8
255
+ },
256
+ {
257
+ "dst": 7,
258
+ "id": 36,
259
+ "length": 40.9,
260
+ "slots": 344,
261
+ "src": 8
262
+ },
263
+ {
264
+ "dst": 9,
265
+ "id": 37,
266
+ "length": 207.4,
267
+ "slots": 344,
268
+ "src": 11
269
+ },
270
+ {
271
+ "dst": 10,
272
+ "id": 38,
273
+ "length": 188.7,
274
+ "slots": 344,
275
+ "src": 11
276
+ },
277
+ {
278
+ "dst": 12,
279
+ "id": 39,
280
+ "length": 87.1,
281
+ "slots": 344,
282
+ "src": 11
283
+ },
284
+ {
285
+ "dst": 6,
286
+ "id": 40,
287
+ "length": 36.9,
288
+ "slots": 344,
289
+ "src": 7
290
+ },
291
+ {
292
+ "dst": 8,
293
+ "id": 41,
294
+ "length": 40.9,
295
+ "slots": 344,
296
+ "src": 7
297
+ },
298
+ {
299
+ "dst": 10,
300
+ "id": 42,
301
+ "length": 180.8,
302
+ "slots": 344,
303
+ "src": 13
304
+ },
305
+ {
306
+ "dst": 12,
307
+ "id": 43,
308
+ "length": 145.6,
309
+ "slots": 344,
310
+ "src": 13
311
+ },
312
+ {
313
+ "dst": 11,
314
+ "id": 44,
315
+ "length": 87.1,
316
+ "slots": 344,
317
+ "src": 12
318
+ },
319
+ {
320
+ "dst": 13,
321
+ "id": 45,
322
+ "length": 145.6,
323
+ "slots": 344,
324
+ "src": 12
325
+ }
326
+ ],
327
+ "name": "DT14",
328
+ "nodes": [
329
+ {
330
+ "id": 0,
331
+ "weight": 0.14
332
+ },
333
+ {
334
+ "id": 1,
335
+ "weight": 0.21
336
+ },
337
+ {
338
+ "id": 2,
339
+ "weight": 0.03
340
+ },
341
+ {
342
+ "id": 3,
343
+ "weight": 0.04
344
+ },
345
+ {
346
+ "id": 4,
347
+ "weight": 0.04
348
+ },
349
+ {
350
+ "id": 5,
351
+ "weight": 0.04
352
+ },
353
+ {
354
+ "id": 6,
355
+ "weight": 0.04
356
+ },
357
+ {
358
+ "id": 7,
359
+ "weight": 0.05
360
+ },
361
+ {
362
+ "id": 8,
363
+ "weight": 0.06
364
+ },
365
+ {
366
+ "id": 9,
367
+ "weight": 0.17
368
+ },
369
+ {
370
+ "id": 10,
371
+ "weight": 0.04
372
+ },
373
+ {
374
+ "id": 11,
375
+ "weight": 0.04
376
+ },
377
+ {
378
+ "id": 12,
379
+ "weight": 0.01
380
+ },
381
+ {
382
+ "id": 13,
383
+ "weight": 0.09
384
+ }
385
+ ]
386
+ }