问题
I am trying to implement ant colony optimization. Tried to refer this paper: Improved ant colony optimization for robot navigation paper. Since I didn't got any answers to those questions I am stuck at half part in my implementation. So am asking specific questions related to ant colony now:
What I have done so far is, have setup a 2d array map, with
0
value for the boundary around the map as well as for obstacles.The obstacles are generated at random position, by inserting the
0
at random [row,column] in that array.I have placed the source, where all the ants starts the journey, to be from the left bottom corner. And I have placed the destination location to be on the top right corner.
Have written code to draw the map visually using Graphics function in VB.Net and it works fine. Color gradient displaying of the pheromones is shown on the map(ie. more white shade for more pheromone deposition on map, otherwise dark shade)
My current implementations pseudo code would look like this:
for each ant from 1 to colonysize
create an ant and insert it to the ant_array
set the ant's current position to the starting position in the map
end for
for each rows in map array
for each column in map array
if it is first row or first column or last row or last column(these holds the boundary), then...
assign 0 as value to <row,column> in the map array
otherwise,
assign INITIAL_PHEROMONE_FACTOR as value to <row,column> in the map array
end if
end for
end of
for 5 random locations in map(ie. <row, column> )
insert 0 as value to denote obstacle
end for
for 1 to TOTAL_NUMBER_OF_ITERATIONS
for 1 to TOTAL_ANTS_IN_COLONY
find the neighbors of the current ant in top, right, bottom and left positions
choose randomly a neighboring position from the above
check whether that location has an obstacle or is a boundary (ie. if it has 0 as value in array map)
if so,
repeat the above two steps of randomly chosing another neighboring position which was not already considered
otherwise, continue to the next line..
set the neighbor position we have selected above as the current position of the ant
save this position to the ant's local path storage
if the current position of this ant is the destination location,
then end program
end for
evaporate pheromones in the map at a constant factor
deposit pheromones on the current location of all the ants
draw the visual representationg of the map
end for
Here's the screenshot of what I have done so far:

At the moment, the implementation is stuck. When I read other papers as well as referred in google, it is said that, the ants at first walks randomly. But pheromone concentration on a path is used by other ants to choose the path. That means, if an ant had found the goal, it should return back to the nest instead of terminating the program? And how the other ants choose a path with high pheromone concentration? There is no guarantee that the other ants are moving in the right path.
Am really lot of confused with this. I understand the simple real world example. Ants at first moves randomly in search of food, and if an finds food, it would return back to the nest and goes back again and therefore the pheromone deposition in that path would be higher and other ants would chose that path.
But when I tried to implement, it's getting tricky and confusing for me. I would really appreciate some simple ideas or explanations. Am not looking for code. That's why I wrote the psuedo code instead of posting the code of my actual implementation done so far.
回答1:
Here's what Ant colony optimization does:
- Send the first ant. Because initially the board has no pheromone, the first ant can only use random movement to search for a path to the food.
- Increase the pheromone value on all the cells that forms the path found by the first ant by a small amount.
- Send another ant, this ant should find a path by picking the next cell to travel to in such a way that the cell with high pheromone value are more likely to be chosen than the cell with lower pheromone. Due to the random factor, the ant may sometimes pick the path with lower pheromone which can occasionally produce better/shorter path.
- If the ant succeeds, then increase the pheromone value on that path so the cells on the path are more likely to be chosen. If the ant doesn't succeed, then abort the ant and start again.
- Occasionally, reduce the pheromone on the whole board so less successful cells would get picked less and less.
- Repeat 3 until path is good enough.
Over a period of time, the path that are most successful will contain higher amount of pheromone than less successful path.
There is no guarantee that the other ants are moving in the right path!
That's the point of the randomness in the algorithm. If the ant only ever used tried and tested path, then it would never be able to improve the path. The point of the using weighted randomness to choose the next cell is so that a stray ant may be able to accidentally stumble on a better path than the original path.
来源:https://stackoverflow.com/questions/23584460/ant-colony-optimization-movement-of-ants