multimodalrouter 0.1.2__py3-none-any.whl → 0.1.4__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 multimodalrouter might be problematic. Click here for more details.

@@ -1,4 +1,4 @@
1
- from .graph import RouteGraph, Hub, EdgeMetadata, OptimizationMetric, Route, VerboseRoute
1
+ from .graph import RouteGraph, Hub, EdgeMetadata, OptimizationMetric, Route, VerboseRoute, Filter
2
2
  from .utils import preprocessor
3
3
 
4
- __all__ = ["RouteGraph", "Hub", "EdgeMetadata", "OptimizationMetric", "Route", "VerboseRoute", "preprocessor"]
4
+ __all__ = ["RouteGraph", "Hub", "EdgeMetadata", "OptimizationMetric", "Route", "VerboseRoute", "preprocessor", "Filter"]
@@ -1,2 +1,2 @@
1
1
  from .graph import RouteGraph # noqa: F401
2
- from .dataclasses import Hub, EdgeMetadata, OptimizationMetric, Route, VerboseRoute # noqa: F401
2
+ from .dataclasses import Hub, EdgeMetadata, OptimizationMetric, Route, VerboseRoute, Filter # noqa: F401
@@ -5,6 +5,7 @@
5
5
 
6
6
  from dataclasses import dataclass
7
7
  from enum import Enum
8
+ from abc import abstractmethod, ABC
8
9
 
9
10
 
10
11
  class OptimizationMetric(Enum):
@@ -49,7 +50,7 @@ class Hub:
49
50
  self.coords: list[float] = coords
50
51
  self.id = id
51
52
  self.hubType = hubType
52
- self.outgoing = {}
53
+ self.outgoing: dict[str, dict[str, EdgeMetadata]] = {}
53
54
 
54
55
  def addOutgoing(self, mode: str, dest_id: str, metrics: EdgeMetadata):
55
56
  if mode not in self.outgoing:
@@ -104,3 +105,35 @@ class Route:
104
105
  class VerboseRoute(Route):
105
106
  """Uses base Route class but adds additional info to hold the edge metadata for every leg"""
106
107
  path: list[tuple[str, str, EdgeMetadata]]
108
+
109
+
110
+ class Filter(ABC):
111
+
112
+ @abstractmethod
113
+ def filterEdge(self, edge: EdgeMetadata) -> bool:
114
+ """
115
+ Return True if you want to keep the edge else False
116
+
117
+ Args:
118
+ edge (EdgeMetadata): Edge to filter
119
+
120
+ Returns:
121
+ bool: True if you want to keep the edge
122
+ """
123
+ pass
124
+
125
+ @abstractmethod
126
+ def filterHub(self, hub: Hub) -> bool:
127
+ """
128
+ Return True if you want to keep the hub else False
129
+
130
+ Args:
131
+ hub (Hub): Hub to filter
132
+
133
+ Returns:
134
+ bool: True if you want to keep the hub
135
+ """
136
+ pass
137
+
138
+ def filter(self, start: Hub, end: Hub, edge: EdgeMetadata) -> bool:
139
+ return self.filterHub(start) and self.filterHub(end) and self.filterEdge(edge)
@@ -9,8 +9,9 @@ import dill
9
9
  import heapq
10
10
  import os
11
11
  import pandas as pd
12
- from .dataclasses import Hub, EdgeMetadata, OptimizationMetric, Route
12
+ from .dataclasses import Hub, EdgeMetadata, OptimizationMetric, Route, Filter
13
13
  from threading import Lock
14
+ from collections import deque
14
15
 
15
16
 
16
17
  class RouteGraph:
@@ -371,10 +372,11 @@ class RouteGraph:
371
372
  self,
372
373
  start_id: str,
373
374
  end_id: str,
374
- allowed_modes: list[str],
375
+ allowed_modes: list[str] = None,
375
376
  optimization_metric: OptimizationMetric | str = OptimizationMetric.DISTANCE,
376
377
  max_segments: int = 10,
377
- verbose: bool = False
378
+ verbose: bool = False,
379
+ custom_filter: Filter = None,
378
380
  ) -> Route | None:
