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

10 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

  10. Lee replied on :

    I am searhing for Ant Colony Optimisation for Vehicle Routing Problem codes too. Please send me if you have.

    Thanks in advanced.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


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

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

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