Download the PHP package mgrechanik/ant-colony-optimization without Composer

On this page you can find all versions of the php package mgrechanik/ant-colony-optimization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ant-colony-optimization

Ant colony optimization

Русская версия

Table of contents


Introdution

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

The task we are solving could be either "Shortest path problem", or Constrained Shortest Path First, etc.
The two first tasks are solved within this library.

There are a lot of strategies and variations of Classic ACO algorithm.
This library out of the box implements Classic ACO and ACO with elitist ants.

The library could be easily extended so you can implement your ACO variations and to solve the tasks you need.

The initial data about the graph comes either from adjacency matrix or from a list of nodes (cities, vertices, etc) with their X and Y coordinates.

The work of library had been tested with performance and efficiency.

Amount of ants, all coefficients and parameters could be changed to your need.

Now we have a web app which you can install and run locally to practice with this algorithm. Look for it's video demo for details.


Demo

Solving the travelling salesman problem with the ant colony optimization algorithm: Using this ACO library to solve the travelling salesman problem

Another example: Using this ACO library to find the path for travelling salesman on the USA map image


Installing

Installing through composer::

The preferred way to install this library is through composer.

Either run

or add

to the require section of your composer.json.


How to use

Basic API

1) Creating a Manager with the dependencies we need

      - By default Finder will be Classic one, and the Task will be the Travelling salesman problem

2) Loading data from an adjacency matrix

      - - from which number start naming aliases of nodes

3) Loading data from an array of cities

      - This array of cities will be transformed to adjacency matrix. Distances will be calculated according to the strategy we set to a Manager.
      - If city has a property it will become it's name alias

4) Changing of the adjacency matrix

      - For example we could make some path impassable -

5) Run the computational process

      - for small graphs we could reduce amount of iterations.
      - It will return the distance we found or when the search gave no result

6) Getting the path we found

      - The path we found who consists of node's numbers.
      All nodes are internally named as numbers from 0 to N-1, where N is node's amount.

7) Getting aliased path we found

      - The path we found which consists of node's name aliases, if we set them.

Examples

Solving "Travelling salesman problem" with Classic ACO

We will get:

Solving "Shortest path problem" with Classic ACO

We will get:

Loading data as an array of cities

Loading data as an adjacency matrix

Using the Elitist Finder

Have a look at the history of our work - best solutions we had been finding

Loading a list of cities from an image file

With the use of this library we can load a list of cities from the image. And the result of the search could be displayed on the image too. It will look like images on Demo.

Read docs of that library for more information how to prepare images but briefly it is this: On white canvas draw points of 10 px diameter (they are vertices of the graph) and use this image with the code below


Settings

Finder settings

The base object we tune is the Finder.
Lets get it:

Settings available:


Performance

First of all turn off XDebug or it's analogies, since they could significantly affect the time the algorithm works

This ACO algorithm finds good paths on a graph. And sometimes even best paths.

Lets take, for example, the task from TSPLIB95 library, which has 52 nodes.
Solving this task with the next code:

We will see:

This code, working on an office computer, found the best path ever known for less than 2 seconds.

We used here Elitist ACO algorithm since in practice it gives better results than Classic one.

An Algorithm is probabilistic, ants travel differently each new search. A lot depends upon amount of nodes, amount of ants, all coefficients and parameters used with formulas.


TSPLIB95

The TSPLIB95 library ships with a lot of - initial data and solutions - best results ever found for these tasks (distances).

The library is valuable that with it's data we could test the efficiency of our algorithms, coefficients and parameters.

The library consists of a lot of different initial data formats. Out of the box we support two of them.

Loading data as a set of X and Y coordinates of cities. Distance is euclidean.

Example of the file with this format - berlin52.tsp .
Loading the list of nodes (cities) and transfer it to Manager:

Loading data as an adjacency matrix

Example of the file with this format - bays29.tsp .
Loading the adjacency matrix and transfer it to Manager:


Terminology

- Ant colony optimization algorithm

- Nodes or vertices or cities. Ants travel between them.

- Adjacency Matrix sets the distances between graph nodes. It is a basic structure our algorithm starts work with.

When graph is loaded like with their coordinates, this information will be converted to Adjacency Matrix

- Finder who implements Classic ACO algorithm

- Finder who implements ACO algorithm when we use elitist ants

- ant, working unit, who move through the graph searching for the paths

- The task we are solving on the graph. For example it could be or . Or other.

- Travelling salesman problem. With this library we can solve both symmetric and asymmetric types of tsp

- The manager which task is to form adjacency matrix , give it to to solve .

- The iteration during which all ants find one path and put pheromones on it. We set amount of iterations themselves.

- is the instance ants leave on paths

- Amount of ants

- Amount of ants in percents relatively to the amount of nodes

- Amount of elitist ants, if we use corresponding algorithm

- Amount of elitist ants in percents relatively to the amount of regular ants

- The coefficient to control the influence of pheromone amount

- The coefficient to control the influence of desirability of path

- The evaporation coefficient

- The starting amount of pheromones on paths

- The constant used to calculate how many pheromones an ant puts on the path it found


All versions of ant-colony-optimization with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mgrechanik/ant-colony-optimization contains the following files

Loading the files please wait ....