diff options
author | Thomas Jourdan <b.vehikel@googlemail.com> | 2009-12-31 07:28:45 (GMT) |
---|---|---|
committer | Thomas Jourdan <b.vehikel@googlemail.com> | 2009-12-31 07:28:45 (GMT) |
commit | ee878465ad84f8b2fd25eccf690ea29dde27e7df (patch) | |
tree | bf93ed14c343f6468d7e5ec5846feff118aac31b /model_random.py | |
parent | ad81db80eab45f50b47e74e96912983e2bd07eb0 (diff) |
using unicode characters as stamps
Diffstat (limited to 'model_random.py')
-rw-r--r-- | model_random.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/model_random.py b/model_random.py index e8cc52e..9d69581 100644 --- a/model_random.py +++ b/model_random.py @@ -177,6 +177,48 @@ def crossingover_list(this_list, other_list): new_list.append(other_list[index].copy()) return new_list +def crossingover_str_list(first, second): + """Crossing over the str elements of the two input lists. + Returns a new list. + pre: len(first) >= 1 + pre: len(second) >= 1 + post: min([len(first), len(second)]) <= len(__return__) <= max([len(first), len(second)]) + post: forall(__return__, lambda x: x in first or x in second) + """ + seq = [] + len_first, len_second = len(first), len(second) + len_max = max([len_first, len_second]) + randseq = crossing_sequence(len_max) + for index in range(len_max): + if randseq[index]: + if index < len_first: + seq.append(first[index][:]) + else: + if index < len_second: + seq.append(second[index][:]) + return seq + +def crossingover_nativeelement_list(first, second): + """Crossing over the native elements of the two input lists. + Returns a new list. This is not a deep copy of the elements. + pre: len(first) >= 1 + pre: len(second) >= 1 + post: min([len(first), len(second)]) <= len(__return__) <= max([len(first), len(second)]) + post: forall(__return__, lambda x: x in first or x in second) + """ + seq = [] + len_first, len_second = len(first), len(second) + len_max = max([len_first, len_second]) + randseq = crossing_sequence(len_max) + for index in range(len_max): + if randseq[index]: + if index < len_first: + seq.append(first[index]) + else: + if index < len_second: + seq.append(second[index]) + return seq + def swap_places(this_list): """Select two elements from the list by random. Exchange these randomly selected elements.""" |