multimodalrouter 0.1.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 multimodalrouter might be problematic. Click here for more details.

@@ -0,0 +1,10 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tobias Karusseit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
@@ -0,0 +1,2 @@
1
+ include LICENSE
2
+ include README.md
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: multimodalrouter
3
+ Version: 0.1.0
4
+ Summary: A graph-based routing library for dynamic routing.
5
+ Author-email: Tobias Karusseit <karusseittobi@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Tobias Karusseit
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+
16
+
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE.md
20
+ Requires-Dist: colorama>=0.4.6
21
+ Requires-Dist: dill>=0.4.0
22
+ Requires-Dist: filelock>=3.19.1
23
+ Requires-Dist: fsspec>=2025.9.0
24
+ Requires-Dist: Jinja2>=3.1.6
25
+ Requires-Dist: MarkupSafe>=3.0.2
26
+ Requires-Dist: mpmath>=1.3.0
27
+ Requires-Dist: networkx>=3.5
28
+ Requires-Dist: numpy>=2.3.3
29
+ Requires-Dist: pandas>=2.3.2
30
+ Requires-Dist: parquet>=1.3.1
31
+ Requires-Dist: ply>=3.11
32
+ Requires-Dist: pyarrow>=21.0.0
33
+ Requires-Dist: python-dateutil>=2.9.0.post0
34
+ Requires-Dist: pytz>=2025.2
35
+ Requires-Dist: setuptools>=80.9.0
36
+ Requires-Dist: six>=1.17.0
37
+ Requires-Dist: sympy>=1.14.0
38
+ Requires-Dist: thriftpy2>=0.5.3
39
+ Requires-Dist: tqdm>=4.67.1
40
+ Requires-Dist: typing_extensions>=4.15.0
41
+ Requires-Dist: tzdata>=2025.2
42
+ Provides-Extra: torch
43
+ Requires-Dist: torch>=2.8.0; extra == "torch"
44
+ Dynamic: license-file
45
+
46
+ # Multi Modal Router
47
+
48
+ The Multi Modal Router is a graph-based routing engine that allows you to build and query any hub-based network. It supports multiple transport modes like driving, flying, or shipping, and lets you optimize routes by distance, time, or custom metrics. It can be expanded to any n-dimensional space making it versatile in any coordinate space
49
+
50
+ > NOTE: This project is a work in progress and features might be added and or changed
51
+
52
+ # In depth Documentation
53
+
54
+ [installation guide](./docs/installation.md)
55
+
56
+ [graph module documentation](./docs/graph.md)
57
+
58
+ [code examples](./docs/examples/demo.py)
59
+
60
+ [command line interface documentation](./docs/cli.md)
61
+
62
+ [utilities documentation](./docs/utils.md)
63
+
64
+
65
+ # Features
66
+
67
+ ## Building Freedom / Unlimited Usecases
68
+
69
+ The graph can be build from any data aslong as the required fields are present ([example](./docs/examples/demoData.csv)). Whether your data contains real world places or you are working in a more abstract spaces with special coordinates and distance metrics the graph will behave the same (with minor limitations due to dynamic distance calculation, but not a problem when distances are already precomputed. [solutions](./docs/graph.md#advanced-options)).
70
+
71
+ #### Example Usecases
72
+
73
+ - real world flight router
74
+ - uses data with real flight data and actuall airport coordinates
75
+ - builds a graph with `airport` [Hubs](./docs/graph.md#hub)
76
+ - connects `airports` based on flight routes
77
+ - `finds` the `shortest flights` or `multi leg routes` to get from `A` to `B`
78
+ - simple example implementation [here](./docs/examples/flightRouter/main.py)
79
+
80
+ - social relation ship graph
81
+ - uses user data like a social network where users are connected through others via a group of other users
82
+ - builds a graph with `users` as Hubs
83
+ - connects users based on know interactions or any other connection meric
84
+ - `finds` users that are likely to `share`; `interests`, `friends`, `a social circle`, etc.
85
+
86
+ - coordinate based game AI and pathfinding
87
+ - uses a predefined path network (e.g. a simple maze)
88
+ - `builds` the garph representation of the network
89
+ - `finds` the shortest way to get from any point `A` to any other point `B` in the network
90
+ - you can checkout a simple example implementation for a maze pathfinder [here](./docs/examples/mazePathfinder/main.py)
91
+
92
+ ![example from the maze solver](./docs/solvedMaze1.png)
93
+
94
+ ## Important considerations for your usecase
95
+
96
+ Depending on your usecase and datasets some features may not be usable see solutions below
97
+
98
+ ### potential problems based on use case
99
+
100
+ **Please check your data for the following**
101
+
102
+ | distance present | coordinate format | unusable features | special considerations |
103
+ |------------------|-------------------|-------------------|------------------------|
104
+ | YES | degrees | None | None|
105
+ | YES|not degrees| runtime distance calculations| set [drivingEnabled = False](./docs/graph.md#args) or do [this](./docs/graph.md#swap-distance-method)|
106
+ | NO | degrees | None | distances must be calculated when [preprocessing](./src/multimodalrouter/utils/preprocessor.py) |
107
+ | NO | not degrees | **ALL** | **U cant build the graph with neither distances or supported coordinates!** [**solution**](./docs/graph.md#swap-distance-method)
108
+
109
+ [**example dataframe with the required fields**](./docs/examples/demoData.csv)
110
+
111
+ ### License
112
+
113
+ [see here](./LICENSE.md)
114
+
115
+
@@ -0,0 +1,70 @@
1
+ # Multi Modal Router
2
+
3
+ The Multi Modal Router is a graph-based routing engine that allows you to build and query any hub-based network. It supports multiple transport modes like driving, flying, or shipping, and lets you optimize routes by distance, time, or custom metrics. It can be expanded to any n-dimensional space making it versatile in any coordinate space
4
+
5
+ > NOTE: This project is a work in progress and features might be added and or changed
6
+
7
+ # In depth Documentation
8
+
9
+ [installation guide](./docs/installation.md)
10
+
11
+ [graph module documentation](./docs/graph.md)
12
+
13
+ [code examples](./docs/examples/demo.py)
14
+
15
+ [command line interface documentation](./docs/cli.md)
16
+
17
+ [utilities documentation](./docs/utils.md)
18
+
19
+
20
+ # Features
21
+
22
+ ## Building Freedom / Unlimited Usecases
23
+
24
+ The graph can be build from any data aslong as the required fields are present ([example](./docs/examples/demoData.csv)). Whether your data contains real world places or you are working in a more abstract spaces with special coordinates and distance metrics the graph will behave the same (with minor limitations due to dynamic distance calculation, but not a problem when distances are already precomputed. [solutions](./docs/graph.md#advanced-options)).
25
+
26
+ #### Example Usecases
27
+
28
+ - real world flight router
29
+ - uses data with real flight data and actuall airport coordinates
30
+ - builds a graph with `airport` [Hubs](./docs/graph.md#hub)
31
+ - connects `airports` based on flight routes
32
+ - `finds` the `shortest flights` or `multi leg routes` to get from `A` to `B`
33
+ - simple example implementation [here](./docs/examples/flightRouter/main.py)
34
+
35
+ - social relation ship graph
36
+ - uses user data like a social network where users are connected through others via a group of other users
37
+ - builds a graph with `users` as Hubs
38
+ - connects users based on know interactions or any other connection meric
39
+ - `finds` users that are likely to `share`; `interests`, `friends`, `a social circle`, etc.
40
+
41
+ - coordinate based game AI and pathfinding
42
+ - uses a predefined path network (e.g. a simple maze)
43
+ - `builds` the garph representation of the network
44
+ - `finds` the shortest way to get from any point `A` to any other point `B` in the network
45
+ - you can checkout a simple example implementation for a maze pathfinder [here](./docs/examples/mazePathfinder/main.py)
46
+
47
+ ![example from the maze solver](./docs/solvedMaze1.png)
48
+
49
+ ## Important considerations for your usecase
50
+
51
+ Depending on your usecase and datasets some features may not be usable see solutions below
52
+
53
+ ### potential problems based on use case
54
+
55
+ **Please check your data for the following**
56
+
57
+ | distance present | coordinate format | unusable features | special considerations |
58
+ |------------------|-------------------|-------------------|------------------------|
59
+ | YES | degrees | None | None|
60
+ | YES|not degrees| runtime distance calculations| set [drivingEnabled = False](./docs/graph.md#args) or do [this](./docs/graph.md#swap-distance-method)|
61
+ | NO | degrees | None | distances must be calculated when [preprocessing](./src/multimodalrouter/utils/preprocessor.py) |
62
+ | NO | not degrees | **ALL** | **U cant build the graph with neither distances or supported coordinates!** [**solution**](./docs/graph.md#swap-distance-method)
63
+
64
+ [**example dataframe with the required fields**](./docs/examples/demoData.csv)
65
+
66
+ ### License
67
+
68
+ [see here](./LICENSE.md)
69
+
70
+
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "multimodalrouter"
7
+ version = "0.1.0"
8
+ description = "A graph-based routing library for dynamic routing."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE.md" }
11
+ authors = [
12
+ { name="Tobias Karusseit", email="karusseittobi@gmail.com" }
13
+ ]
14
+ dependencies = [
15
+ "colorama>=0.4.6",
16
+ "dill>=0.4.0",
17
+ "filelock>=3.19.1",
18
+ "fsspec>=2025.9.0",
19
+ "Jinja2>=3.1.6",
20
+ "MarkupSafe>=3.0.2",
21
+ "mpmath>=1.3.0",
22
+ "networkx>=3.5",
23
+ "numpy>=2.3.3",
24
+ "pandas>=2.3.2",
25
+ "parquet>=1.3.1",
26
+ "ply>=3.11",
27
+ "pyarrow>=21.0.0",
28
+ "python-dateutil>=2.9.0.post0",
29
+ "pytz>=2025.2",
30
+ "setuptools>=80.9.0",
31
+ "six>=1.17.0",
32
+ "sympy>=1.14.0",
33
+ "thriftpy2>=0.5.3",
34
+ "tqdm>=4.67.1",
35
+ "typing_extensions>=4.15.0",
36
+ "tzdata>=2025.2",
37
+ ]
38
+
39
+ requires-python = ">=3.11"
40
+
41
+
42
+ [project.optional-dependencies]
43
+ torch = ["torch>=2.8.0"]
44
+
45
+ [tool.setuptools]
46
+ package-dir = {"" = "src"}
47
+ packages = ["multimodalrouter", "multimodalrouter.graph", "multimodalrouter.router", "multimodalrouter.utils"]
48
+
49
+ [project.scripts]
50
+ multiModalRouter-build = "multimodalrouter.router.build:main"
51
+ multiModalRouter-route = "multimodalrouter.router.route:main"
52
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: multimodalrouter
3
+ Version: 0.1.0
4
+ Summary: A graph-based routing library for dynamic routing.
5
+ Author-email: Tobias Karusseit <karusseittobi@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Tobias Karusseit
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+
16
+
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE.md
20
+ Requires-Dist: colorama>=0.4.6
21
+ Requires-Dist: dill>=0.4.0
22
+ Requires-Dist: filelock>=3.19.1
23
+ Requires-Dist: fsspec>=2025.9.0
24
+ Requires-Dist: Jinja2>=3.1.6
25
+ Requires-Dist: MarkupSafe>=3.0.2
26
+ Requires-Dist: mpmath>=1.3.0
27
+ Requires-Dist: networkx>=3.5
28
+ Requires-Dist: numpy>=2.3.3
29
+ Requires-Dist: pandas>=2.3.2
30
+ Requires-Dist: parquet>=1.3.1
31
+ Requires-Dist: ply>=3.11
32
+ Requires-Dist: pyarrow>=21.0.0
33
+ Requires-Dist: python-dateutil>=2.9.0.post0
34
+ Requires-Dist: pytz>=2025.2
35
+ Requires-Dist: setuptools>=80.9.0
36
+ Requires-Dist: six>=1.17.0
37
+ Requires-Dist: sympy>=1.14.0
38
+ Requires-Dist: thriftpy2>=0.5.3
39
+ Requires-Dist: tqdm>=4.67.1
40
+ Requires-Dist: typing_extensions>=4.15.0
41
+ Requires-Dist: tzdata>=2025.2
42
+ Provides-Extra: torch
43
+ Requires-Dist: torch>=2.8.0; extra == "torch"
44
+ Dynamic: license-file
45
+
46
+ # Multi Modal Router
47
+
48
+ The Multi Modal Router is a graph-based routing engine that allows you to build and query any hub-based network. It supports multiple transport modes like driving, flying, or shipping, and lets you optimize routes by distance, time, or custom metrics. It can be expanded to any n-dimensional space making it versatile in any coordinate space
49
+
50
+ > NOTE: This project is a work in progress and features might be added and or changed
51
+
52
+ # In depth Documentation
53
+
54
+ [installation guide](./docs/installation.md)
55
+
56
+ [graph module documentation](./docs/graph.md)
57
+
58
+ [code examples](./docs/examples/demo.py)
59
+
60
+ [command line interface documentation](./docs/cli.md)
61
+
62
+ [utilities documentation](./docs/utils.md)
63
+
64
+
65
+ # Features
66
+
67
+ ## Building Freedom / Unlimited Usecases
68
+
69
+ The graph can be build from any data aslong as the required fields are present ([example](./docs/examples/demoData.csv)). Whether your data contains real world places or you are working in a more abstract spaces with special coordinates and distance metrics the graph will behave the same (with minor limitations due to dynamic distance calculation, but not a problem when distances are already precomputed. [solutions](./docs/graph.md#advanced-options)).
70
+
71
+ #### Example Usecases
72
+
73
+ - real world flight router
74
+ - uses data with real flight data and actuall airport coordinates
75
+ - builds a graph with `airport` [Hubs](./docs/graph.md#hub)
76
+ - connects `airports` based on flight routes
77
+ - `finds` the `shortest flights` or `multi leg routes` to get from `A` to `B`
78
+ - simple example implementation [here](./docs/examples/flightRouter/main.py)
79
+
80
+ - social relation ship graph
81
+ - uses user data like a social network where users are connected through others via a group of other users
82
+ - builds a graph with `users` as Hubs
83
+ - connects users based on know interactions or any other connection meric
84
+ - `finds` users that are likely to `share`; `interests`, `friends`, `a social circle`, etc.
85
+
86
+ - coordinate based game AI and pathfinding
87
+ - uses a predefined path network (e.g. a simple maze)
88
+ - `builds` the garph representation of the network
89
+ - `finds` the shortest way to get from any point `A` to any other point `B` in the network
90
+ - you can checkout a simple example implementation for a maze pathfinder [here](./docs/examples/mazePathfinder/main.py)
91
+
92
+ ![example from the maze solver](./docs/solvedMaze1.png)
93
+
94
+ ## Important considerations for your usecase
95
+
96
+ Depending on your usecase and datasets some features may not be usable see solutions below
97
+
98
+ ### potential problems based on use case
99
+
100
+ **Please check your data for the following**
101
+
102
+ | distance present | coordinate format | unusable features | special considerations |
103
+ |------------------|-------------------|-------------------|------------------------|
104
+ | YES | degrees | None | None|
105
+ | YES|not degrees| runtime distance calculations| set [drivingEnabled = False](./docs/graph.md#args) or do [this](./docs/graph.md#swap-distance-method)|
106
+ | NO | degrees | None | distances must be calculated when [preprocessing](./src/multimodalrouter/utils/preprocessor.py) |
107
+ | NO | not degrees | **ALL** | **U cant build the graph with neither distances or supported coordinates!** [**solution**](./docs/graph.md#swap-distance-method)
108
+
109
+ [**example dataframe with the required fields**](./docs/examples/demoData.csv)
110
+
111
+ ### License
112
+
113
+ [see here](./LICENSE.md)
114
+
115
+
@@ -0,0 +1,25 @@
1
+ LICENSE.md
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ src/multiModalRouter.egg-info/PKG-INFO
6
+ src/multiModalRouter.egg-info/SOURCES.txt
7
+ src/multiModalRouter.egg-info/dependency_links.txt
8
+ src/multiModalRouter.egg-info/entry_points.txt
9
+ src/multiModalRouter.egg-info/requires.txt
10
+ src/multiModalRouter.egg-info/top_level.txt
11
+ src/multimodalrouter/__init__.py
12
+ src/multimodalrouter.egg-info/PKG-INFO
13
+ src/multimodalrouter.egg-info/SOURCES.txt
14
+ src/multimodalrouter.egg-info/dependency_links.txt
15
+ src/multimodalrouter.egg-info/entry_points.txt
16
+ src/multimodalrouter.egg-info/requires.txt
17
+ src/multimodalrouter.egg-info/top_level.txt
18
+ src/multimodalrouter/graph/__init__.py
19
+ src/multimodalrouter/graph/dataclasses.py
20
+ src/multimodalrouter/graph/graph.py
21
+ src/multimodalrouter/router/__init__.py
22
+ src/multimodalrouter/router/build.py
23
+ src/multimodalrouter/router/route.py
24
+ src/multimodalrouter/utils/__init__.py
25
+ src/multimodalrouter/utils/preprocessor.py
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ multiModalRouter-build = multimodalrouter.router.build:main
3
+ multiModalRouter-route = multimodalrouter.router.route:main
@@ -0,0 +1,25 @@
1
+ colorama>=0.4.6
2
+ dill>=0.4.0
3
+ filelock>=3.19.1
4
+ fsspec>=2025.9.0
5
+ Jinja2>=3.1.6
6
+ MarkupSafe>=3.0.2
7
+ mpmath>=1.3.0
8
+ networkx>=3.5
9
+ numpy>=2.3.3
10
+ pandas>=2.3.2
11
+ parquet>=1.3.1
12
+ ply>=3.11
13
+ pyarrow>=21.0.0
14
+ python-dateutil>=2.9.0.post0
15
+ pytz>=2025.2
16
+ setuptools>=80.9.0
17
+ six>=1.17.0
18
+ sympy>=1.14.0
19
+ thriftpy2>=0.5.3
20
+ tqdm>=4.67.1
21
+ typing_extensions>=4.15.0
22
+ tzdata>=2025.2
23
+
24
+ [torch]
25
+ torch>=2.8.0
@@ -0,0 +1 @@
1
+ multimodalrouter
@@ -0,0 +1,4 @@
1
+ from .graph import RouteGraph, Hub, EdgeMetadata, OptimizationMetric, Route, VerboseRoute
2
+ from .utils import preprocessor
3
+
4
+ __all__ = ["RouteGraph", "Hub", "EdgeMetadata", "OptimizationMetric", "Route", "VerboseRoute", "preprocessor"]
@@ -0,0 +1,2 @@
1
+ from .graph import RouteGraph # noqa: F401
2
+ from .dataclasses import Hub, EdgeMetadata, OptimizationMetric, Route, VerboseRoute # noqa: F401
@@ -0,0 +1,106 @@
1
+ # dataclasses.py
2
+ # Copyright (c) 2025 Tobias Karusseit
3
+ # Licensed under the MIT License. See LICENSE file in the project root for full license information.
4
+
5
+
6
+ from dataclasses import dataclass
7
+ from enum import Enum
8
+
9
+
10
+ class OptimizationMetric(Enum):
11
+ DISTANCE = "distance"
12
+
13
+
14
+ class EdgeMetadata:
15
+ __slots__ = ['transportMode', 'metrics']
16
+
17
+ def __init__(self, transportMode: str = None, **metrics):
18
+ self.transportMode = transportMode
19
+ self.metrics = metrics # e.g., {"distance": 12.3, "time": 15} NOTE distance is required by the graph
20
+
21
+ def getMetric(self, metric: OptimizationMetric | str):
22
+ if isinstance(metric, str):
23
+ value = self.metrics.get(metric)
24
+ if value is None:
25
+ raise KeyError(f"Metric '{metric}' not found in EdgeMetadata")
26
+ return value
27
+
28
+ value = self.metrics.get(metric.value)
29
+ if value is None:
30
+ raise KeyError(f"Metric '{metric.value}' not found in EdgeMetadata")
31
+ return value
32
+
33
+ def copy(self):
34
+ return EdgeMetadata(transportMode=self.transportMode, **self.metrics)
35
+
36
+ @property
37
+ def allMetrics(self):
38
+ return self.metrics.copy()
39
+
40
+ def __str__(self):
41
+ return f"transportMode={self.transportMode}, metrics={self.metrics}"
42
+
43
+
44
+ class Hub:
45
+ """Base hub class - using regular class instead of dataclass for __slots__ compatibility"""
46
+ __slots__ = ['coords', 'id', 'outgoing', 'hubType']
47
+
48
+ def __init__(self, coords: list[float], id: str, hubType: str):
49
+ self.coords: list[float] = coords
50
+ self.id = id
51
+ self.hubType = hubType
52
+ self.outgoing = {}
53
+
54
+ def addOutgoing(self, mode: str, dest_id: str, metrics: EdgeMetadata):
55
+ if mode not in self.outgoing:
56
+ self.outgoing[mode] = {}
57
+ self.outgoing[mode][dest_id] = metrics
58
+
59
+ def getMetrics(self, mode: str, dest_id: str) -> EdgeMetadata:
60
+ return self.outgoing.get(mode, {}).get(dest_id, None)
61
+
62
+ def getMetric(self, mode: str, dest_id: str, metric: str) -> float:
63
+ connection = self.outgoing.get(mode, {}).get(dest_id)
64
+ return getattr(connection, metric, None) if connection else None
65
+
66
+ def __hash__(self):
67
+ return hash((self.hubType, self.id))
68
+
69
+
70
+ @dataclass
71
+ class Route:
72
+ """Route class can use dataclass since it doesn't need __slots__"""
73
+ path: list[tuple[str, str]]
74
+ totalMetrics: EdgeMetadata
75
+ optimizedMetric: OptimizationMetric
76
+
77
+ @property
78
+ def optimizedValue(self):
79
+ return self.totalMetrics.getMetric(self.optimizedMetric)
80
+
81
+ @property
82
+ def flatPath(self, toStr=True):
83
+ """Flatten the path into a list of hub IDs"""
84
+ if not self.path:
85
+ return []
86
+ # get all source hubs plus the final destination
87
+ path = [edge for edge in self.path]
88
+ if not toStr:
89
+ return path
90
+ pathStr = ""
91
+ for i, edge in enumerate(path):
92
+ if i == 0:
93
+ pathStr += f"Start: {edge[0]}"
94
+ continue
95
+
96
+ if len(edge) > 2 and isinstance(edge[2], EdgeMetadata):
97
+ pathStr += f"\n\tEdge: ({str(edge[2])})\n-> {edge[0]}"
98
+ else:
99
+ pathStr += f"{edge[0]} -> {edge[1]}"
100
+ return pathStr
101
+
102
+
103
+ @dataclass
104
+ class VerboseRoute(Route):
105
+ """Uses base Route class but adds additional info to hold the edge metadata for every leg"""
106
+ path: list[tuple[str, str, EdgeMetadata]]