Giter Club home page Giter Club logo

isula's Introduction

isula

example workflow packagecloud Quality Gate Status

Isula

About

Ant Colony Optimisation (ACO) is an algorithmic framework for solving combinatorial optimisation problems. Algorithms in the framework imitate the foraging behaviour of ants. Ants in the wild traverse a terrain looking for food, while depositing pheromones over the path they take. Pheromone is a chemical substance attractive to ants. Efficient ants find shorter paths, making more trips from the food source to the colony than fellow ants on longer routes. This produces an accumulation of pheromone over short paths, getting the attention of the rest the colony. Over time, the whole colony converges towards the shortest path found.

In a similar fashion, artificial ants in ACO algorithms traverse the solution space of an optimisation problem, depositing pheromone over the components of the solution they built. The amount of pheromone is proportional to the quality of their solution, so pheromone accumulates in the most valuable solution components. Over time, ants in the artificial colony converge to high-quality solutions for a given optimisation problem. Isula allows an easy implementation of Ant-Colony Optimisation algorithms using the Java Programming Language. It contains the common elements present in the meta-heuristic, to allow algorithm designers the reutilization of behaviors. With Isula, solving optimisation problems with Ant Colony can be done in few lines of code.

Usage

Setup

The code uploaded to this GitHub Repository corresponds to a Maven Java Project. As such, it is strongly recommended that you have Maven installed before working with Isula.

You can use Isula as a dependency on your own Ant Colony Optimization project, by adding the following to your pom.xml file:

<repositories>
    <repository>
        <id>isula</id>
        <url>https://packagecloud.io/cgavidia/isula/maven2
        </url>
    </repository>
</repositories>
<dependencies>
<dependency>
    <groupId>isula</groupId>
    <artifactId>isula</artifactId>
    <version>2.1.6</version>
</dependency>
</dependencies>

Algorithm Configuration

To solve a problem with an Ant-Colony Optimization algorithm, you need a colony of agents (a.k.a. ants), a graph representing the problem, and a pheromone data-structure to allow communication between these agents. Isula tries to emulate that pattern:

TspProblemConfiguration configurationProvider=new TspProblemConfiguration(problemRepresentation);
        AntColony<Integer, TspEnvironment> colony=getAntColony(configurationProvider);
        TspEnvironment environment=new TspEnvironment(problemRepresentation);

        AcoProblemSolver<Integer, TspEnvironment> solver=new AcoProblemSolver<>();
        solver.initialize(environment,colony,configurationProvider);
        solver.addDaemonActions(new StartPheromoneMatrix<Integer, TspEnvironment>(),
        new PerformEvaporation<Integer, TspEnvironment>());

        solver.addDaemonActions(getPheromoneUpdatePolicy());

        solver.getAntColony().addAntPolicies(new RandomNodeSelection<Integer, TspEnvironment>());
        solver.solveProblem();

That's a snippet from our Travelling Salesman Problem solution. Some things to notice there:

  • Problem and algorithm configuration are provided by ConfigurationProvider instances. Make your own with the values you need.
  • The class that does most of the job is AcoProblemSolver. In this case, we're using the same one provided by the framework but you can extend it to suit your needs.
  • The ProblemSolver needs an Environment that manages the problem graph and the pheromone matrix. You need to extend the Environment class provided by the framework to adjust it to your problem.
  • And we need an AntColony. The AntColony main responsibility is to create Ants, and make them built solutions in iterations. The base AntColony class makes implementing this very easy.
  • The heart of the algorithm is the Ant class. You will need to define an Ant that suits your needs.
  • Isula supports daemon actions (global behaviors) and ant-level policies, such as the ones present in multiple ACO Algorithms. You can add daemon actions to a solver via the addDaemonActions method and ant policies to a colony via the addAntPolicies method.
  • Finally, you call the solveProblem() method and wait for the best solution to be obtained.

Isula Workflow

Here is a sequence diagram of the solveProblem() method, for you to get an idea on how isula works:

Isula Workflow

Isula will provide you the basic execution flow for an algorithm in the ACO metaheuristic. Usually, you can rely on the implementations already available for AcoProblemSolver and AntColony but you are free to override and extend in case you need it. Take in mind that you will need to create your own Ant instance for custom problems, however the base implementation already contains a lot of functionality available. If you need some reference, please take a look to the projects on the "Examples" section.

Every ACO algorithm has a set of customized behaviours that are executed during the solution processes: this behaviours can have global impact (DaemonAction instances, like pheromone update rules) or only affect an ant and its solution (like component selection rules: they are subclasses of AntPolicy). Isula already provides these behaviours for some representative algorithms (take a look at the isula.aco.algorithms package) ,but you might need to define your own policies or extend the ones already available.

Examples

If you are not familiar with the framework, a good place to start is the classic Travelling Salesman Problem:

Here are some advanced examples of optimization problems solved with Isula-based algorithms:

Resources

Support

Feel free to contact me via email, or create a GitHub Issue here.

isula's People

Contributors

cptanalatriste avatar jbrcaballero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

isula's Issues

A new Environment API

Ants should not have access to the Environment API: All its interactions should be mediated by the Ant Colony type.

Issue with problem reading and solution suggestion

I'm using the framework in particular way. I have to determine pathways between cities of my own. Now each time I had a problem to solve, I'd override a tsp file I created. The thing is when I was trying to solve a new problem, the getRepresentationFromFile() method was returning me the previous problem. I bypassed it by using my own method which were rendering the problem representation from an arraylist (instead of a file).
Now the other issue I have is that whenever I passed to the algorithm only close cities or neighborhoods coordinates, the algorithm would fail. There should be at least one long distance between two points for the algorithm to work. It'd break otherwise.
I don't know what's the real issue and how to fix it. And I need to do more: instead of using the Euclidean methods to calculate distances, I want to use a geolocation service API to use the actual estimated travel time between 2 points plus the estimated time to spend on each point.
I think that having my own getDistance() method (which calls the API and do stuffs) would help me do that but I'm not sure it'll prevent the program from crashing if the two points are still close.

Any way you can help me? It's for my internship

General Architecture

I think it is important to clarify the responsibilities and functionalties of each clas (actor) in the system.
The Environment: Is a representation of the problem to solve. I can think of two representatins: matrix and graph. Although a graph can be represented by a matrix, it is possible that we need to store/access additional informaton in which case a more robust graph representation is required. The enviroment keeps track of the pherome values and provides an API for changing this values, i.e. init the values, get the value of an edge/path, perform the global decay.
The Colony: The Colony is the container for the ants. It also contains the policies the ants in the colony follow. Its API should allow creation of ants, admin of the policies (add/remove), initiate the foraging (i.e. solve the problem), thet the best ant, etc. The coloby should have a reference to the environment(s) in which it is placed (I am thinking colony reuse and perhaps one colony with many environments).
The Ant: The ant should be an autonomous agent. This means that once it "leaves" the colony it should be able to find the food and return by itself. As such, the ant should keep a reference to the environment so it can make navigation decisions. The ant keeps track of the solution if is currently working on and should be capable of determining when a solution is ready (i.e. return to the colony). Since the ant colony system algorithm performs the decay and update pheromone activities after all ants have found a soultion, there is no need for syncrhonized access to the environment (in case Ants run in separate threads)

A new Ant Colony API

Isula should offer specialized Ant Colonies per ACO Algorithm: For example, a Min-Max Colony or an Ant-System Colony.

customization issue

Hello.

I've replaced the tsp file with data coming from a database and it works well. Now I want to replace the classic Euclidean distance metrics with estimated travel time between points.
I've already written the methods for that and then, given two points, I can tell how many seconds it'll take to travel from one of them to the other.
I don't know how to integrate that in the system.

Your help would be very appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.