Skip to main content

Ant Colony Optimization

Develop Deploy PyPi version Downloads

A Python package to find the shortest path in a graph using Ant Colony Optimization (ACO).

➡️ Check out my Medium article for a detailed walkthrough 🚀

The Ant colony Optimization algorithm is a probabilistic technique for solving computational problems which can be reduced to finding good paths through graphs (source).

This implementation of the ACO algorithm uses the NetworkX graph environment.

🏁 Getting Started

To install the package directly from PyPi:

$ pip install aco_routing

🎈 Usage

Check out: example.py

Import all the dependencies:

from aco_routing import ACO
import networkx as nx

Create a NetworkX.Graph object with nodes and edges:

G = nx.DiGraph()

G.add_edge("A", "B", cost=2)
G.add_edge("B", "C", cost=2)
G.add_edge("A", "H", cost=2)
G.add_edge("H", "G", cost=2)
G.add_edge("C", "F", cost=1)
G.add_edge("F", "G", cost=1)
G.add_edge("G", "F", cost=1)
G.add_edge("F", "C", cost=1)
G.add_edge("C", "D", cost=10)
G.add_edge("E", "D", cost=2)
G.add_edge("G", "E", cost=2)

Use ACO to find the shortest path and cost between the source and destination:

aco = ACO(G, ant_max_steps=100, num_iterations=100, ant_random_spawn=True)

aco_path, aco_cost = aco.find_shortest_path(
    source="A",
    destination="D",
    num_ants=100,
)

Output:

ACO path: A -> H -> G -> E -> D
ACO path cost: 8.0

📦 Contents

Ant

aco_routing.Ant

  • An Ant that traverses the graph.

ACO

aco_routing.ACO

  • The traditional Ant Colony Optimization algorithm that spawns ants at various nodes in the graph and finds the shortest path between the specified source and destination (pseudo code).

Contributing

  • Post any issues and suggestions on the GitHub issues page.
  • To contribute, fork the project and then create a pull request back to master.

Metadata

Release files for aco-routing 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aco-routing 1.2.1
File Size Uploaded
aco_routing-1.2.1.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aco-routing 1.2.1
File Interpreter ABI Platform
aco_routing-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / aco_routing-1.2.1.tar.gz

Download URL aco_routing-1.2.1.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8df6d9da02cd293b35da53142f8f32b58e816a9d76b16bc67d03ab888e6e4e0b
BLAKE2b-256 checksum
How to use checksums
e84926a49b40d42726e379658227967b4b327337a5ea72a67ba1004403e12c98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / aco_routing-1.2.1-py3-none-any.whl

Download URL aco_routing-1.2.1-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99183787d0a6413bbbdab4886594007a26bc24c948b6181c391648a5e8f06466
BLAKE2b-256 checksum
How to use checksums
359ef2883d9b32e981e1b2360763bbd048e59bc839de7f7144ad73a4caf07545
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page