379
381
  """
380
382
  Find the optimal path between two hubs using Dijkstra
@@ -399,6 +401,9 @@ class RouteGraph:
399
401
  if end_hub is None:
400
402
  raise ValueError(f"End hub '{end_id}' not found in graph")
401
403
 
404
+ if allowed_modes is None:
405
+ allowed_modes = list(self.TransportModes.values())
406
+
402
407
  if start_id == end_id:
403
408
  # create a route with only the start hub
404
409
  # no verbose since no edges are needed
@@ -460,6 +465,15 @@ class RouteGraph:
460
465
  if connection_metrics is None: # skip if the connection has no metrics
461
466
  continue
462
467
 
468
+ try:
469
+ next_hub = self.getHubById(next_hub_id)
470
+ except KeyError:
471
+ raise ValueError(
472
+ f"Hub with ID '{next_hub_id}' not found in graph! But it is connected to hub '{current_hub_id}' via mode '{mode}'." # noqa: E501
473
+ )
474
+ if custom_filter is not None and not custom_filter.filter(current_hub, next_hub, connection_metrics):
475
+ continue
476
+
463
477
  # get the selected metric alue for this connection
464
478
  connection_value = connection_metrics.getMetric(optimization_metric)
465
479
  new_metric_value = current_metric_value + connection_value
@@ -488,6 +502,65 @@ class RouteGraph:
488
502
 
489
503
  return None
490
504
 
505
+ def radial_search(
506
+ self,
507
+ hub_id: str,
508
+ radius: float,
509
+ optimization_metric: OptimizationMetric | str = OptimizationMetric.DISTANCE,
510
+ allowed_modes: list[str] = None,
511
+ custom_filter: Filter = None,
512
+ ) -> list[float, Hub]:
513
+ """
514
+ Find all hubs within a given radius of a given hub
515
+ (Note: distance is measured from the connecting paths not direct)
516
+
517
+ Args:
518
+ hub_id: ID of the center hub
519
+ radius: maximum distance from the center hub
520
+ optimization_metric: metric to optimize for (e.g. distance, time, cost)
521
+ allowed_modes: list of allowed transport modes (default: None => all modes)
522
+
523
+ Returns:
524
+ list of tuples containing the metric value and the corresponding hub object
525
+ """
526
+
527
+ center = self.getHubById(hub_id)
528
+ if center is None:
529
+ return [center]
530
+
531
+ if allowed_modes is None:
532
+ allowed_modes = list(self.TransportModes.values())
533
+
534
+ hubsToSearch = deque([center])
535
+ queued = set([hub_id])
536
+ reachableHubs: dict[str, tuple[float, Hub]] = {hub_id: (0.0, center)}
537
+
538
+ while hubsToSearch:
539
+ hub = hubsToSearch.popleft() # get the current hub to search
540
+ currentMetricVal, _ = reachableHubs[hub.id] # get the current metric value
541
+ for mode in allowed_modes:
542
+ outgoing = hub.outgoing.get(mode, {}) # find all outgoing connections
543
+ # dict like {dest_id: EdgeMetadata}
544
+ for id, edgemetadata in outgoing.items(): # iter over outgoing connections
545
+ thisMetricVal = edgemetadata.getMetric(optimization_metric)
546
+ if thisMetricVal is None:
547
+ continue
548
+ nextMetricVal = currentMetricVal + thisMetricVal
549
+ if nextMetricVal > radius:
550
+ continue
551
+ knownMetric = reachableHubs.get(id, None)
552
+ destHub = self.getHubById(id)
553
+ if custom_filter is not None and not custom_filter.filter(hub, destHub, edgemetadata):
554
+ continue
555
+ # only save smaller metric values
556
+ if knownMetric is None or knownMetric[0] > nextMetricVal:
557
+ reachableHubs.update({id: (nextMetricVal, destHub)})
558
+ if id not in queued:
559
+ queued.add(id)
560
+ hubsToSearch.append(destHub)
561
+
562
+ return [v for v in reachableHubs.values()]
563
+
491
564
  def compare_routes(
492
565
  self,
493
566
  start_id: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multimodalrouter
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A graph-based routing library for dynamic routing.
5
5
  Author-email: Tobias Karusseit <karusseittobi@gmail.com>
6
6
  License: MIT License
@@ -14,6 +14,7 @@ License: MIT License
14
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
15
 
16
16
 
17
+ Project-URL: Homepage, https://github.com/K-T0BIAS/MultiModalRouter
17
18
  Project-URL: Repository, https://github.com/K-T0BIAS/MultiModalRouter
18
19
  Requires-Python: >=3.11
19
20
  Description-Content-Type: text/markdown
@@ -50,6 +51,8 @@ Dynamic: license-file
50
51
 
51
52
  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
52
53
 
54
+ > NEWS: v0.1.3 now on pypi ([installation guide](./docs/installation.md))
55
+
53
56
  > NOTE: This project is a work in progress and features might be added and or changed
54
57
 
55
58
  # In depth Documentation
@@ -0,0 +1,15 @@
1
+ multimodalrouter/__init__.py,sha256=Kva-wGkYdCi4GveSLe6emkTjd13C3K_ynhihADTQxZY,256
2
+ multimodalrouter/graph/__init__.py,sha256=zvKvSpZ8PbuOpG6DL14CJPV34ZLYderNJV4Amw1jsLI,150
3
+ multimodalrouter/graph/dataclasses.py,sha256=HC8oyaiM6IjgB4uAh9ybxCa8bNsasSQes_m8xgZLyXE,4407
4
+ multimodalrouter/graph/graph.py,sha256=k20ynHXPwVdZcjjp8a3dzCOuEHBPtEjnpauHtcvry9Y,23314
5
+ multimodalrouter/router/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ multimodalrouter/router/build.py,sha256=jrGcFyVS7-Qg6CXAVVwiXM_krLBHBoRH85Slknmutns,2843
7
+ multimodalrouter/router/route.py,sha256=5RZGFgrTYm930RJX6i26d8f8_k7CGnp5lKZJBM1gcKk,1956
8
+ multimodalrouter/utils/__init__.py,sha256=jsZ7cBB-9otxzMiN9FVviGuknxnOPmaG2RBbZuiezeg,53
9
+ multimodalrouter/utils/preprocessor.py,sha256=45ya0cg0PGCV3YMk680_HZUve1QGJ7JHPSHoRvYdleY,6333
10
+ multimodalrouter-0.1.4.dist-info/licenses/LICENSE.md,sha256=CRtvaQsLnzHvSIzusV5sHHw-e8w8gytXq8R7AP1GBmE,1092
11
+ multimodalrouter-0.1.4.dist-info/METADATA,sha256=LThCkDktNOaUhROpecvapLoXZxT8BZHvrhCTbsIA4LY,6048
12
+ multimodalrouter-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ multimodalrouter-0.1.4.dist-info/entry_points.txt,sha256=vp177Z2KMWPGJkS_dVpX05LVtBYssdlyYhTCG0kYmjo,138
14
+ multimodalrouter-0.1.4.dist-info/top_level.txt,sha256=4RYMG9hyl8mDNJ_gTrlh8QdYjZNXLDBzFVK1PcTpAYg,17
15
+ multimodalrouter-0.1.4.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- multimodalrouter/__init__.py,sha256=3O9ft058b5x09ORYD8Luw1qyEYoAx4kFPMjBs2HkfBM,238
2
- multimodalrouter/graph/__init__.py,sha256=FSIR6ZN-IM0r-NRcM81AiPn2FVe9fA8rkc9r2746Lr4,142
3
- multimodalrouter/graph/dataclasses.py,sha256=Bmcg3NFfFyPJS2sJO-IO0TnNCJ_pCG_n9lfJKVvFjxI,3535
4
- multimodalrouter/graph/graph.py,sha256=UPFcFIxhlJ1gfpHG8mPWAGiRjxVgEy_VTv16AneSjYM,19944
5
- multimodalrouter/router/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- multimodalrouter/router/build.py,sha256=jrGcFyVS7-Qg6CXAVVwiXM_krLBHBoRH85Slknmutns,2843
7
- multimodalrouter/router/route.py,sha256=5RZGFgrTYm930RJX6i26d8f8_k7CGnp5lKZJBM1gcKk,1956
8
- multimodalrouter/utils/__init__.py,sha256=jsZ7cBB-9otxzMiN9FVviGuknxnOPmaG2RBbZuiezeg,53
9
- multimodalrouter/utils/preprocessor.py,sha256=45ya0cg0PGCV3YMk680_HZUve1QGJ7JHPSHoRvYdleY,6333
10
- multimodalrouter-0.1.2.dist-info/licenses/LICENSE.md,sha256=CRtvaQsLnzHvSIzusV5sHHw-e8w8gytXq8R7AP1GBmE,1092
11
- multimodalrouter-0.1.2.dist-info/METADATA,sha256=T6HDVDe3CWNbqqFT9ZgjAgpzRS5pNZ2yo-Pzi13YITU,5902
12
- multimodalrouter-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- multimodalrouter-0.1.2.dist-info/entry_points.txt,sha256=vp177Z2KMWPGJkS_dVpX05LVtBYssdlyYhTCG0kYmjo,138
14
- multimodalrouter-0.1.2.dist-info/top_level.txt,sha256=4RYMG9hyl8mDNJ_gTrlh8QdYjZNXLDBzFVK1PcTpAYg,17
15
- multimodalrouter-0.1.2.dist-info/RECORD,,