Docsity

Algorithm Pseudocode for Cellular Automaton Simulation, Study notes of Algorithms and Programming

Toggle sidebar
bg1
A Appendix: Algorithm Pseudocode
Algorithm 1: Main
P arameterS et โ†โˆ’ CommandLineArg uments
InitialS izeDistribution โ†โˆ’ READ(โ€œSizeDistribution.txt00)
CreateW indow (P arameterSet(โ€œW idth00 ), P arameter Set(โ€œHeight00))
P laceCel ls()
SimulationT ime โ†โˆ’ 0
MainLoop()
Algorithm 2: PlaceCells
for Nโ†โˆ’ BiggestAggregateSiz e to 1do
//NumberOfAggregates[1..MaxSize] has the number of
//aggregates of sizes 1..MaxSize respectively
for Mโ†โˆ’ NumberOf Agg regates[N]to 1do
Randomly pick aggregate of size N from file
repeat
Choose random coordinates
until Aggregate can be placed without intersection
Algorithm 3: MainLoop
while SimulationT ime < 24hr do
if Divide? == T rue then
foreach Cell in C ELLS do
if Cell.Quiescent == F alse And Cell.isDying == F alse then
Divide(C ell)
CalculateGradient()
CellMove()
Aggreg ateM ove()
DetectCollisions()
Age()
if SaveS tate? == T rue then
Emit()
SaveS tate()
SimulationT ime+ = S imulationStepT ime
pf3
pf4

Partial preview of the text

Download Algorithm Pseudocode for Cellular Automaton Simulation and more Study notes Algorithms and Programming in PDF only on Docsity!

A Appendix: Algorithm Pseudocode

Algorithm 1: Main

P arameterSet โ†โˆ’ CommandLineArguments

InitialSizeDistribution โ†โˆ’ READ(โ€œSizeDistribution.txtโ€ฒโ€ฒ)

CreateW indow(P arameterSet(โ€œW idthโ€ฒโ€ฒ), P arameterSet(โ€œHeightโ€ฒโ€ฒ))

P laceCells()

SimulationT ime โ†โˆ’ 0

M ainLoop()

Algorithm 2: PlaceCells

for N โ†โˆ’ BiggestAggregateSize to 1 do

//NumberOfAggregates[1..MaxSize] has the number of

//aggregates of sizes 1..MaxSize respectively

for M โ†โˆ’ N umberOf Aggregates[N ] to 1 do

Randomly pick aggregate of size N from file

repeat

Choose random coordinates

until Aggregate can be placed without intersection

Algorithm 3: MainLoop

while SimulationT ime < 24 hr do

if Divide? == T rue then

foreach Cell in CELLS do

if Cell.Quiescent == F alse And Cell.isDying == F alse then

Divide(Cell)

CalculateGradient()

CellM ove()

AggregateM ove()

DetectCollisions()

Age()

if SaveState? == T rue then

Emit()

SaveState()

SimulationT ime+ = SimulationStepT ime

Algorithm 4: Divide

Input: Cell C PDividing = getK 3 (C.N umAttachments) โˆ— PP rolif eration //Division occurs with probability PDividing if C decides to divide then Dir โ†โˆ’ direction chosen randomly between 1 to 6 (Figure 3) while direction chosen is occupied do Dir = (Dir + 1) M od 6 Put a new cell CN at (C.center + Dir) C.Age โ†โˆ’ CN .Age โ†โˆ’ 0 C.quiescent โ†โˆ’ CN .quiescent โ†โˆ’ T rue CN separates from C with probability PSeparation

Algorithm 5: CalculateGradient

for C 1 โ†โˆ’ 1 to N U M CELLS do for C 2 โ†โˆ’ C 1 + 1 to N U M CELLS do if CELLS[C 1 ] And CELLS[C 2 ] do not belong to same aggregate then Dist โ†โˆ’ Distance between CELLS[C 1 ] and CELLS[C 2 ] if Dist โ‰ค CELLS[C 2 ].RM ax then CELLS[C 1 ].N eighborSet.add(C 2 ) if Dist โ‰ค CELLS[C 1 ].RM ax then CELLS[C 2 ].N eighborSet.add(C 1 )

foreach Cell in CELLS do Initialize values of all receptors to zero foreach OtherCell in Cell.N eighborSet do foreach Ri in Cell.Receptors do Dist โ†โˆ’ Distance between OtherCell and Ri Ri.V alue+ = (OtherCell.k 1 โˆ— C 0 )/(1 + Dist) Cell.Gradient โ†โˆ’ Calculate gradient from Equation 3 Cell.GradientAngle โ†โˆ’ Calculate theta from Equation 3

Algorithm 8: DetectCollisions

for C 1 โ†โˆ’ 1 to N U M CELLS do for C 2 โ†โˆ’ C 1 + 1 to N U M CELLS do if CELLS[C 1 ] and CELLS[C 2 ] do not belong to same aggregate then Dist โ†โˆ’ Distance between CELLS[C 1 ] and CELLS[C 2 ] if Dist < 2 โˆ— CellRadius then Aggregate 1 โ†โˆ’ CELLS[C 1 ].AggregateN umber Aggregate 2 โ†โˆ’ CELLS[C 2 ].AggregateN umber if Both cells are single then Form a new doublet else if Only one is single then //Assume CELLS[C 2 ] is single CELLS[C 2 ] joins Aggregate 1 else //Assume Aggregate1 has more cells All members of Aggregate2 joins Aggregate 1 Aggregate2 is destroyed CELLS[C 1 ].N umberOf Attachments + + CELLS[C 2 ].N umberOf Attachments + +

Algorithm 9: Age

foreach Cell in CELLS do Cell.Age+ = SimulationStepT ime if Cell.Quiescent = T rue And Cell.Age >= QuiescentT ime then Cell.Quiescent = F alse else if Cell is single And Cell.Age >= TApoptosis then Cell.isDying = T rue Cell dies with probability 1 โˆ’ PLive (Figure 2:Right) if Cell dies then Remove Cell from CELLS

Algorithm 10: Emit

foreach GridP oint (x, y) do ChemoGrid[x][y] = 0 foreach Cell in CELLS do foreach GridP oint (x, y) within Cell.RM ax distance from Cell do Dist โ†โˆ’ Distance between Cell and GridP oint ChemoGrid[x][y]+ = (Cell.k 1 โˆ— C 0 )/(1 + Dist)