modgeosys-graph-algorithms: Spatial Graph Algorithms
A repository for [hopefully] clean, readable, and easily-called implementations of some spatial navigation, path planning, and obstacle avoidance algorithms I will be using in the near future, written in modern Python and/or Rust with Python bindings. I'll be adding more algorithm implementations over time.
Algorithms: Currently implemented + planned
- A* - Graph path search algorithm.
- Code-complete in both Python and Rust.
- Needs a more thorough test suite.
- Needs Python bindings for Rust implementation.
- Prim's algorithm - Prim's Minimum Spanning Tree algorithm.
- Code-complete in Python.
- Tested on toy dataset in test suite.
- Tested on larger sample (pickled) dataset, not yet incorporated into test suite.
- Needs a Rust implementation and corresponding Python bindings.
Usage
A*
import pickle
from pprint import pprint
from modgeosys.graph.edge_weight import length_cost_per_unit
from modgeosys.graph.types import Graph, COMPUTED_WEIGHT
from modgeosys.graph.distance import manhattan_distance, euclidean_distance
from modgeosys.graph.a_star import a_star
# Define a toy graph.
toy_graph = Graph.from_edge_definitions(edge_definitions=((((0.0, 0.0), (0.0, 2.0)), COMPUTED_WEIGHT, {'cost_per_unit': 2}),
(((0.0, 0.0), (1.0, 0.0)), COMPUTED_WEIGHT, {'cost_per_unit': 1}),
(((1.0, 0.0), (2.0, 1.0)), COMPUTED_WEIGHT, {'cost_per_unit': 1}),
(((0.0, 2.0), (2.0, 3.0)), COMPUTED_WEIGHT, {'cost_per_unit': 3}),
(((2.0, 1.0), (2.0, 3.0)), COMPUTED_WEIGHT, {'cost_per_unit': 1})),
distance_function=manhattan_distance, edge_weight_function=length_cost_per_unit)
# Load a bigger graph from a pickle file.
with open('python/data/graph.pickle', 'rb') as pickled_sample_larger_graph_file:
larger_graph = pickle.load(pickled_sample_larger_graph_file)
larger_graph.distance_function = manhattan_distance
larger_graph.edge_weight_function = length_cost_per_unit
# Call the A* function.
toy_a_star_path = a_star(graph=toy_graph, start_node_index=0, goal_node_index=4)
print('Toy A* Path:')
pprint(toy_a_star_path)
print()
larger_a_star_path = a_star(graph=larger_graph, start_node_index=0, goal_node_index=4)
print('Large A* Path:')
pprint(larger_a_star_path)
Prim's algorithm
import pickle
from modgeosys.graph.edge_weight import length_cost_per_unit
from modgeosys.graph.types import Graph, COMPUTED_WEIGHT
from modgeosys.graph.distance import manhattan_distance, euclidean_distance
from modgeosys.graph.prim import prim
# Define a toy graph.
toy_graph = Graph.from_edge_definitions(edge_definitions=((((0.0, 0.0), (0.0, 2.0)), COMPUTED_WEIGHT, {'cost_per_unit': 2}),
(((0.0, 0.0), (1.0, 0.0)), COMPUTED_WEIGHT, {'cost_per_unit': 1}),
(((1.0, 0.0), (2.0, 1.0)), COMPUTED_WEIGHT, {'cost_per_unit': 1}),
(((0.0, 2.0), (2.0, 3.0)), COMPUTED_WEIGHT, {'cost_per_unit': 3}),
(((2.0, 1.0), (2.0, 3.0)), COMPUTED_WEIGHT, {'cost_per_unit': 1})),
distance_function=manhattan_distance, edge_weight_function=length_cost_per_unit)
# Load a bigger graph from a pickle file.
with open('python/data/graph.pickle', 'rb') as pickled_sample_larger_graph_file:
larger_graph = pickle.load(pickled_sample_larger_graph_file)
# Call the Prim function.
toy_minimum_spanning_tree = prim(graph=toy_graph, start_node_index=0)
print('Toy Prim Minimum Spanning Tree:')
print(toy_minimum_spanning_tree)
print()
larger_minimum_spanning_tree = prim(graph=larger_graph, start_node_index=0)
print('Prim Minimum Spanning Tree:')
print(larger_minimum_spanning_tree)
Metadata
Release files for modgeosys-graph-algorithms 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modgeosys_graph_algorithms-0.4.3.tar.gz | 12.3 kB | Without provenance | Details for modgeosys_graph_algorithms-0.4.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modgeosys_graph_algorithms-0.4.3-py3-none-any.whl | Python 3 | none | any | Details for modgeosys_graph_algorithms-0.4.3-py3-none-any.whl |
Total release size: 27.3 kB
Release files / modgeosys_graph_algorithms-0.4.3.tar.gz
| Download URL | modgeosys_graph_algorithms-0.4.3.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa19dbcb618020501a3c4cd744c1b87944d657942dc90ae49cb9853c492ee828
|
|
BLAKE2b-256 checksum How to use checksums |
21717e8c6c49d301294a4ef8dc24a561cf26fb645e3e9aa3d051a0f898052a24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.12 Linux/6.5.0-28-generic
|
Release files / modgeosys_graph_algorithms-0.4.3-py3-none-any.whl
| Download URL | modgeosys_graph_algorithms-0.4.3-py3-none-any.whl |
|---|---|
| Size | 15.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91d1c36e32748f8f12afe168e287a6414ac96dfb4162a92fd6259ed1f18a4faf
|
|
BLAKE2b-256 checksum How to use checksums |
e672c0c7d83edf6c9dcfbb8ad8d1dafda5013ec463d16922a22d0bcabf24fb76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.12 Linux/6.5.0-28-generic
|
Security for modgeosys-graph-algorithms 0.4.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.