@@ -13,7 +13,7 @@ Class {
1313 #classVars : [
1414 'Primes'
1515 ],
16- #category : 'Math-FunctionFit'
16+ #category : # 'Math-FunctionFit'
1717}
1818
1919{ #category : #utils }
@@ -57,14 +57,24 @@ PMAnotherChromosomeManager class >> origin: anArray range: anotherArray [
5757PMAnotherChromosomeManager >> crossover: aChromosome1 and: aChromosome2 [
5858"the Discrete Recombination operator
5959that does not prefer schemata of certain parameters based on their position"
60- |new1 new2|
61- aChromosome1=aChromosome2 ifTrue:[^Array with:( self mutate: aChromosome2) with: (self mutate: aChromosome1) ].
60+ | random new1 new2 |
61+
62+ aChromosome1 = aChromosome2 ifTrue:[
63+ ^ Array
64+ with: (self mutate: aChromosome2)
65+ with: (self mutate: aChromosome1) ].
66+
6267 new1 := self clone: aChromosome1.
6368 new2 := self clone: aChromosome2.
64- 2 to: new1 size do: [:i| (Float random <0.5)ifTrue:[
69+
70+ random := Random new.
71+
72+ 2 to: new1 size do: [ :i |
73+ (random next < 0.5) ifTrue: [
6574 new1 at: i put: (aChromosome2 at: i).
66- new2 at: i put: (aChromosome1 at: i)]].
67- ^Array with: new1 with: new2
75+ new2 at: i put: (aChromosome1 at: i) ] ].
76+
77+ ^ Array with: new1 with: new2
6878]
6979
7080{ #category : #operation }
@@ -116,20 +126,26 @@ PMAnotherChromosomeManager >> lineCrossOver: aChromosome1 and: aChromosome2 [
116126
117127{ #category : #operation }
118128PMAnotherChromosomeManager >> mutate: aVector [
119- "BGA mutation"
120- | isMutated threshold new index|
121- isMutated :=false.
122- threshold :=1/ aVector size asFloat .
123- new :=aVector copy.
124- 1 to: aVector size do:[:i| Float random < threshold ifTrue:[
125- isMutated :=true.
129+ "BGA mutation"
130+ | isMutated threshold new random index|
131+
132+ isMutated := false.
133+ threshold := 1 / aVector size asFloat.
134+ new := aVector copy.
135+ random := Random new.
136+
137+ 1 to: aVector size do: [ :i |
138+ random next < threshold ifTrue: [
139+ isMutated := true.
126140 new at: i put: (new at: i) +
127- ((Float random <0.5 ifTrue: [0.5] ifFalse:[0.5 negated ] )*(self randomRangeAt: i))]].
141+ ((random next < 0.5 ifTrue: [ 0.5 ] ifFalse:[ -0.5 ]) * (self randomRangeAt: i)) ] ].
142+
128143 isMutated ifFalse: [
129144 index := aVector size random + 1.
130145 new at: index put: (new at: index) +
131- ((Float random <0.5 ifTrue: [0.5] ifFalse:[0.5 negated ] )*(self randomRangeAt: index))].
132- ^new
146+ ((random next < 0.5 ifTrue: [ 0.5 ] ifFalse:[ -0.5 ]) * (self randomRangeAt: index)) ].
147+
148+ ^ new
133149]
134150
135151{ #category : #accessing }
@@ -155,8 +171,9 @@ PMAnotherChromosomeManager >> printOn: aStream [
155171
156172{ #category : #operation }
157173PMAnotherChromosomeManager >> process: aChromosome1 and: aChromosome2 [
158- | roll |
159- roll := Number random.
174+ | random roll |
175+ random := Random new.
176+ roll := random next.
160177 roll < rateOfCrossover
161178 ifTrue: [population addAll: (self crossover: aChromosome1 and: aChromosome2)]
162179 ifFalse:
@@ -224,8 +241,10 @@ PMAnotherChromosomeManager >> rateOfMutation: aNumber [
224241
225242{ #category : #private }
226243PMAnotherChromosomeManager >> smallDistribution [
227- "an exponential distribution as used by H. Mühlenbein"
228- ^2 raisedTo: (16 *Float random negated)
244+ "an exponential distribution as used by H. Mühlenbein"
245+ | random |
246+ random := Random new.
247+ ^ 2 raisedTo: (16 * random next negated)
229248]
230249
231250{ #category : #private }
0 commit comments