From f04623597f364dd6f85bf4c5ddc16cd0d47a93e7 Mon Sep 17 00:00:00 2001 From: Serge Stinckwich Date: Tue, 25 Oct 2022 14:52:25 +0800 Subject: [PATCH] Classify methods --- ...KELinearWalkProportionalSelection.class.st | 4 ++-- .../KEProportionalSelection.class.st | 7 +++++- src/Kendrick-Core/KETransition.class.st | 23 ++++++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Kendrick-Core/KELinearWalkProportionalSelection.class.st b/src/Kendrick-Core/KELinearWalkProportionalSelection.class.st index 88f7b5b3..07c6e836 100644 --- a/src/Kendrick-Core/KELinearWalkProportionalSelection.class.st +++ b/src/Kendrick-Core/KELinearWalkProportionalSelection.class.st @@ -7,13 +7,13 @@ Class { #category : #'Kendrick-Core-Simulations' } -{ #category : #'as yet unclassified' } +{ #category : #accessing } KELinearWalkProportionalSelection >> at: index put: value [ total := total + value - frequencies at:index. frequencies at: index put: value ] -{ #category : #'as yet unclassified' } +{ #category : #initialization } KELinearWalkProportionalSelection >> initialize: size [ super initialize: size. diff --git a/src/Kendrick-Core/KEProportionalSelection.class.st b/src/Kendrick-Core/KEProportionalSelection.class.st index bef53325..f1e92d79 100644 --- a/src/Kendrick-Core/KEProportionalSelection.class.st +++ b/src/Kendrick-Core/KEProportionalSelection.class.st @@ -3,6 +3,11 @@ Abstract class for proportional selection Based on code from: [https://web.archive.org/web/20210424164451/https://thoughts.johnbnelson.com/fast_proportional_selection/](https://web.archive.org/web/20210424164451/https://thoughts.johnbnelson.com/fast_proportional_selection/) +# Methods +`at:` returns the frequencies according to the position in the selection +`from:` initializes the proportional selection with a new collection of frequencies + +`at:put:`, `normalize` and `sample` are abstract methods. " Class { @@ -36,7 +41,7 @@ aCollection doWithIndex:[:each :i| self at: i put: each] ] -{ #category : #initialize } +{ #category : #initialization } KEProportionalSelection >> initialize: size [ frequencies := Array new: size withAll:0 ] diff --git a/src/Kendrick-Core/KETransition.class.st b/src/Kendrick-Core/KETransition.class.st index b75ee5f7..94156702 100644 --- a/src/Kendrick-Core/KETransition.class.st +++ b/src/Kendrick-Core/KETransition.class.st @@ -29,17 +29,18 @@ KETransition >> = aTransition [ { #category : #accessing } KETransition >> executeOn: model times: times [ - (from at: #status) = #empty - ifFalse: [ | old new | - old := model population compartments at: from. - new := old - times. - new := new max: 0. - model population compartments at: from put: new ]. - (to at: #status) = #empty - ifFalse: [ | old new | - old := model population compartments at: to. - new := old + times. - model population compartments at: to put: new ] + + | old new | + (from at: #status) = #empty ifFalse: [ + | old new | + old := model population compartments at: from. + new := old - times. + new := new max: 0. + model population compartments at: from put: new ]. + (to at: #status) = #empty ifTrue: [ ^ self ]. + old := model population compartments at: to. + new := old + times. + model population compartments at: to put: new ] { #category : #accessing }