Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. def crossoverpunten(ch1, ch2):
  2.     """
  3.        >>> chromosoom1 = [3, 5, 7, 9, 20, 25, 30, 40, 55, 56, 57, 60, 62]
  4.        >>> chromosoom2 = [1, 4, 7, 11, 14, 25, 44, 47, 55, 57, 100]
  5.        >>> crossoverpunten(chromosoom1, chromosoom2)
  6.        4
  7.    """
  8.     return len(list(set(ch1) & set(ch2)))
  9.  
  10. def maximaleSom(ch1, ch2):
  11.     pos1, pos2, sums, crossoverpoints = 0, 0, [], []
  12.     partSums1, partSums2 = 0, 0
  13.     while pos1 < len(ch1) and pos2 < len(ch2):
  14.         val1 = ch1[pos1]
  15.         val2 = ch2[pos2]
  16.         if val1 < val2:
  17.             partSums1 += val1
  18.             pos1 += 1
  19.         elif val2 < val1:
  20.             partSums2 += val2
  21.             pos2 += 1
  22.         elif val1 == val2:
  23.             crossoverpoints.append(val1)
  24.             sums.append((partSums1, partSums2))
  25.             partSums1, partSums2 = 0, 0
  26.  
  27.     #now we need to determine the unfinished list, if there is one
  28.  
  29.     unfinished = None
  30.     unfinishedPos = 0
  31.     if pos1 < len(ch1):
  32.         unfinished = ch1
  33.         unfinishedPos = pos1
  34.     elif pos2 < len(ch2):
  35.         unfinished = ch2
  36.         unfinishedPos = pos2
  37.  
  38.     if unfinished != None:
  39.         i = unfinishedPos
  40.         while i < len(unfinished):
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. # for _ in range(len(ch1 + ch2)):
  48. #     if pos1 < len(ch1) and ch1[pos1] < ch2[pos2]:
  49. #         partSums1 += ch1[pos1]
  50. #         pos1 += 1
  51. #     elif pos2 < len(ch2) and ch2[pos2] < ch2[pos2]:
  52. #         partSums2 += ch2[pos2]
  53. #         pos2 += 1
  54. #     elif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement