I am working on an optimization problem. I have X number of ambulance locations, where X ranges from 1-39.
There are 43 numbers [Ambulance Locations] to choose from (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39) , we choose 3 of them since I have 3 ambulances.
To encode my problem for `programming`, I am working on Chromosome representation:
I can only put my ambulance in three locations among 1-39 locations (Restriction).
Assume that I want to put my Ambulance on the 5th, 19th, and 31 positions.
I am doing something like this for a better presentation:
Chromosome 1 = [5, 19, 31] --> 3 Ambulances
Chromosome 1= [000010000000000000100000000000100000000] - Chromosome Presentation
In the above presentation, I am turning on 5-bit, 19-bit, and 31-bit.
To achieve mutation, what can be a good way to randomly change present positions to other positions keeping the range only between 1-39 locations (Restriction)?
random.sample(range(1,40),3)? would give you 3 bit positions at random ... that you could encode withtest_num = sum(1<<i for i in random.sample(range(1,40),3))is that what you mean? then you could print it withf"{test_num:039b}"3binary number positions among39 positions. Since I want to do mutation, I do not want to repeat the sequence of the generated3 bits. I am following this formula(Combinations without repetition (Is order important: No)- hackmath.net/en/calculator/combinations-and-permutations? n=39&k=3&order=0&repeat=0). How can I avoid repetition of the generated 3 bits, keeping order is not important? for instance I want 100 samples off"{test_num:039b}"generate 100 or 200strings usingtest_num = sum(1<<i for i in random.sample(range(1,40),3)). These all will be unique. Am I wrong?