title: Ant colony optimization - movement of ants
body: <p>I am trying to implement ant colony optimization. Tried to refer this paper: <a href="https://stackoverflow.com/questions/23574744/improved-ant-colony-optimization-for-robot-navigation-paper">Improved ant colony optimization for robot navigation paper</a>. 
  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:</p>
  
  <ol>
  <li><p>What I have done so far is, have setup a 2d array map, with <code>0</code> value for the boundary around the map as well as for obstacles.</p></li>
  <li><p>The obstacles are generated at random position, by inserting the <code>0</code> at random [row,column] in that array.</p></li>
  <li><p>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.</p></li>
  <li><p>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)</p></li>
  </ol>
  
  <p>My current implementations pseudo code would look like this:</p>
  
  <pre><code>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 &lt;row,column&gt; in the map array
      otherwise,
         assign INITIAL_PHEROMONE_FACTOR as value to &lt;row,column&gt; in the map array 
      end if
    end for
  end of
  
  for 5 random locations in map(ie. &lt;row, column&gt; )
    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
  </code></pre>
  
  <p>Here's the screenshot of what I have done so far:</p>
  
  <p><img src="https://i.stack.imgur.com/34fuO.png" alt="enter image description here"></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>