@@ -113,13 +113,24 @@ def select_parents(
113
113
>>> len(selected_parents)
114
114
2 # Should select the two parents with the best fitness scores.
115
115
>>> np.array_equal(selected_parents[0], np.array([1.0, 2.0]))
116
- # Parent 1 should be [1.0, 2.0]
117
- True
116
+ True # Parent 1 should be [1.0, 2.0]
118
117
>>> np.array_equal(selected_parents[1], np.array([-1.0, -2.0]))
119
- # Parent 2 should be [-1.0, -2.0]
120
- True
121
- """
118
+ True # Parent 2 should be [-1.0, -2.0]
122
119
120
+ >>> population_score = [
121
+ ... (np.array([1.0, 2.0]), 5.0),
122
+ ... (np.array([1.0, -2.0]), 5.0),
123
+ ... (np.array([0.0, 0.0]), 0.0),
124
+ ... (np.array([-1.0, 2.0]), 5.0),
125
+ ... (np.array([-1.0, -2.0]), 5.0)
126
+ ... ]
127
+ >>> selected_parents = ga.select_parents(population_score)
128
+ >>> len(selected_parents)
129
+ 5 # Should select the top 5 parents with the best fitness scores.
130
+ >>> np.array_equal(selected_parents[0], np.array([1.0, 2.0]))
131
+ True # Parent 1 should be [1.0, 2.0]
132
+ """
133
+
123
134
if not population_score :
124
135
raise ValueError ("Population score is empty, cannot select parents." )
125
136
0 commit comments