Skip to main content

No project description provided

Project description

modgeosys-graph-algorithms: Graph Algorithms

A repository for [hopefully] clean, readable, and easily-called implementations of some 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.
  • Prim's algorithm - Prim's Minimum Spanning Tree algorithm.
    • Planned.

Usage

A* (Python)

from modgeosys.graph.a_star import a_star
from modgeosys.graph.types import Node, Edge, Graph
from modgeosys.graph.distance import manhattan_distance, euclidean_distance

# Define a graph.
nodes = [Node(coordinates=(0.0, 0.0)),
         Node(coordinates=(0.0, 2.0)),
         Node(coordinates=(1.0, 0.0)),
         Node(coordinates=(2.0, 1.0)),
         Node(coordinates=(2.0, 3.0))]
edges = (Edge(weight=2.0, node_indices=frozenset((0, 1))),
         Edge(weight=1.0, node_indices=frozenset((0, 2))),
         Edge(weight=1.0, node_indices=frozenset((2, 3))),
         Edge(weight=3.0, node_indices=frozenset((1, 4))),
         Edge(weight=1.0, node_indices=frozenset((3, 4))))
graph = Graph(nodes=nodes, edges=edges)

# Call the A* function.
path = a_star(graph=graph, start_node_index=0, goal_node_index=4, heuristic_distance=manhattan_distance)

# Report the resulting path.
print(path)

A* (Rust)

use std::collections::HashSet;

use modgeosys_graph::a_star::a_star;
use modgeosys_graph::types::{Node, Edge, Graph};
use modgeosys_graph::distance::manhattan_distance;

fn main()
{
  // Define a graph.
  let nodes = vec![Node::new(vec![0.0, 0.0]),
                   Node::new(vec![0.0, 2.0]),
                   Node::new(vec![1.0, 0.0]),
                   Node::new(vec![2.0, 1.0]),
                   Node::new(vec![2.0, 3.0])];
  let edges = vec![Edge::new(2.0, HashSet::from([0, 1])),
                   Edge::new(1.0, HashSet::from([0, 2])),
                   Edge::new(1.0, HashSet::from([2, 3])),
                   Edge::new(3.0, HashSet::from([1, 4])),
                   Edge::new(1.0, HashSet::from([3, 4]))];
  let graph = Graph::new(nodes, edges);

  // Call the A* function.
  let path = a_star(&graph, 0, 4, manhattan_distance).unwrap();

  // Report the resulting path.
  println!("{:?}", path);
}

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.1.2.tar.gz (7.5 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.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for modgeosys_graph_algorithms-0.1.2.tar.gz
Algorithm Hash digest
SHA256 babcffc0c7a34d82c18b7d21ee0082cdeb7eb52d7638febeb12fe3b8753d370e
MD5 efa3730ea250a341dd78b61e2e58f08c
BLAKE2b-256 92dfa53cfe8d4d0c6511e4c9249e964985e99ca592cce59fc73adf5e605914a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for modgeosys_graph_algorithms-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cd0e04d18c226dc5f46955347d74869f0301d1d1cbf54f9183b928e6568a0794
MD5 774c92df2d9f8e8769830dea416c623a
BLAKE2b-256 ff926685e88b4eb1ae16b2ff4a8fa8b5a0d91daac408f0c86ce7061fad4026bd

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