Created
December 16, 2021 17:35
-
-
Save Ifihan/e04febddc8f619a95c8cdbf8de5e02ab to your computer and use it in GitHub Desktop.
Cross-over genetic algorithm implementation in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
# prb_score = int(input("Enter the probability score: ")) | |
def cross_over(parent1, parent2): | |
child1 = [] | |
child2 = [] | |
for i in range(len(parent1)): | |
if random.random() < 0.5: | |
child1.append(parent1[i]) | |
child2.append(parent2[i]) | |
else: | |
child1.append(parent2[i]) | |
child2.append(parent1[i]) | |
return child1, child2 | |
print(cross_over([1,0, 0, 1], [0, 1, 0, 0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment