File Exchange Pick of the Week

May 4th, 2007

Ant Colony Optimization

I recently finished up my final seminar for The MathWorks before transitioning to a new position at the MathWorks. (My old job is now available, you can have my title and office, but not the blog!) One of the books that I read during the journey was Emergence: The Connected Lives of Ants, Brains, Cities, and Software. It appealed to me because of the complex behavior that can emerge from many agents following simple rules.

One of the examples was discussing Ant Colony Optimization as used to solve the Traveling Salesman Problem. I was intrigued enough that I wanted to program it up in MATLAB to see how it works. Once I got on to The File Exchange here at MATLAB Central, Wang had already implemented it. We discussed it over e-mail; he made some changes to show the iterative nature of the solution graphically. Now we can watch as the ants go about their work. It turns out that the solution converges very quickly so the animation is not as active as I had hoped. However, often you will be able to see a potential optimization, and within a few iterations that optimization will “pop” through.

You can get the files here. Then try this example:

ACO('st70.tsp')

ACO.jpg

9 Responses to “Ant Colony Optimization”

  1. Paul replied on :

    I get the error message “??? Undefined function or method ‘randint’ for input arguments of type ‘double’.”

    Am I doing something stupid?

    I’m running Matlab R2007a. Do I need a specif toolbox?

  2. J.Paul replied on :

    It didn’t work for me either, so I did some digging and found randint in the Communications toolbox. I wrote a simple randint function and it works now. This will work for this case, but it doesn’t exactly mimic the functionality of the Comm Toolbox randint

    function out = randint(m,n,range)
    % RANDINT(m,n,range) generates a m x n matrix of random integers from range(1) to range(2) inclusive

    a = range(1);
    b = range(2);
    out = floor((b-a+1)*rand(m,n)) +a;

  3. masoud replied on :

    I’m running Matlab 7.0.4. Do I need a specif toolbox for ant colony model? I want to use classification algorithm

  4. Doug replied on :

    Masoud,

    According to the author’s notes on the page where you download, you will need R2006a. You can tell what version you have with the VER command.

    Doug

  5. Mr. Thanh replied on :

    I have a problem about ant colony optimization. I do not know this algorithm because I have nothing to read. Please, help me.

    If you have any code about application Ant Colony to find Minimum, please send me.

    I am looking forward to your letter
    thank you very much.

  6. Doug replied on :

    Try the wikipedia article:

    http://en.wikipedia.org/wiki/Ant_colony_optimization

    Dogu

  7. dr_sara replied on :

    alslam alikm;
    dear friend i search for program solving any of data mining techniques by matlab i prefer “classification”
    i hope you can provide me any links thanks;
    best regrades;
    dr_sara

  8. chris replied on :

    is there any code in MATLAB to calculate any fitness’ values using ACO ?thanx

  9. Diane replied on :

    Hello,
    This is a very nice site.
    Btw do u have any matlab code Ant Colony Optimisation for Vehicle Routing Problem?

    Thk You very much


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.