Metadata-Version: 2.4
Name: aco_routing
Version: 1.2.1
Summary: A Python package to find the shortest path in a graph using Ant Colony Optimization (ACO)
Home-page: https://github.com/hasnainroopawalla/ant-colony-optimization
Author: Hasnain Roopawalla
Author-email: hasnain.roopawalla@gmail.com
License: MIT
Keywords: python,machinelearning,ai,aco
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-python
Dynamic: summary

Ant Colony Optimization

[![Develop](https://github.com/hasnainroopawalla/Ant-Colony-Optimization/actions/workflows/develop.yml/badge.svg)](https://github.com/hasnainroopawalla/Ant-Colony-Optimization/actions/workflows/develop.yml)
[![Deploy](https://github.com/hasnainroopawalla/Ant-Colony-Optimization/actions/workflows/deploy.yml/badge.svg)](https://github.com/hasnainroopawalla/Ant-Colony-Optimization/actions/workflows/deploy.yml)
[![PyPi version](https://img.shields.io/pypi/v/aco_routing.svg)](https://pypi.python.org/pypi/aco_routing/)
![Downloads](https://img.shields.io/pypi/dm/aco_routing.svg)

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

➡️ Check out my [Medium article](https://medium.com/@hasnain.roopawalla/ant-colony-optimization-1bbc346c2da5) 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](https://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms)).

This implementation of the ACO algorithm uses the [NetworkX](https://networkx.org/) graph environment.

## 🏁 Getting Started 

### To install the package directly from PyPi:

```
$ pip install aco_routing
```

## 🎈 Usage 

> Check out: [example.py](https://github.com/hasnainroopawalla/ant-colony-optimization/blob/master/example.py)

Import all the dependencies:

```python
from aco_routing import ACO
import networkx as nx
```

Create a `NetworkX.Graph` object with nodes and edges:

```python
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`:

```python
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](https://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms#Algorithm_and_formula)).

## Contributing

- Post any issues and suggestions on the GitHub [issues](https://github.com/hasnainroopawalla/Ant-Colony-Optimization/issues) page.
- To contribute, fork the project and then create a pull request back to master.
