Preventing Self-Crossover in Genetic Algorithms: A Code Explanation
This code generates a random integer between 1 and 'ps' using the 'rand' function and assigns it to the variable 'r'. It then enters a 'while' loop that checks whether the current value of 'j' is equal to the remainder of 'r' divided by 'ps'. This is done to prevent the crossover of an individual with itself. If 'j' is equal to 'r' mod 'ps', a new random value is generated for 'r' until 'j' is no longer equal to 'r' mod 'ps'. Once a suitable value for 'r' is found, the 'while' loop is exited and the crossover operation can proceed.
原文地址: https://www.cveoy.top/t/topic/oAQL 著作权归作者所有。请勿转载和采集!