Ant Colony Optimization
Implementation of the Ant Colony Optimization algorithm in Python
Currently works on 2D Cartesian coordinate system
Installation
From PyPi
pip install aco
Using Poetry
poetry add aco
Usage
AntColony(
nodes,
start=None,
ant_count=300,
alpha=0.5,
beta=1.2,
pheromone_evaporation_rate=0.40,
pheromone_constant=1000.0,
iterations=300,
)
Travelling Salesman Problem
import matplotlib.pyplot as plt
import random
from aco import AntColony
plt.style.use("dark_background")
COORDS = (
(20, 52),
(43, 50),
(20, 84),
(70, 65),
(29, 90),
(87, 83),
(73, 23),
)
def random_coord():
r = random.randint(0, len(COORDS))
return r
def plot_nodes(w=12, h=8):
for x, y in COORDS:
plt.plot(x, y, "g.", markersize=15)
plt.axis("off")
fig = plt.gcf()
fig.set_size_inches([w, h])
def plot_all_edges():
paths = ((a, b) for a in COORDS for b in COORDS)
for a, b in paths:
plt.plot((a[0], b[0]), (a[1], b[1]))
plot_nodes()
colony = AntColony(COORDS, ant_count=300, iterations=300)
optimal_nodes = colony.get_path()
for i in range(len(optimal_nodes) - 1):
plt.plot(
(optimal_nodes[i][0], optimal_nodes[i + 1][0]),
(optimal_nodes[i][1], optimal_nodes[i + 1][1]),
)
plt.show()
Reference
Metadata
Release files for aco 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aco-0.2.3.tar.gz | 3.6 kB | Without provenance | Details for aco-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aco-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for aco-0.2.3-py3-none-any.whl |
Total release size: 6.9 kB
Release files / aco-0.2.3.tar.gz
| Download URL | aco-0.2.3.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcb719872316ab68d0dc209f9eae6942938a19a5980d02ab00a422f097a97dbb
|
|
BLAKE2b-256 checksum How to use checksums |
46432ed08a77d0a71f9254fbc0f4010f4bdb016d858856f3c2cf177960bdf50e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.4 Linux/5.15.0-52-generic
|
Release files / aco-0.2.3-py3-none-any.whl
| Download URL | aco-0.2.3-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5a560cbb39dc7e9d719bce24fe727b67347ae290534d6bdce8e22545efffa45
|
|
BLAKE2b-256 checksum How to use checksums |
e62772b6120d52e3299b2610fc8e5b9ad12ef87e7ea5818d4299e8dc543ff7cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.4 Linux/5.15.0-52-generic
|
Security for aco 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.