Skip to content

Commit

Permalink
Merge pull request #509 from SergeStinckwich/master
Browse files Browse the repository at this point in the history
Classify methods in Proportion classes
  • Loading branch information
SergeStinckwich authored Oct 25, 2022
2 parents c4bc671 + 99212fa commit 176cfa0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Kendrick-Core/KELinearWalkProportionalSelection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/Kendrick-Core/KEProportionalSelection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
]
Expand Down
23 changes: 12 additions & 11 deletions src/Kendrick-Core/KETransition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 176cfa0

Please sign in to comment.