1

I am trying to implement a stochastic ant colony optimisation algorithm, and I'm having trouble working out how to implement movement choices based on probabilities.

the standard (greedy) version that I have implemented so far is that an ant m at a vertex i on a graph G = (V,E) where E is the set of edges (i, j), will choose the next vertex j based on the following criteria:

j = argmax(<fitness function for j>) 
such that j is connected to i

the problem I am having is in trying to implement a stochastic version of this, so that now the criteria for choosing a new vertex, j is:

P(j) = <fitness function for j>/sum(<fitness function for J>)
where P(j) is the probability of choosing vertex j,
such j is connected to i,
and J is the set of all vertices connected to i

I understand the mathematics behind it, I am just having trouble working out how i should actually implement it.

if, say, i have 3 vertices connected to i, each with a probability of 0.2, 0.3, 0.5 - what is the best way to make the selection? should I just randomly select a vertex j, then generate a random number r in the range (0,1) and if r >= P(j), select vertex j? or is there a better way?

guskenny83
  • 1,321
  • 14
  • 27
  • 1
    If i understood well, you have to pick one j, because sum(pij) = 1. Each j has its probability. To achieve it, in the example you gave, pick r uniformly from [0,1]: if r < 2 then the first element (0.2), else if < 0.5 then the second (0.3), else the third (0.5). The general algorithm starts by arranging the array and giving element a cumulative value. – A.S.H Oct 09 '15 at 05:10
  • If you agree on the idea, I can write some C pseudo code for the general case if you are interested :) – A.S.H Oct 09 '15 at 05:13
  • 1
    That makes sense. I thought of something like that initially but then thought it wouldn't work, but on further thought, because the probabilities have to add up to 1, it will.. i was thinking of an example where we have 0.8 and 0.9, so 0.9 would only be chosen 0.2 of the time. But of course that is illegal! Thanks for clarifying.. – guskenny83 Oct 09 '15 at 05:56

2 Answers2

0

Looking at the problem statement, I think you are not trying to visit all nodes (connected to i (say) ), but some of the nodes based on some probability distribution. Lets take an example:

You have a node i and connected to it are 5 nodes, a1...a5, with probabilities p1...p5, such that sum(p_i) = 1. No, say the precision of probabilities that you consider is 2 places after decimal. Also, you dont want to visit all 5 nodes, but only k of them. Lets say, in this example, k = 2. So, since 2 places of decimal is your probability precision, add 3 to it to increase normality of probability distribution in the random function. (You can change this 3 to any number of your choice, as far as performance is concerned) (Since you have not tagged any language, I'll take example of java's nextInt() function to generate random numbers.)

Lets give some values:

p1...p5 = {0.17, 0.11, 0.45, 0.03, 0.24}

Now, in a loop from 1 to k, generate a random number from (0...10^5). {5 = 2 + 3, ie. precision + 3}. If the generated number is from 0 to 16999, go with node a1, 17000 to 27999, go with a2, 28000 to 72999, go with a3...and so on. You get the idea.

vish4071
  • 5,135
  • 4
  • 35
  • 65
0

What you're trying to implement is a weighted random choice depending on the probabilities for the components of the solution, or a random proportional selection rule on ACO terms. Here is an snippet of the implementation of this rule on the Isula Framework:

double value = random.nextDouble();
while (componentWithProbabilitiesIterator.hasNext()) {
    Map.Entry<C, Double> componentWithProbability = componentWithProbabilitiesIterator
            .next();

    Double probability = componentWithProbability.getValue();  
    total += probability;

    if (total >= value) {
        nextNode = componentWithProbability.getKey();
        getAnt().visitNode(nextNode);
        return true;
    }
}

You just need to generate a random value between 0 and 1 (stored in value), and start accumulating the probabilities of the components (on the total variable). When the total exceeds the threshold defined in value, we have found the component to add to the solution.

Carlos Gavidia-Calderon
  • 7,145
  • 9
  • 34
  • 59