0

I have a binary vector of 32 bit. This vector represents an integer in my solution space. Now I want to perform exploitation in this vector for searching in the search space.I have learnt that I have to flip more bits around the LSB in the binary string to perform exploitation.So,I thought of generating an exponential distribution and mutate(flip) the bits according to it.Will it be a viable solution. ?

Also ,it would be a great help if somebody could please help with the code.I am having a hard time coding this logic.I was trying to do something like this :

double exploit_probs[32]={2.1760605535605863e-14,5.915145860370273e-14,1.6079033504929256e-13,4.3707344595633353e-13,1.1880888058450779e-12,3.229560211524282e-12,8.778854836900806e-12,2.3863401577827254e-11,6.486745087422874e-11,1.763280129698758e-10,4.793092335043042e-10,1.3028975796473835e-09,3.5416428150987542e-09,9.627183307175482e-09,2.6169397443139367e-08,7.113579753140834e-08,1.933671457825691e-07,5.256263986017488e-07,1.4288006878775044e-06,3.883882946347204e-06,1.0557488436917582e-05,2.869822897223955e-05,7.800987432419569e-05,0.00021205282381583498,0.0005764193376520116,0.001566870211111862,0.004259194822419162,0.011577691889648859,0.031471429479130154,0.08554821486874982,0.23254415793483257,0.6321205588285657};
int i=0;
for(int k=0;k<32;k++){
    if( (rand()/RAND_MAX) < exploit_probs[i++]){
        if(key[k]==0){  //key is the binary array.
            key[k]=1;
        }
        else{
            key[k]=0;
        }
    }
}

But ,I feel the above code will be biased ,since rand()/RAND_MAX will generate values between 0-1.But my probability distribution ranges from 2.1760605535605863e-14 to 0.6321205588285657.So there is very less probability that my bits will be flipped.The last bits has 63% chance of getting flipped.

gag123
  • 357
  • 1
  • 2
  • 8
  • 2
    It is not clear what you are trying to achieve. Please [edit] your question and add more details, a [mre] and maybe an example. `rand()` returns an integer value and `rand()/RAND_MAX` will do an integer division which will produce a value 0 in most cases and 1 if `rand()` returned `RAND_MAX`. You would have to cast at least one value to `double` for a `double` result. `RAND_MAX` is guaranteed to be at least 32767, in this case the lowest non-zero result would be approximately 3e-5. You would need to get much more random bits to get reasonable results for lower probabilities. – Bodo Apr 21 '21 at 15:18
  • I just need an idea of how to perform exploitation in a binary like 00110101 . – gag123 Apr 23 '21 at 05:56
  • **Please [edit] your question to add information or clarification** instead of adding information in comments. I don't see any connection between your algorithm and my understanding of *exploitation*. (Maybe I'm lacking some background information.) I could try to fix the random number comparison in your code without such knowledge. Where do the values in `exploit_probs` come from? Do you need the precision schown in your code? Is there some algorithm to calculate the numbers? It might be difficult to generate random numbers with enough precision to match the wide range of probability values. – Bodo Apr 23 '21 at 09:00

2 Answers2

0

First, you are saying that you have string but you are assigning an integer to it. It should be like

if( (rand()/RAND_MAX) < exploit_probs[i++])
{
    if(key[k]==0){  //key is the binary array.
        key[k]= '1';
    }
    else{
        key[k]= '0';
    }
}

Also, mutations are rare in generic algorithms. Actual change comes from cross-over. So it's okay for them to have that little chance for mutation.

fatihsonmez
  • 103
  • 11
  • I have just edited .Its not string .Its a binary value like 01101010. But that's not the main concern.My concern is,I just need a way to randomly flip bits towards the end side of the binary vector. Like for 01101010 ,I need to randomly flip bits around the last 4 digits(say) : 1010 --> 1011--> 1110 etc. – gag123 Apr 23 '21 at 06:17
0

The smaller the change in your solution the more the exploitation you are applying. Therefore, in your case, flipping only one bit in your solution is the highest level of exploitation that you can achieve. In contrast, the highest level of exploitation you can achieve is by random search.

GA try to balance it by applying crossover and mutation operators. The mutation is essentially to add diversity to your population (to explore new areas of the search space). Crossover exploits the search space by creating (or moving) the solutions towards already known (good) positions of the search space.

If you want a true exploitation step in your algorithm, after you generate the new population (offspring) using crossover and mutation operators, you could apply a local search operator on each of the new individuals. In this sense, your algorithm would be a hybrid metaheuristic.

Applying local search after the generation of the offspring guarantee that each of the new sampled solutions is actually on the local minimum. Currently, the best algorithm for very hard combinatorial problems such as VRP and FJSP are hybrid metaheuristics.

Local search relies on the neighbourhood function. So in your case is very simple to define a neighbourhood function. For any given solution composed of n bits, you generate n new solutions where each new solution has one bit flipped in comparison to the original solution, e.g., solution [0, 0, 0], neighbours [1, 0, 0], [0, 1, 0], [0, 0, 1].

// Simple local search to be applied after generation of offspring
for individual in offspring:
    neighborhood = neighborhood_func(individual)
    for neighbour in neighbourhood:
        if fitness(neighbour) >= fitness(individual):
            // you found a better solution, replace it
            // replacing even if he has same fitness is good for diversity

Note that multiple neighbourhood functions can be defined for the same problem.

WillEnsaba
  • 756
  • 1
  • 8
  • 23