Skip to main content

No project description provided

Project description

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.heuristic_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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modgeosys_graph_algorithms-0.3.9.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modgeosys_graph_algorithms-0.3.9-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file modgeosys_graph_algorithms-0.3.9.tar.gz.

File metadata

  • Download URL: modgeosys_graph_algorithms-0.3.9.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.5.0-28-generic

File hashes

Hashes for modgeosys_graph_algorithms-0.3.9.tar.gz
Algorithm Hash digest
SHA256 5f8d46b2dd967918c124311cbcb5cd0a2a942ef3ec383b60700cd94f437aca61
MD5 3266a9e1871c0b95cc6764b8637ae3ee
BLAKE2b-256 529c76db9fec8a0001b15db1b0fee2af37c5431d6307942df72613b0c4b50e4d

See more details on using hashes here.

File details

Details for the file modgeosys_graph_algorithms-0.3.9-py3-none-any.whl.

File metadata

File hashes

Hashes for modgeosys_graph_algorithms-0.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 60a9ff14f7c9e3c1c5f6b1f7bec520ea88d52ba1cfae6e1399ab5862a995b528
MD5 7631c27a6b7c9715e57bbb619d798488
BLAKE2b-256 3d56063a3526c59d6c8b0ce4971aa166c46af3e2f8a8409962a76541e396ac91

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page