scgraph 2.1.0__tar.gz → 2.1.2__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.
- {scgraph-2.1.0/scgraph.egg-info → scgraph-2.1.2}/PKG-INFO +1 -1
- {scgraph-2.1.0 → scgraph-2.1.2}/pyproject.toml +2 -2
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/core.py +23 -24
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/utils.py +6 -6
- {scgraph-2.1.0 → scgraph-2.1.2/scgraph.egg-info}/PKG-INFO +1 -1
- {scgraph-2.1.0 → scgraph-2.1.2}/setup.cfg +1 -1
- {scgraph-2.1.0 → scgraph-2.1.2}/LICENSE +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/README.md +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/__init__.py +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/geographs/__init__.py +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/geographs/marnet.py +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/geographs/north_america_rail.py +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/geographs/oak_ridge_maritime.py +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph/geographs/us_freeway.py +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph.egg-info/SOURCES.txt +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph.egg-info/dependency_links.txt +0 -0
- {scgraph-2.1.0 → scgraph-2.1.2}/scgraph.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.black]
|
|
2
2
|
line-length = 80
|
|
3
|
-
target-version = ['
|
|
3
|
+
target-version = ['py312']
|
|
4
4
|
exclude = '/.*(migrations|__pycache__|geographs).*/'
|
|
5
5
|
|
|
6
6
|
[tool.setuptools]
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "scgraph"
|
|
15
|
-
version = "2.1.
|
|
15
|
+
version = "2.1.2"
|
|
16
16
|
description = "Determine an approximate route between two points on earth."
|
|
17
17
|
authors = [
|
|
18
18
|
{name="Connor Makowski", email="conmak@mit.edu"}
|
|
@@ -298,7 +298,7 @@ class Graph:
|
|
|
298
298
|
|
|
299
299
|
class GeoGraph:
|
|
300
300
|
def __init__(
|
|
301
|
-
self, graph: list[dict], nodes: list[list[int
|
|
301
|
+
self, graph: list[dict], nodes: list[list[int, float]]
|
|
302
302
|
) -> None:
|
|
303
303
|
"""
|
|
304
304
|
Function:
|
|
@@ -397,17 +397,17 @@ class GeoGraph:
|
|
|
397
397
|
|
|
398
398
|
def get_shortest_path(
|
|
399
399
|
self,
|
|
400
|
-
origin_node: dict[int
|
|
401
|
-
destination_node: dict[int
|
|
400
|
+
origin_node: dict[int, float],
|
|
401
|
+
destination_node: dict[int, float],
|
|
402
402
|
output_units: str = "km",
|
|
403
403
|
algorithm_fn=Graph.dijkstra_makowski,
|
|
404
|
-
off_graph_circuity: float
|
|
404
|
+
off_graph_circuity: [int, float] = 1,
|
|
405
405
|
node_addition_type: str = "quadrant",
|
|
406
|
-
node_addition_circuity: float
|
|
406
|
+
node_addition_circuity: [int, float] = 4,
|
|
407
407
|
geograph_units: str = "km",
|
|
408
408
|
output_coordinate_path: str = "list_of_lists",
|
|
409
409
|
output_path: bool = False,
|
|
410
|
-
node_addition_lat_lon_bound: float
|
|
410
|
+
node_addition_lat_lon_bound: [int, float] = 5,
|
|
411
411
|
node_addition_math: str = "euclidean",
|
|
412
412
|
**kwargs,
|
|
413
413
|
) -> dict:
|
|
@@ -453,7 +453,7 @@ class GeoGraph:
|
|
|
453
453
|
- `origin`: The id of the origin node from the graph dictionary to start the shortest path from
|
|
454
454
|
- `destination`: The id of the destination node from the graph dictionary to end the shortest path at
|
|
455
455
|
- `off_graph_circuity`
|
|
456
|
-
- Type:
|
|
456
|
+
- Type: int | float
|
|
457
457
|
- What: The circuity factor to apply to any distance calculations between your origin and destination nodes and their connecting nodes in the graph
|
|
458
458
|
- Default: 1
|
|
459
459
|
- Notes:
|
|
@@ -476,7 +476,7 @@ class GeoGraph:
|
|
|
476
476
|
- If the passed graph is not a connected graph (meaning it is comprised of multiple disconnected networks)
|
|
477
477
|
- The entrypoints generated using the `node_addition_type` will determine which disconnected networks will be used to calculate the `optimal route`
|
|
478
478
|
- `node_addition_circuity`
|
|
479
|
-
- Type:
|
|
479
|
+
- Type: int | float
|
|
480
480
|
- What: The circuity factor to apply when adding your origin and destination nodes to the distance matrix
|
|
481
481
|
- Default: 4
|
|
482
482
|
- Note:
|
|
@@ -507,7 +507,7 @@ class GeoGraph:
|
|
|
507
507
|
- What: Whether to output the path as a list of geograph node ids (for debugging and other advanced uses)
|
|
508
508
|
- Default: False
|
|
509
509
|
- `node_addition_lat_lon_bound`
|
|
510
|
-
- Type:
|
|
510
|
+
- Type: int | float
|
|
511
511
|
- What: Forms a bounding box around the origin and destination nodes as they are added to graph
|
|
512
512
|
- Only points on the current graph inside of this bounding box are considered when updating the distance matrix for the origin or destination nodes
|
|
513
513
|
- Default: 5
|
|
@@ -596,10 +596,10 @@ class GeoGraph:
|
|
|
596
596
|
- Type: dict
|
|
597
597
|
- What: The output from the algorithm function
|
|
598
598
|
- `node_addition_circuity`
|
|
599
|
-
- Type:
|
|
599
|
+
- Type: int | float
|
|
600
600
|
- What: The circuity factor that was applied when adding your origin and destination nodes to the distance matrix
|
|
601
601
|
- `off_graph_circuity`
|
|
602
|
-
- Type:
|
|
602
|
+
- Type: int | float
|
|
603
603
|
- What: The circuity factor to apply to any distance calculations between your origin and destination nodes and their connecting nodes in the graph
|
|
604
604
|
"""
|
|
605
605
|
coordinate_path = output["coordinate_path"]
|
|
@@ -619,7 +619,7 @@ class GeoGraph:
|
|
|
619
619
|
4,
|
|
620
620
|
)
|
|
621
621
|
|
|
622
|
-
def get_coordinate_path(self, path: list[int]) -> list[dict[int
|
|
622
|
+
def get_coordinate_path(self, path: list[int]) -> list[dict[int, float]]:
|
|
623
623
|
"""
|
|
624
624
|
Function:
|
|
625
625
|
|
|
@@ -663,11 +663,11 @@ class GeoGraph:
|
|
|
663
663
|
def get_node_distances(
|
|
664
664
|
self,
|
|
665
665
|
node: list,
|
|
666
|
-
circuity: int
|
|
666
|
+
circuity: [int, float],
|
|
667
667
|
node_addition_type: str,
|
|
668
668
|
node_addition_math: str,
|
|
669
|
-
lat_lon_bound: int
|
|
670
|
-
) -> dict[int
|
|
669
|
+
lat_lon_bound: [int, float],
|
|
670
|
+
) -> dict[int, float]:
|
|
671
671
|
"""
|
|
672
672
|
Function:
|
|
673
673
|
|
|
@@ -681,7 +681,7 @@ class GeoGraph:
|
|
|
681
681
|
- What: A list of the latitude and longitude of the node
|
|
682
682
|
- EG: [latitude, longitude] -> [31.23, 121.47]
|
|
683
683
|
- `circuity`
|
|
684
|
-
- Type:
|
|
684
|
+
- Type: int | float
|
|
685
685
|
- What: The circuity to apply to any distance calculations
|
|
686
686
|
- Note: This defaults to 4 to prevent the algorithm from taking a direct route in direction of the destination over some impassible terrain (EG: a maritime network that goes through land)
|
|
687
687
|
- `node_addition_type`
|
|
@@ -705,7 +705,7 @@ class GeoGraph:
|
|
|
705
705
|
- Notes:
|
|
706
706
|
- Once the closest node (or closest quadrant node) is determined, the haversine distance (with circuity) is used to calculate the distance between the nodes when adding it to the graph.
|
|
707
707
|
- `lat_lon_bound`
|
|
708
|
-
- Type:
|
|
708
|
+
- Type: int | float
|
|
709
709
|
- What: Forms a bounding box around the node that is to be added to graph. Only selects graph nodes to consider joining that are within this bounding box.
|
|
710
710
|
"""
|
|
711
711
|
assert node_addition_type in [
|
|
@@ -727,7 +727,7 @@ class GeoGraph:
|
|
|
727
727
|
if len(nodes) == 0:
|
|
728
728
|
# Default to all if the lat_lon_bound fails to find any nodes
|
|
729
729
|
return self.get_node_distances(
|
|
730
|
-
node=
|
|
730
|
+
node=node,
|
|
731
731
|
circuity=circuity,
|
|
732
732
|
lat_lon_bound=180,
|
|
733
733
|
node_addition_type=node_addition_type,
|
|
@@ -767,11 +767,11 @@ class GeoGraph:
|
|
|
767
767
|
|
|
768
768
|
def add_node(
|
|
769
769
|
self,
|
|
770
|
-
node: dict[int
|
|
771
|
-
circuity: int
|
|
770
|
+
node: dict[int, float],
|
|
771
|
+
circuity: [int, float],
|
|
772
772
|
node_addition_type: str = "quadrant",
|
|
773
773
|
node_addition_math: str = "euclidean",
|
|
774
|
-
lat_lon_bound: int
|
|
774
|
+
lat_lon_bound: [int, float] = 5,
|
|
775
775
|
) -> int:
|
|
776
776
|
"""
|
|
777
777
|
Function:
|
|
@@ -788,7 +788,7 @@ class GeoGraph:
|
|
|
788
788
|
Optional Arguments:
|
|
789
789
|
|
|
790
790
|
- `circuity`
|
|
791
|
-
- Type:
|
|
791
|
+
- Type: int | float
|
|
792
792
|
- What: The circuity to apply to any distance calculations
|
|
793
793
|
- Default: 4
|
|
794
794
|
- Note: This defaults to 4 to prevent the algorithm from taking a direct route in direction of the destination over some impassible terrain (EG: a maritime network that goes through land)
|
|
@@ -814,7 +814,7 @@ class GeoGraph:
|
|
|
814
814
|
- Notes:
|
|
815
815
|
- Once the closest node (or closest quadrant node) is determined, the haversine distance (with circuity) is used to calculate the distance between the nodes when adding it to the graph.
|
|
816
816
|
- `lat_lon_bound`
|
|
817
|
-
- Type:
|
|
817
|
+
- Type: int | float
|
|
818
818
|
- What: Forms a bounding box around the node that is to be added to graph. Only selects graph nodes to consider joining that are within this bounding box.
|
|
819
819
|
- Default: 5
|
|
820
820
|
|
|
@@ -843,7 +843,6 @@ class GeoGraph:
|
|
|
843
843
|
lat_lon_bound, (int, float)
|
|
844
844
|
), "Lat_lon_bound must be a number"
|
|
845
845
|
assert lat_lon_bound > 0, "Lat_lon_bound must be greater than 0"
|
|
846
|
-
|
|
847
846
|
node = [node["latitude"], node["longitude"]]
|
|
848
847
|
# Get the distances to all other nodes
|
|
849
848
|
distances = self.get_node_distances(
|
|
@@ -5,7 +5,7 @@ def haversine(
|
|
|
5
5
|
origin: list[float, int],
|
|
6
6
|
destination: list[float, int],
|
|
7
7
|
units: str = "km",
|
|
8
|
-
circuity: int
|
|
8
|
+
circuity: [int, float] = 1,
|
|
9
9
|
):
|
|
10
10
|
"""
|
|
11
11
|
Function:
|
|
@@ -28,7 +28,7 @@ def haversine(
|
|
|
28
28
|
- What: units to return the distance in? (one of "km", "m", "mi", or "ft")
|
|
29
29
|
- Default: "km"
|
|
30
30
|
- `circuity`:
|
|
31
|
-
- Type:
|
|
31
|
+
- Type: int | float
|
|
32
32
|
- What: Multiplier to increase the calculated distance (to account for circuity)
|
|
33
33
|
- Default: 1
|
|
34
34
|
|
|
@@ -69,7 +69,7 @@ def haversine(
|
|
|
69
69
|
raise Exception()
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def hard_round(decimal_places: int, a: int
|
|
72
|
+
def hard_round(decimal_places: int, a: [int, float]):
|
|
73
73
|
"""
|
|
74
74
|
Function:
|
|
75
75
|
|
|
@@ -81,7 +81,7 @@ def hard_round(decimal_places: int, a: int | float):
|
|
|
81
81
|
- Type: int
|
|
82
82
|
- What: number of decimal places to round to
|
|
83
83
|
- `a`:
|
|
84
|
-
- Type:
|
|
84
|
+
- Type: int | float
|
|
85
85
|
- What: number to round
|
|
86
86
|
"""
|
|
87
87
|
return int(a * (10**decimal_places) + (0.5 if a > 0 else -0.5)) / (
|
|
@@ -90,7 +90,7 @@ def hard_round(decimal_places: int, a: int | float):
|
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
def distance_converter(
|
|
93
|
-
distance: int
|
|
93
|
+
distance: [int, float], input_units: str, output_units: str
|
|
94
94
|
):
|
|
95
95
|
"""
|
|
96
96
|
Function:
|
|
@@ -115,7 +115,7 @@ def distance_converter(
|
|
|
115
115
|
return (distance / km_table[input_units]) * km_table[output_units]
|
|
116
116
|
|
|
117
117
|
|
|
118
|
-
def get_line_path(output: list
|
|
118
|
+
def get_line_path(output: [list, dict], filename=None):
|
|
119
119
|
"""
|
|
120
120
|
Function:
|
|
121
121
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|