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

Quang00 / qnscheduling / 25485096441

07 May 2026 08:33AM UTC coverage: 76.981% (+0.1%) from 76.853%
25485096441

push

github

Quang00
refactor

0 of 1 new or added line in 1 file covered. (0.0%)

2 existing lines in 1 file now uncovered.

923 of 1199 relevant lines covered (76.98%)

2.31 hits per line

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

0.0
/utils/predictor.py
1
from itertools import combinations
×
2

3
import networkx as nx
×
4

5

6
def topology_stats(gml_path: str) -> dict[str, float]:
×
7
    """Compute statistics for a network topology represented by a GML file.
8
    Args:
9
        gml_path (str): GML file path representing the network topology.
10

11
    Returns:
12
        dict[str, float]: avg_disjoint_paths, avg_hops_all, avg_hops_shortest.
13
    """
14
    G = nx.read_gml(gml_path)
×
15
    disjoint_path_counts = []
×
16
    hops_count_all_paths = []
×
17

UNCOV
18
    for u, v in combinations(G.nodes(), 2):
×
19
        paths = list(nx.edge_disjoint_paths(G, u, v))
×
20
        disjoint_path_counts.append(len(paths))
×
21
        hops_count_all_paths.extend(len(path) - 1 for path in paths)
×
22

UNCOV
23
    avg_disjoint_paths = (
×
24
        sum(disjoint_path_counts) / len(disjoint_path_counts)
25
        if disjoint_path_counts
26
        else 0
27
    )
28
    avg_hops_all = (
×
29
        sum(hops_count_all_paths) / len(hops_count_all_paths)
30
        if hops_count_all_paths
31
        else 0
32
    )
NEW
33
    avg_hops_shortest = nx.average_shortest_path_length(G)
×
34

35
    stats = {
×
36
        "avg_disjoint_paths": avg_disjoint_paths,
37
        "avg_hops_all": avg_hops_all,
38
        "avg_hops_shortest": avg_hops_shortest,
39
    }
40
    return stats
×
41

42

43
def predictor(gml_path: str) -> dict[str, float | str]:
×
44
    """Predict whether a network topology is more suitable for static or
45
    dynamic routing based on its statistics.
46

47
    Args:
48
        gml_path (str): GML file path representing the network topology.
49

50
    Returns:
51
        dict[str, float | str]: path_redundancy, path_stretch, score,
52
        prediction.
53
    """
54
    stats = topology_stats(gml_path)
×
55
    path_redundancy = stats["avg_disjoint_paths"] - 1
×
56
    path_stretch = stats["avg_hops_all"] / stats["avg_hops_shortest"] - 1
×
57
    if path_stretch == 0:
×
58
        score = 0 if path_redundancy == 0 else float("inf")
×
59
    else:
60
        score = path_redundancy / path_stretch
×
61

62
    if score == 0:
×
63
        prediction = "equal"
×
64
    elif path_redundancy < 0.3:
×
65
        prediction = "static"
×
66
    elif score >= 3.3:
×
67
        prediction = "dynamic"
×
68
    else:
69
        prediction = "static"
×
70

71
    topology_prediction = {
×
72
        "path_redundancy": path_redundancy,
73
        "path_stretch": path_stretch,
74
        "score": score,
75
        "prediction": prediction,
76
    }
77
    return topology_prediction
×
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

© 2026 Coveralls, Inc