diff --git a/src/FireAutomata-Model-Tests/FireAutomataCellStateTest.class.st b/src/FireAutomata-Model-Tests/FireAutomataCellStateTest.class.st index d029d39..5add175 100644 --- a/src/FireAutomata-Model-Tests/FireAutomataCellStateTest.class.st +++ b/src/FireAutomata-Model-Tests/FireAutomataCellStateTest.class.st @@ -1,16 +1,17 @@ Class { - #name : #FireAutomataCellStateTest, - #superclass : #TestCase, + #name : 'FireAutomataCellStateTest', + #superclass : 'TestCase', #instVars : [ 'emptyCellState', 'treeCellState', 'fireCellState', 'ashCellState' ], - #category : #'FireAutomata-Model-Tests' + #category : 'FireAutomata-Model-Tests', + #package : 'FireAutomata-Model-Tests' } -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataCellStateTest >> setUp [ super setUp. @@ -21,13 +22,13 @@ FireAutomataCellStateTest >> setUp [ ashCellState := FireAutomataAshState new. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testAshCellStateColor [ self assert: ashCellState color equals: Color gray. ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellStateTest >> testAshTurnsToEmpty [ | cellState | @@ -41,13 +42,13 @@ FireAutomataCellStateTest >> testAshTurnsToEmpty [ self assert: cellState isEmpty. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testEmptyCellStateColor [ self assert: emptyCellState color equals: Color black. ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellStateTest >> testEmptyRemainsEmpty [ | cellState | @@ -58,13 +59,13 @@ FireAutomataCellStateTest >> testEmptyRemainsEmpty [ self assert: cellState isEmpty ]. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testFireCellStateColor [ self assert: fireCellState color equals: Color red. ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellStateTest >> testFireTurnsToAsh [ | cellState | @@ -78,7 +79,7 @@ FireAutomataCellStateTest >> testFireTurnsToAsh [ self assert: cellState isAsh. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testIsAsh [ self deny: emptyCellState isAsh. @@ -87,7 +88,7 @@ FireAutomataCellStateTest >> testIsAsh [ self assert: ashCellState isAsh. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testIsEmpty [ self assert: emptyCellState isEmpty. @@ -96,7 +97,7 @@ FireAutomataCellStateTest >> testIsEmpty [ self deny: ashCellState isEmpty. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testIsFire [ self deny: emptyCellState isFire. @@ -105,7 +106,7 @@ FireAutomataCellStateTest >> testIsFire [ self deny: ashCellState isFire. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testIsTree [ self deny: emptyCellState isTree. @@ -114,7 +115,7 @@ FireAutomataCellStateTest >> testIsTree [ self deny: ashCellState isTree. ] -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellStateTest >> testTreeCellStateColor [ self assert: treeCellState color equals: Color green. diff --git a/src/FireAutomata-Model-Tests/FireAutomataCellTest.class.st b/src/FireAutomata-Model-Tests/FireAutomataCellTest.class.st index 2f77e99..7a48e6f 100644 --- a/src/FireAutomata-Model-Tests/FireAutomataCellTest.class.st +++ b/src/FireAutomata-Model-Tests/FireAutomataCellTest.class.st @@ -1,33 +1,28 @@ Class { - #name : #FireAutomataCellTest, - #superclass : #TestCase, + #name : 'FireAutomataCellTest', + #superclass : 'TestCase', #instVars : [ 'cell' ], - #category : #'FireAutomata-Model-Tests' + #category : 'FireAutomata-Model-Tests', + #package : 'FireAutomata-Model-Tests' } -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataCellTest >> setUp [ super setUp. cell := FireAutomataCell new. ] -{ #category : #tests } -FireAutomataCellTest >> testEntityName [ - - self assert: cell class entityName equals: 'Cell' -] - -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellTest >> testGenerateTree [ cell generateTree. self assert: cell isTreeCell. ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellTest >> testGenerateTreeWithProbability [ "With random seed 42 the PMFishmanMooreRandomGenerator generates the following numbers: @@ -36,7 +31,8 @@ FireAutomataCellTest >> testGenerateTreeWithProbability [ This means that if we ask a cell 4 times to generate a tree with probability 0.1, then the first 3 times, nothing will happen. And on the 4th request, the tree will appear." - Cormas randomGenerator: (PMFishmanMooreRandomGenerator seed: 42). + cell randomNumberGenerator: PMFishmanMooreRandomGenerator new. + cell randomSeed: 42. 3 timesRepeat: [ cell generateTreeWithProbability: 0.1. @@ -46,13 +42,13 @@ FireAutomataCellTest >> testGenerateTreeWithProbability [ self assert: cell isTreeCell. ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellTest >> testInitializedEmpty [ self assert: cell isEmptyCell ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellTest >> testNewState [ cell setOnFire. @@ -67,13 +63,13 @@ FireAutomataCellTest >> testNewState [ self assert: cell isAshCell. ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellTest >> testPov [ self assert: cell pov isColor. ] -{ #category : #tests } +{ #category : 'tests' } FireAutomataCellTest >> testSetOnFire [ cell setOnFire. diff --git a/src/FireAutomata-Model-Tests/package.st b/src/FireAutomata-Model-Tests/package.st index 35b59f4..5211f5c 100644 --- a/src/FireAutomata-Model-Tests/package.st +++ b/src/FireAutomata-Model-Tests/package.st @@ -1 +1 @@ -Package { #name : #'FireAutomata-Model-Tests' } +Package { #name : 'FireAutomata-Model-Tests' } diff --git a/src/FireAutomata-Model/FireAutomataAshState.class.st b/src/FireAutomata-Model/FireAutomataAshState.class.st index 3f49922..69d638e 100644 --- a/src/FireAutomata-Model/FireAutomataAshState.class.st +++ b/src/FireAutomata-Model/FireAutomataAshState.class.st @@ -1,44 +1,45 @@ Class { - #name : #FireAutomataAshState, - #superclass : #FireAutomataCellState, + #name : 'FireAutomataAshState', + #superclass : 'FireAutomataCellState', #instVars : [ 'iterationsToDisappear' ], - #category : #'FireAutomata-Model' + #category : 'FireAutomata-Model', + #package : 'FireAutomata-Model' } -{ #category : #'default values' } +{ #category : 'default values' } FireAutomataAshState class >> defaultIterationsToDisappear [ ^ 2 ] -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataAshState >> color [ ^ Color gray ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataAshState >> initialize [ super initialize. iterationsToDisappear := self class defaultIterationsToDisappear. ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataAshState >> isAsh [ ^ true ] -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataAshState >> iterationsToDisappear: aNumber [ "Set the number of iterations during which the cell should remain in the state of ash. After those iterations, the ash will disappear and the state will be changed" iterationsToDisappear := aNumber ] -{ #category : #'instance creation' } +{ #category : 'instance creation' } FireAutomataAshState >> newState [ iterationsToDisappear := iterationsToDisappear - 1. diff --git a/src/FireAutomata-Model/FireAutomataCell.class.st b/src/FireAutomata-Model/FireAutomataCell.class.st index 98105c9..dd0e358 100644 --- a/src/FireAutomata-Model/FireAutomataCell.class.st +++ b/src/FireAutomata-Model/FireAutomataCell.class.st @@ -1,73 +1,68 @@ Class { - #name : #FireAutomataCell, - #superclass : #CMSpatialEntityCell, - #category : #'FireAutomata-Model' + #name : 'FireAutomataCell', + #superclass : 'CMSpatialEntityCell', + #category : 'FireAutomata-Model', + #package : 'FireAutomata-Model' } -{ #category : #accessing } -FireAutomataCell class >> entityName [ - - ^ 'Cell' -] - -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataCell >> generateTree [ self state: (FireAutomataTreeState forCell: self) ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataCell >> generateTreeWithProbability: aNumber [ "Probability that a cell is initialized with a tree in it" - Cormas random < aNumber + self random < aNumber ifTrue: [ self generateTree ] ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataCell >> initialize [ super initialize. self state: (FireAutomataEmptyState forCell: self). ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCell >> isAshCell [ ^ state isAsh ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCell >> isEmptyCell [ ^ state isEmpty ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCell >> isFireCell [ ^ state isFire ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCell >> isTreeCell [ ^ state isTree ] -{ #category : #'instance creation' } +{ #category : 'instance creation' } FireAutomataCell >> newState [ self bufferState: state newState. ] -{ #category : #pov } +{ #category : 'pov' } FireAutomataCell >> pov [ ^ state color ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataCell >> setOnFire [ self state: (FireAutomataFireState forCell: self) diff --git a/src/FireAutomata-Model/FireAutomataCellState.class.st b/src/FireAutomata-Model/FireAutomataCellState.class.st index 6fcf280..9232653 100644 --- a/src/FireAutomata-Model/FireAutomataCellState.class.st +++ b/src/FireAutomata-Model/FireAutomataCellState.class.st @@ -1,13 +1,14 @@ Class { - #name : #FireAutomataCellState, - #superclass : #Object, + #name : 'FireAutomataCellState', + #superclass : 'Object', #instVars : [ 'cell' ], - #category : #'FireAutomata-Model' + #category : 'FireAutomata-Model', + #package : 'FireAutomata-Model' } -{ #category : #'as yet unclassified' } +{ #category : 'as yet unclassified' } FireAutomataCellState class >> forCell: aCell [ ^ self new @@ -15,43 +16,43 @@ FireAutomataCellState class >> forCell: aCell [ yourself ] -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataCellState >> cell: aCell [ cell := aCell ] -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataCellState >> color [ self subclassResponsibility ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCellState >> isAsh [ ^ false ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCellState >> isEmpty [ ^ false ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCellState >> isFire [ ^ false ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataCellState >> isTree [ ^ false ] -{ #category : #'instance creation' } +{ #category : 'instance creation' } FireAutomataCellState >> newState [ self subclassResponsibility diff --git a/src/FireAutomata-Model/FireAutomataEmptyState.class.st b/src/FireAutomata-Model/FireAutomataEmptyState.class.st index aa95e48..c45b5f6 100644 --- a/src/FireAutomata-Model/FireAutomataEmptyState.class.st +++ b/src/FireAutomata-Model/FireAutomataEmptyState.class.st @@ -1,22 +1,23 @@ Class { - #name : #FireAutomataEmptyState, - #superclass : #FireAutomataCellState, - #category : #'FireAutomata-Model' + #name : 'FireAutomataEmptyState', + #superclass : 'FireAutomataCellState', + #category : 'FireAutomata-Model', + #package : 'FireAutomata-Model' } -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataEmptyState >> color [ ^ Color black ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataEmptyState >> isEmpty [ ^ true ] -{ #category : #'instance creation' } +{ #category : 'instance creation' } FireAutomataEmptyState >> newState [ ^ self diff --git a/src/FireAutomata-Model/FireAutomataFireState.class.st b/src/FireAutomata-Model/FireAutomataFireState.class.st index 3c3e31e..8d5524d 100644 --- a/src/FireAutomata-Model/FireAutomataFireState.class.st +++ b/src/FireAutomata-Model/FireAutomataFireState.class.st @@ -1,44 +1,45 @@ Class { - #name : #FireAutomataFireState, - #superclass : #FireAutomataCellState, + #name : 'FireAutomataFireState', + #superclass : 'FireAutomataCellState', #instVars : [ 'iterationsToBurn' ], - #category : #'FireAutomata-Model' + #category : 'FireAutomata-Model', + #package : 'FireAutomata-Model' } -{ #category : #'default values' } +{ #category : 'default values' } FireAutomataFireState class >> defaultIterationsToBurn [ ^ 3 ] -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataFireState >> color [ ^ Color red ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataFireState >> initialize [ super initialize. iterationsToBurn := self class defaultIterationsToBurn. ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataFireState >> isFire [ ^ true ] -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataFireState >> iterationsToBurn: aNumber [ "Set the number of iterations during which the fire should be burning. After those iterations, the fire will stop and the state will be changed" iterationsToBurn := aNumber ] -{ #category : #'instance creation' } +{ #category : 'instance creation' } FireAutomataFireState >> newState [ iterationsToBurn := iterationsToBurn - 1. diff --git a/src/FireAutomata-Model/FireAutomataModel.class.st b/src/FireAutomata-Model/FireAutomataModel.class.st index 129fdf5..7a3fb38 100644 --- a/src/FireAutomata-Model/FireAutomataModel.class.st +++ b/src/FireAutomata-Model/FireAutomataModel.class.st @@ -1,16 +1,18 @@ Class { - #name : #FireAutomataModel, - #superclass : #CMAbstractModel, + #name : 'FireAutomataModel', + #superclass : 'CMAbstractModel', #instVars : [ 'theCells' ], #classInstVars : [ - 'defaultInit' + 'defaultNumberOfColumns', + 'defaultNumberOfRows' ], - #category : #'FireAutomata-Model' + #category : 'FireAutomata-Model', + #package : 'FireAutomata-Model' } -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataModel class >> aboutThisModel [ ^ 'This is a simple cellular automata (CA) that simulate the diffusion of fire in a forest. @@ -25,208 +27,157 @@ For more information, see: http://cormas.cirad.fr/fr/applica/fireautomata.htm ' ] -{ #category : #default } -FireAutomataModel class >> defaultControl [ - - ^ #step: -] - -{ #category : #accessing } -FireAutomataModel class >> defaultInit [ - - ^ defaultInit ifNil: [ defaultInit := #init58WithFireWithFiremen ] -] - -{ #category : #accessing } -FireAutomataModel class >> defaultInit: anObject [ +{ #category : 'default' } +FireAutomataModel class >> defaultNumberOfColumns [ - defaultInit := anObject + ^ defaultNumberOfColumns ] -{ #category : #default } -FireAutomataModel class >> defaultNumberOfColumns [ +{ #category : 'default' } +FireAutomataModel class >> defaultNumberOfColumns: aNumber [ - ^ 100 + defaultNumberOfColumns := aNumber ] -{ #category : #default } +{ #category : 'default' } FireAutomataModel class >> defaultNumberOfRows [ - ^ 100 + ^ defaultNumberOfRows ] -{ #category : #default } -FireAutomataModel class >> defaultProbes [ +{ #category : 'default' } +FireAutomataModel class >> defaultNumberOfRows: aNumber [ - ^ #( #numberOfTreeCells ) + defaultNumberOfRows := aNumber ] -{ #category : #description } -FireAutomataModel class >> howToRunIt [ - - ^ '1. Prepare the visualisation of the spatial grid. - -1.1 Click on the first icon of the Visualisation area to open the standard spatial grid. - -1.2 In the Topology menu, clicking on the Grid size item opens a window allowing you to choose the number of lines and columns. For example, choose 30 * 30. - -1.3 Check the border condition: Topology -> Grid boundaries -> closed. - -1.4 Right-click within the spatial grid window to select the pov view for FireAutomata_Cell . - -1.5 To display the legend of this viewpoint: Tools -> Display legends. - - -2. Prepare the initial spatial grid - -2.1 Click on the Initialize button of the Simulation area. - -2.2 Select the init53 and stepSynchronously: methods, then validate by clicking on Apply and close. - -2.3 From the spatial grid menu, use Tools -> Click to... -> Change attribute... -> state, enter fire and validate. The cursor takes a new shape. Click on a cell to change manually its state to fire, then switch back to the mouse select mode with Tools -> Click to... -> Select +{ #category : 'initialization' } +FireAutomataModel class >> initializeParameters [ - -3. Run the model - -3.1 Enter 50 in the Final time input field of the Simulation area. - -3.2 Click on the Run button of the Simulation area. - - -4. Have a look at the charts - -4.1 Click on the third icon of the Visualisation area to open the charts window. - - - -5. Run alternative versions of the model - -5.1 Select the init58 and stepSynchronously: methods, then run the model again. - -5.2 Select the init53 and stepAsynchronously: methods, then run the model again.' + super initializeParameters. + defaultNumberOfColumns := 100. + defaultNumberOfRows := 100 ] -{ #category : #init } +{ #category : 'init' } FireAutomataModel >> init53 [ + self initCommon. - self theCells do: [ :cell | cell generateTreeWithProbability: 0.53 ]. + theCells do: [ :cell | cell generateTreeWithProbability: 0.53 ]. ] -{ #category : #init } +{ #category : 'init' } FireAutomataModel >> init53WithFire [ + self init53. - self pickCell setOnFire + self pickRandomCell setOnFire ] -{ #category : #init } +{ #category : 'init' } FireAutomataModel >> init58 [ + self initCommon. - self theCells do: [ :cell | cell generateTreeWithProbability: 0.58 ]. + theCells do: [ :cell | cell generateTreeWithProbability: 0.58 ]. ] -{ #category : #init } +{ #category : 'init' } FireAutomataModel >> init58WithColumnOfFire [ + self init58. self setFirstColumnOnFire. ] -{ #category : #init } +{ #category : 'init' } FireAutomataModel >> init58WithFire [ + self init58. - self pickCell setOnFire. + self pickRandomCell setOnFire. ] -{ #category : #init } +{ #category : 'init' } FireAutomataModel >> init58WithMultipleFires [ + | numberOfFires | numberOfFires := 3. self init58. - self theCells do: #init58WithMultipleFires. - numberOfFires timesRepeat: [ self pickCell setOnFire ] + numberOfFires timesRepeat: [ self pickRandomCell setOnFire ] ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataModel >> initCommon [ self - createGridLines: self class defaultNumberOfRows - columns: self class defaultNumberOfColumns + createGridNumberOfRows: self class defaultNumberOfRows + numberOfColumns: self class defaultNumberOfColumns neighbourhood: 4 - closed: true. - - self displayPov: #pov of: FireAutomataCell. + closed: true ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataModel >> initialize [ super initialize. theCells := OrderedCollection new. ] -{ #category : #probes } +{ #category : 'probes' } FireAutomataModel >> numberOfAshCells [ - - ^ self theCells count: [ :cell | cell isAshCell ] + + ^ theCells count: [ :cell | cell isAshCell ] ] -{ #category : #probes } +{ #category : 'probes' } FireAutomataModel >> numberOfEmptyCells [ - - ^ self theCells count: [ :cell | cell isEmptyCell ] + + ^ theCells count: [ :cell | cell isEmptyCell ] ] -{ #category : #probes } +{ #category : 'probes' } FireAutomataModel >> numberOfFireCells [ - - ^ self theCells count: [ :cell | cell isFireCell ] + + ^ theCells count: [ :cell | cell isFireCell ] ] -{ #category : #probes } +{ #category : 'probes' } FireAutomataModel >> numberOfTreeCells [ - - ^ self theCells count: [ :cell | cell isTreeCell ] + + ^ theCells count: [ :cell | cell isTreeCell ] ] -{ #category : #initialization } +{ #category : 'initialization' } FireAutomataModel >> setFirstColumnOnFire [ | numberOfRows numberOfColumns firstCellInRow | - numberOfRows := self spaceModel line. - numberOfColumns := self spaceModel column. + numberOfRows := self spaceModel numberOfRows. + numberOfColumns := self spaceModel numberOfColumns. 1 to: numberOfRows do: [ :rowIndex | firstCellInRow := self theCells at: (rowIndex - 1) * numberOfColumns + 1. firstCellInRow setOnFire ]. ] -{ #category : #control } +{ #category : 'control' } FireAutomataModel >> step: anObject [ - + self stepSynchronously: anObject ] -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataModel >> theCells [ - + + ^ theCells ] - -{ #category : #accessing } -FireAutomataModel >> theCells: anObject [ - - theCells := anObject -] diff --git a/src/FireAutomata-Model/FireAutomataTreeState.class.st b/src/FireAutomata-Model/FireAutomataTreeState.class.st index f3c5aed..f6fd138 100644 --- a/src/FireAutomata-Model/FireAutomataTreeState.class.st +++ b/src/FireAutomata-Model/FireAutomataTreeState.class.st @@ -1,22 +1,23 @@ Class { - #name : #FireAutomataTreeState, - #superclass : #FireAutomataCellState, - #category : #'FireAutomata-Model' + #name : 'FireAutomataTreeState', + #superclass : 'FireAutomataCellState', + #category : 'FireAutomata-Model', + #package : 'FireAutomata-Model' } -{ #category : #accessing } +{ #category : 'accessing' } FireAutomataTreeState >> color [ ^ Color green ] -{ #category : #testing } +{ #category : 'testing' } FireAutomataTreeState >> isTree [ ^ true ] -{ #category : #'instance creation' } +{ #category : 'instance creation' } FireAutomataTreeState >> newState [ ^ (cell neighbourhood anySatisfy: [ :neighbourCell | neighbourCell state isFire ]) diff --git a/src/FireAutomata-Model/package.st b/src/FireAutomata-Model/package.st index 7aed6aa..8789271 100644 --- a/src/FireAutomata-Model/package.st +++ b/src/FireAutomata-Model/package.st @@ -1 +1 @@ -Package { #name : #'FireAutomata-Model' } +Package { #name : 'FireAutomata-Model' }