topolib 0.3.0__tar.gz
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.
- topolib-0.3.0/LICENSE +22 -0
- topolib-0.3.0/MANIFEST.in +5 -0
- topolib-0.3.0/PKG-INFO +127 -0
- topolib-0.3.0/README.md +105 -0
- topolib-0.3.0/diagrams/class_diagram.puml +75 -0
- topolib-0.3.0/docs/source/conf.py +37 -0
- topolib-0.3.0/docs/source/index.rst +33 -0
- topolib-0.3.0/docs/source/modules.rst +7 -0
- topolib-0.3.0/docs/source/topolib.analysis.rst +21 -0
- topolib-0.3.0/docs/source/topolib.elements.rst +23 -0
- topolib-0.3.0/docs/source/topolib.rst +20 -0
- topolib-0.3.0/docs/source/topolib.topology.rst +29 -0
- topolib-0.3.0/pyproject.toml +37 -0
- topolib-0.3.0/setup.cfg +4 -0
- topolib-0.3.0/tests/test_link.py +77 -0
- topolib-0.3.0/tests/test_metrics.py +53 -0
- topolib-0.3.0/tests/test_node.py +28 -0
- topolib-0.3.0/tests/test_path.py +46 -0
- topolib-0.3.0/tests/test_topology.py +144 -0
- topolib-0.3.0/tests/test_version.py +6 -0
- topolib-0.3.0/topolib/analysis/__init__.py +3 -0
- topolib-0.3.0/topolib/analysis/metrics.py +80 -0
- topolib-0.3.0/topolib/assets/DT14.json +386 -0
- topolib-0.3.0/topolib/assets/DT17.json +423 -0
- topolib-0.3.0/topolib/assets/FRANCE-43.json +1104 -0
- topolib-0.3.0/topolib/assets/JPN-12.json +282 -0
- topolib-0.3.0/topolib/assets/NSFNet.json +357 -0
- topolib-0.3.0/topolib/assets/PLN-12.json +308 -0
- topolib-0.3.0/topolib/assets/UKNet.json +617 -0
- topolib-0.3.0/topolib/elements/__init__.py +8 -0
- topolib-0.3.0/topolib/elements/link.py +145 -0
- topolib-0.3.0/topolib/elements/node.py +119 -0
- topolib-0.3.0/topolib/topolib.egg-info/PKG-INFO +127 -0
- topolib-0.3.0/topolib/topolib.egg-info/SOURCES.txt +38 -0
- topolib-0.3.0/topolib/topolib.egg-info/dependency_links.txt +1 -0
- topolib-0.3.0/topolib/topolib.egg-info/requires.txt +2 -0
- topolib-0.3.0/topolib/topolib.egg-info/top_level.txt +4 -0
- topolib-0.3.0/topolib/topology/__init__.py +4 -0
- topolib-0.3.0/topolib/topology/path.py +84 -0
- topolib-0.3.0/topolib/topology/topology.py +126 -0
topolib-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2025 Danilo Bórquez-Paredes
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
topolib-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: topolib
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A compact Python library for modeling, analyzing, and visualizing optical network topologies.
|
|
5
|
+
Author-email: Danilo Bórquez-Paredes <danilo.borquez.p@uai.cl>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/DaniloBorquez/topolib
|
|
8
|
+
Project-URL: Documentation, https://topolib.readthedocs.io/
|
|
9
|
+
Project-URL: Source, https://gitlab.com/DaniloBorquez/topolib
|
|
10
|
+
Project-URL: Issues, https://gitlab.com/DaniloBorquez/topolib/-/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy>=1.21
|
|
20
|
+
Requires-Dist: networkx>=2.6
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# Topolib 🚀
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[](https://www.python.org/)
|
|
27
|
+
[](LICENSE)
|
|
28
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/issues)
|
|
29
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=develop)
|
|
30
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=release)
|
|
31
|
+
[](https://topolib.readthedocs.io/en/latest/?badge=latest)
|
|
32
|
+
|
|
33
|
+
A compact Python library for working with optical network topologies: nodes, links, metrics and visualization tools. 🌐
|
|
34
|
+
|
|
35
|
+
## Overview
|
|
36
|
+
|
|
37
|
+
Topolib models network topologies with three main modules:
|
|
38
|
+
|
|
39
|
+
- `topolib.elements` — Definitions of elementary building blocks
|
|
40
|
+
- `Node` — represents a network node with id, name and geographic coordinates
|
|
41
|
+
- `Link` — connects two `Node` objects and stores link length and id
|
|
42
|
+
|
|
43
|
+
- `topolib.topology` — High-level topology model
|
|
44
|
+
- `Topology` — holds nodes and links, provides methods to add/remove nodes and links, compute metrics, export JSON, and compute shortest/disjoint paths
|
|
45
|
+
- `Path` — represents a path through the topology
|
|
46
|
+
|
|
47
|
+
- `topolib.analysis` — Metrics and analysis helpers
|
|
48
|
+
- `Metrics` — functions to compute node degree, link length statistics, connection matrices, etc.
|
|
49
|
+
|
|
50
|
+
- `topolib.visualization` — Visualization helpers
|
|
51
|
+
- `MapView` — functions to display topology with OSM or paper-style maps
|
|
52
|
+
|
|
53
|
+
(These components are derived from the project's class diagram in `diagrams/class_diagram.puml`.)
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
- Modular design: elements, topology, analysis, and visualization
|
|
57
|
+
- Easy-to-use classes for nodes, links, and paths
|
|
58
|
+
- Built-in metrics and analysis helpers
|
|
59
|
+
- JSON import/export and interoperability
|
|
60
|
+
- Ready for Sphinx, Read the Docs, and PyPI
|
|
61
|
+
|
|
62
|
+
## Quickstart ⚡
|
|
63
|
+
|
|
64
|
+
Create and activate a virtual environment, install dev dependencies and run tests:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
python -m venv .venv
|
|
68
|
+
source .venv/bin/activate
|
|
69
|
+
python -m pip install -U pip
|
|
70
|
+
python -m pip install -r dev-requirements.txt
|
|
71
|
+
python -m pytest -q
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install topolib
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or for development:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git clone https://gitlab.com/DaniloBorquez/topolib.git
|
|
84
|
+
cd topolib
|
|
85
|
+
python -m venv .venv
|
|
86
|
+
source .venv/bin/activate
|
|
87
|
+
pip install -e .
|
|
88
|
+
pip install -r dev-requirements.txt
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
Full documentation: [https://topolib.readthedocs.io/](https://topolib.readthedocs.io/)
|
|
94
|
+
|
|
95
|
+
## Basic usage example
|
|
96
|
+
|
|
97
|
+
```py
|
|
98
|
+
from topolib.elements.node import Node
|
|
99
|
+
from topolib.topology.topology import Topology
|
|
100
|
+
|
|
101
|
+
# Create nodes
|
|
102
|
+
n1 = Node(1, 'A', 10.0, 20.0)
|
|
103
|
+
n2 = Node(2, 'B', 11.0, 21.0)
|
|
104
|
+
|
|
105
|
+
# Build topology
|
|
106
|
+
topo = Topology()
|
|
107
|
+
topo.add_node(n1)
|
|
108
|
+
topo.add_node(n2)
|
|
109
|
+
# add links, compute metrics, visualize
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## Development 🛠️
|
|
114
|
+
|
|
115
|
+
See `CONTRIBUTING.md` for development guidelines, commit message rules and pre-commit setup.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## Class diagram
|
|
120
|
+
|
|
121
|
+

|
|
122
|
+
|
|
123
|
+
(If you prefer a rendered image of the UML, render the PlantUML file locally or in your CI pipeline.)
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
See `LICENSE` in the project root.
|
topolib-0.3.0/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Topolib 🚀
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
[](https://www.python.org/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/issues)
|
|
7
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=develop)
|
|
8
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=release)
|
|
9
|
+
[](https://topolib.readthedocs.io/en/latest/?badge=latest)
|
|
10
|
+
|
|
11
|
+
A compact Python library for working with optical network topologies: nodes, links, metrics and visualization tools. 🌐
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Topolib models network topologies with three main modules:
|
|
16
|
+
|
|
17
|
+
- `topolib.elements` — Definitions of elementary building blocks
|
|
18
|
+
- `Node` — represents a network node with id, name and geographic coordinates
|
|
19
|
+
- `Link` — connects two `Node` objects and stores link length and id
|
|
20
|
+
|
|
21
|
+
- `topolib.topology` — High-level topology model
|
|
22
|
+
- `Topology` — holds nodes and links, provides methods to add/remove nodes and links, compute metrics, export JSON, and compute shortest/disjoint paths
|
|
23
|
+
- `Path` — represents a path through the topology
|
|
24
|
+
|
|
25
|
+
- `topolib.analysis` — Metrics and analysis helpers
|
|
26
|
+
- `Metrics` — functions to compute node degree, link length statistics, connection matrices, etc.
|
|
27
|
+
|
|
28
|
+
- `topolib.visualization` — Visualization helpers
|
|
29
|
+
- `MapView` — functions to display topology with OSM or paper-style maps
|
|
30
|
+
|
|
31
|
+
(These components are derived from the project's class diagram in `diagrams/class_diagram.puml`.)
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
- Modular design: elements, topology, analysis, and visualization
|
|
35
|
+
- Easy-to-use classes for nodes, links, and paths
|
|
36
|
+
- Built-in metrics and analysis helpers
|
|
37
|
+
- JSON import/export and interoperability
|
|
38
|
+
- Ready for Sphinx, Read the Docs, and PyPI
|
|
39
|
+
|
|
40
|
+
## Quickstart ⚡
|
|
41
|
+
|
|
42
|
+
Create and activate a virtual environment, install dev dependencies and run tests:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m venv .venv
|
|
46
|
+
source .venv/bin/activate
|
|
47
|
+
python -m pip install -U pip
|
|
48
|
+
python -m pip install -r dev-requirements.txt
|
|
49
|
+
python -m pytest -q
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install topolib
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or for development:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
git clone https://gitlab.com/DaniloBorquez/topolib.git
|
|
62
|
+
cd topolib
|
|
63
|
+
python -m venv .venv
|
|
64
|
+
source .venv/bin/activate
|
|
65
|
+
pip install -e .
|
|
66
|
+
pip install -r dev-requirements.txt
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
Full documentation: [https://topolib.readthedocs.io/](https://topolib.readthedocs.io/)
|
|
72
|
+
|
|
73
|
+
## Basic usage example
|
|
74
|
+
|
|
75
|
+
```py
|
|
76
|
+
from topolib.elements.node import Node
|
|
77
|
+
from topolib.topology.topology import Topology
|
|
78
|
+
|
|
79
|
+
# Create nodes
|
|
80
|
+
n1 = Node(1, 'A', 10.0, 20.0)
|
|
81
|
+
n2 = Node(2, 'B', 11.0, 21.0)
|
|
82
|
+
|
|
83
|
+
# Build topology
|
|
84
|
+
topo = Topology()
|
|
85
|
+
topo.add_node(n1)
|
|
86
|
+
topo.add_node(n2)
|
|
87
|
+
# add links, compute metrics, visualize
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Development 🛠️
|
|
92
|
+
|
|
93
|
+
See `CONTRIBUTING.md` for development guidelines, commit message rules and pre-commit setup.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## Class diagram
|
|
98
|
+
|
|
99
|
+

|
|
100
|
+
|
|
101
|
+
(If you prefer a rendered image of the UML, render the PlantUML file locally or in your CI pipeline.)
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
See `LICENSE` in the project root.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
@startuml TopolibModularClassDiagram
|
|
2
|
+
|
|
3
|
+
package topolib.topology {
|
|
4
|
+
class Topology {
|
|
5
|
+
- {static} topologies
|
|
6
|
+
-nodes: List<Node>
|
|
7
|
+
-links: List<Link>
|
|
8
|
+
+add_node(node: Node)
|
|
9
|
+
+remove_node(node_id: int)
|
|
10
|
+
+add_link(link: Link)
|
|
11
|
+
+remove_link(link_id: int)
|
|
12
|
+
+update_metrics()
|
|
13
|
+
+export_json(): str
|
|
14
|
+
+get_geographic_area(): float
|
|
15
|
+
+get_diameter(): float
|
|
16
|
+
+calculate_laplacian(): Matrix
|
|
17
|
+
+get_shortest_paths(s: int, d: int, N: int): List<Path>
|
|
18
|
+
+get_disjoint_paths(s: int, d: int, N: int): List<Path>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class Path {
|
|
22
|
+
-nodes: List<Node>
|
|
23
|
+
-total_length: float
|
|
24
|
+
+get_summary(): str
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
package topolib.elements {
|
|
29
|
+
class Node {
|
|
30
|
+
-id: int
|
|
31
|
+
-name: str
|
|
32
|
+
-latitude: float
|
|
33
|
+
-longitude: float
|
|
34
|
+
+coordinates(): Tuple[float, float]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class Link {
|
|
38
|
+
-id: int
|
|
39
|
+
-source: Node
|
|
40
|
+
-target: Node
|
|
41
|
+
-length: float
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
package topolib.analysis {
|
|
46
|
+
class Metrics {
|
|
47
|
+
+get_max_node_degree(topology: Topology): int
|
|
48
|
+
+get_min_node_degree(topology: Topology): int
|
|
49
|
+
+get_avg_node_degree(topology: Topology): float
|
|
50
|
+
+get_max_link_length(topology: Topology): float
|
|
51
|
+
+get_min_link_length(topology: Topology): float
|
|
52
|
+
+get_avg_link_length(topology: Topology): float
|
|
53
|
+
+get_connection_matrix(topology: Topology): numpy.ndarray
|
|
54
|
+
+get_link_value_matrix(topology: Topology): numpy.ndarray
|
|
55
|
+
+get_node_degree_matrix(topology: Topology): numpy.ndarray
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
package topolib.visualization {
|
|
60
|
+
class MapView {
|
|
61
|
+
+display_osm(topology: Topology)
|
|
62
|
+
+display_paper(topology: Topology)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
topolib.topology.Topology --> topolib.elements.Node : uses
|
|
67
|
+
topolib.topology.Topology --> topolib.elements.Link : uses
|
|
68
|
+
topolib.topology.Topology --> topolib.analysis.Metrics : calculates
|
|
69
|
+
topolib.topology.Topology --> topolib.visualization.MapView : visualizes
|
|
70
|
+
topolib.topology.Topology --> topolib.topology.Path : generates
|
|
71
|
+
|
|
72
|
+
topolib.elements.Link --> topolib.elements.Node : connects
|
|
73
|
+
topolib.topology.Path --> topolib.elements.Node : traverses
|
|
74
|
+
|
|
75
|
+
@enduml
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
|
|
3
|
+
# -- Add project root to sys.path for autodoc --
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
sys.path.insert(0, os.path.abspath(
|
|
7
|
+
os.path.join(os.path.dirname(__file__), '../../')))
|
|
8
|
+
#
|
|
9
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
10
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
11
|
+
|
|
12
|
+
# -- Project information -----------------------------------------------------
|
|
13
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
14
|
+
|
|
15
|
+
project = 'topolib'
|
|
16
|
+
copyright = '2025, Danilo Borquez'
|
|
17
|
+
author = 'Danilo Borquez'
|
|
18
|
+
release = '0.1.0'
|
|
19
|
+
|
|
20
|
+
# -- General configuration ---------------------------------------------------
|
|
21
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
22
|
+
|
|
23
|
+
extensions = [
|
|
24
|
+
'sphinx.ext.autodoc',
|
|
25
|
+
'sphinx.ext.napoleon',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
templates_path = ['_templates']
|
|
29
|
+
exclude_patterns = []
|
|
30
|
+
|
|
31
|
+
language = 'en'
|
|
32
|
+
|
|
33
|
+
# -- Options for HTML output -------------------------------------------------
|
|
34
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
35
|
+
|
|
36
|
+
html_theme = 'sphinx_rtd_theme'
|
|
37
|
+
html_static_path = ['_static']
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.. topolib documentation master file, created by
|
|
2
|
+
sphinx-quickstart on Wed Oct 8 18:21:25 2025.
|
|
3
|
+
You can adapt this file completely to your liking, but it should at least
|
|
4
|
+
contain the root `toctree` directive.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Welcome to Topolib's documentation!
|
|
8
|
+
===================================
|
|
9
|
+
|
|
10
|
+
**Topolib** is a compact Python library for modeling, analyzing, and visualizing optical network topologies.
|
|
11
|
+
It provides a clean, object-oriented API for nodes, links, topologies, metrics, and visualization tools, making it ideal for research, teaching, and rapid prototyping in network science and engineering.
|
|
12
|
+
|
|
13
|
+
**Key features:**
|
|
14
|
+
|
|
15
|
+
- Modular design: elements, topology, analysis, and visualization
|
|
16
|
+
- Easy-to-use classes for nodes, links, and paths
|
|
17
|
+
- Built-in metrics and analysis helpers
|
|
18
|
+
- JSON import/export and interoperability
|
|
19
|
+
- Ready for integration with Sphinx, Read the Docs, and PyPI
|
|
20
|
+
|
|
21
|
+
Get started by exploring the modules below, or see the README for quick usage examples.
|
|
22
|
+
|
|
23
|
+
.. note::
|
|
24
|
+
This documentation is generated automatically from the source code and is always up to date with the latest release.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
.. toctree::
|
|
29
|
+
:maxdepth: 2
|
|
30
|
+
:caption: Contents:
|
|
31
|
+
|
|
32
|
+
modules
|
|
33
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
topolib.analysis package
|
|
2
|
+
========================
|
|
3
|
+
|
|
4
|
+
Submodules
|
|
5
|
+
----------
|
|
6
|
+
|
|
7
|
+
topolib.analysis.metrics module
|
|
8
|
+
-------------------------------
|
|
9
|
+
|
|
10
|
+
.. automodule:: topolib.analysis.metrics
|
|
11
|
+
:members:
|
|
12
|
+
:undoc-members:
|
|
13
|
+
:show-inheritance:
|
|
14
|
+
|
|
15
|
+
Module contents
|
|
16
|
+
---------------
|
|
17
|
+
|
|
18
|
+
.. automodule:: topolib.analysis
|
|
19
|
+
:members:
|
|
20
|
+
:undoc-members:
|
|
21
|
+
:show-inheritance:
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
topolib.elements package
|
|
2
|
+
========================
|
|
3
|
+
|
|
4
|
+
Submodules
|
|
5
|
+
----------
|
|
6
|
+
|
|
7
|
+
topolib.elements.link module
|
|
8
|
+
----------------------------
|
|
9
|
+
|
|
10
|
+
.. automodule:: topolib.elements.link
|
|
11
|
+
:members:
|
|
12
|
+
:undoc-members:
|
|
13
|
+
:show-inheritance:
|
|
14
|
+
|
|
15
|
+
topolib.elements.node module
|
|
16
|
+
----------------------------
|
|
17
|
+
|
|
18
|
+
.. automodule:: topolib.elements.node
|
|
19
|
+
:members:
|
|
20
|
+
:undoc-members:
|
|
21
|
+
:show-inheritance:
|
|
22
|
+
|
|
23
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
topolib package
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
Subpackages
|
|
5
|
+
-----------
|
|
6
|
+
|
|
7
|
+
.. toctree::
|
|
8
|
+
:maxdepth: 4
|
|
9
|
+
|
|
10
|
+
topolib.analysis
|
|
11
|
+
topolib.elements
|
|
12
|
+
topolib.topology
|
|
13
|
+
|
|
14
|
+
Module contents
|
|
15
|
+
---------------
|
|
16
|
+
|
|
17
|
+
.. automodule:: topolib
|
|
18
|
+
:members:
|
|
19
|
+
:undoc-members:
|
|
20
|
+
:show-inheritance:
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
topolib.topology package
|
|
2
|
+
========================
|
|
3
|
+
|
|
4
|
+
Submodules
|
|
5
|
+
----------
|
|
6
|
+
|
|
7
|
+
topolib.topology.path module
|
|
8
|
+
----------------------------
|
|
9
|
+
|
|
10
|
+
.. automodule:: topolib.topology.path
|
|
11
|
+
:members:
|
|
12
|
+
:undoc-members:
|
|
13
|
+
:show-inheritance:
|
|
14
|
+
|
|
15
|
+
topolib.topology.topology module
|
|
16
|
+
--------------------------------
|
|
17
|
+
|
|
18
|
+
.. automodule:: topolib.topology.topology
|
|
19
|
+
:members:
|
|
20
|
+
:undoc-members:
|
|
21
|
+
:show-inheritance:
|
|
22
|
+
|
|
23
|
+
Module contents
|
|
24
|
+
---------------
|
|
25
|
+
|
|
26
|
+
.. automodule:: topolib.topology
|
|
27
|
+
:members:
|
|
28
|
+
:undoc-members:
|
|
29
|
+
:show-inheritance:
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "topolib"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "A compact Python library for modeling, analyzing, and visualizing optical network topologies."
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Danilo Bórquez-Paredes", email = "danilo.borquez.p@uai.cl" }
|
|
11
|
+
]
|
|
12
|
+
license = "MIT"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
dependencies = [
|
|
16
|
+
"numpy>=1.21",
|
|
17
|
+
"networkx>=2.6"
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Intended Audience :: Science/Research",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://gitlab.com/DaniloBorquez/topolib"
|
|
29
|
+
Documentation = "https://topolib.readthedocs.io/"
|
|
30
|
+
Source = "https://gitlab.com/DaniloBorquez/topolib"
|
|
31
|
+
Issues = "https://gitlab.com/DaniloBorquez/topolib/-/issues"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["topolib"]
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
include-package-data = true
|
topolib-0.3.0/setup.cfg
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from topolib.elements.node import Node
|
|
3
|
+
from topolib.elements.link import Link
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_link_creation_and_properties():
|
|
7
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
8
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
9
|
+
link = Link(10, n1, n2, 5.5)
|
|
10
|
+
|
|
11
|
+
assert link.id == 10
|
|
12
|
+
assert link.source is n1
|
|
13
|
+
assert link.target is n2
|
|
14
|
+
assert link.length == 5.5
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_link_length_validation():
|
|
18
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
19
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
20
|
+
with pytest.raises(ValueError):
|
|
21
|
+
Link(1, n1, n2, -1)
|
|
22
|
+
with pytest.raises(TypeError):
|
|
23
|
+
Link(1, n1, n2, "not-a-number")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_link_endpoint_validation():
|
|
27
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
28
|
+
|
|
29
|
+
# a dummy object without node attributes
|
|
30
|
+
class Dummy:
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
with pytest.raises(TypeError):
|
|
34
|
+
Link(1, Dummy(), n1, 1.0)
|
|
35
|
+
with pytest.raises(TypeError):
|
|
36
|
+
Link(1, n1, Dummy(), 1.0)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_endpoints_and_repr():
|
|
40
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
41
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
42
|
+
link = Link(2, n1, n2, 10)
|
|
43
|
+
assert link.endpoints() == (n1, n2)
|
|
44
|
+
assert "Link(id=2" in repr(link)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_link_setters_and_errors():
|
|
48
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
49
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
50
|
+
link = Link(99, n1, n2, 1.0)
|
|
51
|
+
# Test id setter
|
|
52
|
+
link.id = 123
|
|
53
|
+
assert link.id == 123
|
|
54
|
+
|
|
55
|
+
# Test source setter error
|
|
56
|
+
class Dummy:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
with pytest.raises(TypeError):
|
|
60
|
+
link.source = Dummy()
|
|
61
|
+
# Test target setter error
|
|
62
|
+
with pytest.raises(TypeError):
|
|
63
|
+
link.target = Dummy()
|
|
64
|
+
# Test length setter error (non-numeric)
|
|
65
|
+
with pytest.raises(TypeError):
|
|
66
|
+
link.length = "bad"
|
|
67
|
+
# Test length setter error (negative)
|
|
68
|
+
with pytest.raises(ValueError):
|
|
69
|
+
link.length = -5
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_link_length_setter_typeerror():
|
|
73
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
74
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
75
|
+
link = Link(1, n1, n2, 1.0)
|
|
76
|
+
with pytest.raises(TypeError):
|
|
77
|
+
link.length = object() # No convertible a float, cubre el except
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from topolib.analysis.metrics import Metrics
|
|
4
|
+
from topolib.topology import Topology
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from topolib.elements.node import Node
|
|
8
|
+
from topolib.elements.link import Link
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_node_degree():
|
|
12
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
13
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
14
|
+
n3 = Node(3, "C", 2.0, 2.0)
|
|
15
|
+
l1 = Link(1, n1, n2, 10)
|
|
16
|
+
l2 = Link(2, n2, n3, 20)
|
|
17
|
+
topo = Topology(nodes=[n1, n2, n3], links=[l1, l2])
|
|
18
|
+
result = Metrics.node_degree(topo)
|
|
19
|
+
assert result == {1: 1, 2: 2, 3: 1}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_link_length_stats():
|
|
23
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
24
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
25
|
+
l1 = Link(1, n1, n2, 10)
|
|
26
|
+
l2 = Link(2, n2, n1, 20)
|
|
27
|
+
topo = Topology(nodes=[n1, n2], links=[l1, l2])
|
|
28
|
+
stats = Metrics.link_length_stats(topo)
|
|
29
|
+
assert stats["min"] == 10
|
|
30
|
+
assert stats["max"] == 20
|
|
31
|
+
assert stats["avg"] == 15
|
|
32
|
+
# Empty case
|
|
33
|
+
topo_empty = Topology()
|
|
34
|
+
assert Metrics.link_length_stats(topo_empty) == {
|
|
35
|
+
"min": None,
|
|
36
|
+
"max": None,
|
|
37
|
+
"avg": None,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_connection_matrix():
|
|
42
|
+
n1 = Node(1, "A", 0.0, 0.0)
|
|
43
|
+
n2 = Node(2, "B", 1.0, 1.0)
|
|
44
|
+
n3 = Node(3, "C", 2.0, 2.0)
|
|
45
|
+
l1 = Link(1, n1, n2, 10)
|
|
46
|
+
l2 = Link(2, n2, n3, 20)
|
|
47
|
+
topo = Topology(nodes=[n1, n2, n3], links=[l1, l2])
|
|
48
|
+
matrix = Metrics.connection_matrix(topo)
|
|
49
|
+
assert matrix == [
|
|
50
|
+
[0, 1, 0],
|
|
51
|
+
[1, 0, 1],
|
|
52
|
+
[0, 1, 0],
|
|
53
|
+
]
|