Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def crossoverpunten(ch1, ch2):
- """
- >>> chromosoom1 = [3, 5, 7, 9, 20, 25, 30, 40, 55, 56, 57, 60, 62]
- >>> chromosoom2 = [1, 4, 7, 11, 14, 25, 44, 47, 55, 57, 100]
- >>> crossoverpunten(chromosoom1, chromosoom2)
- 4
- """
- return len(list(set(ch1) & set(ch2)))
- def maximaleSom(ch1, ch2):
- pos1, pos2, sums, crossoverpoints = 0, 0, [], []
- partSums1, partSums2 = 0, 0
- while pos1 < len(ch1) and pos2 < len(ch2):
- val1 = ch1[pos1]
- val2 = ch2[pos2]
- if val1 < val2:
- partSums1 += val1
- pos1 += 1
- elif val2 < val1:
- partSums2 += val2
- pos2 += 1
- elif val1 == val2:
- crossoverpoints.append(val1)
- sums.append((partSums1, partSums2))
- partSums1, partSums2 = 0, 0
- #now we need to determine the unfinished list, if there is one
- unfinished = None
- unfinishedPos = 0
- if pos1 < len(ch1):
- unfinished = ch1
- unfinishedPos = pos1
- elif pos2 < len(ch2):
- unfinished = ch2
- unfinishedPos = pos2
- if unfinished != None:
- i = unfinishedPos
- while i < len(unfinished):
- # for _ in range(len(ch1 + ch2)):
- # if pos1 < len(ch1) and ch1[pos1] < ch2[pos2]:
- # partSums1 += ch1[pos1]
- # pos1 += 1
- # elif pos2 < len(ch2) and ch2[pos2] < ch2[pos2]:
- # partSums2 += ch2[pos2]
- # pos2 += 1
- # elif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement