Skip to main content

Simple graph algorithms: Kruskal, Prim and Hamiltonian cycle

Project description

# graph-algo-nd

Лёгкая библиотека с реализациями алгоритмов работы с графами:
- MST: Kruskal и Prim
- Hamiltonian cycle: поиск одного гамильтонова цикла (бэктрекинг, только для маленьких графов)

Установка (локально, для разработки)
1. Создайте виртуальное окружение
   - python -m venv venv
   - source venv/bin/activate  (Linux/macOS) или venv\Scripts\activate (Windows)
2. Установите зависимости:
   - pip install -U pip build twine
   - pip install networkx matplotlib
3. Установите пакет в editable режиме (для разработки):
   - pip install -e .

Примеры использования
```python
from graph_algorithms import kruskal_mst, prim_mst, find_hamiltonian_cycle

# MST: список рёбер (u, v, weight), вершины предполагаются 0..n-1
edges = [(0,1,1.5), (0,2,1.0), (1,3,2.0), (2,3,1.0)]
n = 4

mst_edges_k, weight_k = kruskal_mst(n, edges)
mst_edges_p, weight_p = prim_mst(n, edges)
print("Kruskal weight:", weight_k)
print("Prim weight:", weight_p)

# Hamiltonian (не взвешенный граф): adjacency dict {v: [neighs]}
adj = {
    0: [1,2],
    1: [0,2,3],
    2: [0,1,3],
    3: [1,2]
}
cycle = find_hamiltonian_cycle(adj)
print("Hamiltonian cycle:", cycle)

Запуск тестов

  1. Установите pytest и networkx (если ещё не установлены):
    • pip install pytest networkx
  2. Запустите:
    • pytest -q

Сборка и публикация (Test PyPI, затем PyPI)

  1. Установите инструменты сборки:
    • pip install build twine
  2. Соберите дистрибутивы:
    • python -m build
  3. Загрузите на Test PyPI (рекомендуется сначала протестировать там):
    • twine upload --repository testpypi dist/* (Потребуется аккаунт/testpypi token)
  4. Установите из Test PyPI для проверки:
  5. После проверки публикуйте на PyPI:
    • twine upload dist/*

Структура репозитория (основное)

  • graph_algorithms/
    • mst/kruskal.py
    • mst/prim.py
    • hamilton/hamiltonian.py
    • init.py
  • tests/
    • test_mst.py
    • test_hamilton.py
  • examples/usage.py
  • pyproject.toml, setup.cfg, MANIFEST.in, LICENSE, README.md
  • .github/workflows/ci.yml

Лицензия: MIT

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

graph_algo_nd-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

graph_algo_nd-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file graph_algo_nd-0.1.0.tar.gz.

File metadata

  • Download URL: graph_algo_nd-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for graph_algo_nd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9773f72f2fe4a14d131e459084f88eceafc831a7e309a66f8f7221a1a8854aa3
MD5 3d9d59aeb8ac1edeca1ba04ce8fc88ea
BLAKE2b-256 e7e37e89900629e4ee8fe207dd16db601f0906b03ced5729071e42bfd4c43522

See more details on using hashes here.

File details

Details for the file graph_algo_nd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: graph_algo_nd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for graph_algo_nd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d63a23c3038b27e6068da67d550e8b5d100c36cc1bc8e945d88d7e802fee3d8
MD5 f3d8c6bac25d2655ededfda1f85e5fcf
BLAKE2b-256 bbf5c8503eaecc991d05b56f24f75ac4ab5fb67089ba878a02238dfa33aa69c9

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