Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/model_random.py
diff options
context:
space:
mode:
authorThomas Jourdan <b.vehikel@googlemail.com>2010-01-03 10:49:23 (GMT)
committer Thomas Jourdan <b.vehikel@googlemail.com>2010-01-03 10:49:23 (GMT)
commit9e2fd70f8e06e550baf1e396568e6c9674b3d08f (patch)
treefcd3a2b8df82cd4b2bf0cb22843c9a3ffed6c3f1 /model_random.py
parentee878465ad84f8b2fd25eccf690ea29dde27e7df (diff)
Added stamps using SVG files.
Bug fixed in the minimal distance calculation of Voronoi diagrams.
Diffstat (limited to 'model_random.py')
-rw-r--r--model_random.py84
1 files changed, 43 insertions, 41 deletions
diff --git a/model_random.py b/model_random.py
index 9d69581..7adeeb5 100644
--- a/model_random.py
+++ b/model_random.py
@@ -152,71 +152,73 @@ def crossingover_list(this_list, other_list):
len_this, len_other = len(this_list), len(other_list)
min_elements = min([len_this, len_other])
max_elements = max([len_this, len_other])
-
new_list = []
- cross_sequence = crossing_sequence(min_elements)
- for index in range(min_elements):
- this_element, other_element = this_list[index], other_list[index]
- if this_element.__class__ == other_element.__class__ \
- and 'crossingover' in dir(this_element):
- # delegate crossing over to the elements components
- new_list.append(this_element.crossingover(other_element))
- else:
- # crossing over whole elements
- if cross_sequence[index]:
- new_list.append(this_element.copy())
+ if max_elements > 0:
+ cross_sequence = crossing_sequence(min_elements)
+ for index in range(min_elements):
+ this_element, other_element = this_list[index], other_list[index]
+ if this_element.__class__ == other_element.__class__ \
+ and 'crossingover' in dir(this_element):
+ # delegate crossing over to the elements components
+ new_list.append(this_element.crossingover(other_element))
else:
- new_list.append(other_element.copy())
-
- # appending elements from protozoon of greater size
- if len_this > len_other:
- for index in range(min_elements, max_elements):
- new_list.append(this_list[index].copy())
- if len_this < len_other:
- for index in range(min_elements, max_elements):
- new_list.append(other_list[index].copy())
+ # crossing over whole elements
+ if cross_sequence[index]:
+ new_list.append(this_element.copy())
+ else:
+ new_list.append(other_element.copy())
+
+ # appending elements from protozoon of greater size
+ if len_this > len_other:
+ for index in range(min_elements, max_elements):
+ new_list.append(this_list[index].copy())
+ if len_this < len_other:
+ for index in range(min_elements, max_elements):
+ 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
+ pre: len(first) >= 0
+ pre: len(second) >= 0
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][:])
+ if len_max > 0:
+ 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
+ pre: len(first) >= 0
+ pre: len(second) >= 0
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])
+ if len_max > 0:
+ 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):