This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RING of R-Rows C-cols in the center of width w cells | |
seedCenterRing <- function(r, c, wide){ | |
for(x in as.integer((areaW-c)/2): as.integer((areaW + c)/2)){ | |
for(y in as.integer((areaH-r)/2): as.integer((areaH + r)/2)){ | |
area_df[x,y] <<- 1 | |
} | |
} | |
#scoop out the inner ring | |
for(x in as.integer((areaW-c)/2 + wide): as.integer((areaW + c)/2 - wide)){ | |
for(y in as.integer((areaH-r)/2+wide): as.integer((areaH + r)/2- wide )){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# R-Rows C-cols in the center | |
seedAreaCenter <- function(r, c){ | |
for(x in as.integer((areaW-c)/2): as.integer((areaW + c)/2)){ | |
for(y in as.integer((areaH-r)/2): as.integer((areaH + r)/2)){ | |
area_df[x,y] <<- 1 | |
} | |
} | |
} | |
#Seed a central area and let it grow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# w-cols to the R and L of center column | |
seedColumns <- function(c, w){ | |
startLCol = as.integer( (areaW-c) / 2 ) | |
startRCol = as.integer( (areaW+c) / 2 ) | |
for(y in 1:areaH) { | |
clist = c((startLCol-w):startLCol, startRCol:(startRCol+w)) | |
lapply(clist, function(x) area_df[x,y] <<- 1) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original Code by Matt Asher for statisticsblog.com | |
# Feel free to modify and redistribute, but please keep this notice | |
#Modifications by Ram Narasimhan | |
# @ramnarasimhan | |
source("~/RStats/simFunctions.R") | |
library(ggplot2) | |
library(plyr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
store_iteration_stats<- function(kNumSettlers, found.home, max.look.around) { | |
#how many settlers found homes | |
print(c(found.home," settled out of ", kNumSettlers, (found.home/kNumSettlers)*100, "%" ) ) | |
#avg # of steps per new settler | |
print(c("num of look arounds max'ed:", max.look.around)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Are any of the 4 direct N E W S adjacent cells occupied? | |
isAnyOfNEWSCellsOccupied <- function(m,n) { | |
canOccupy <- FALSE | |
NEWSdir = c(2,4,5,7) | |
#traverse the vector of 4 elements | |
for(k in 1:4) { | |
xCheck = m + adjacells[NEWSdir[k],1] | |
yCheck = n + adjacells[NEWSdir[k],2] | |
if(!(outOfBounds(xCheck, yCheck))) { | |
if(area_df[xCheck, yCheck] > 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Are any of the 4 diagonally adjacent cells occupied? | |
isAnyDiagNeighboringCellOccupied <- function(m,n) { | |
canOccupy <- FALSE | |
diag.dir = c(1,3,6,8) | |
#traverse the vector of 4 elements | |
for(k in 1:4) { | |
xCheck = m + adjacells[diag.dir[k],1] | |
yCheck = n + adjacells[diag.dir[k],2] | |
if(!(outOfBounds(xCheck, yCheck))) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make multiple runs (Replication of simulation) and take the average of stats | |
st <- data.frame() | |
st_row<- vector() | |
for(i in 1:kNumReplications) { | |
area_df <- resetIteration() | |
seedAreaWithPioneers(numPioneers,seeding.opt) | |
simstats <- accommodateSettlers(kNumSettlers, settling.option) | |
found.home <- simstats[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
store_iteration_stats<- function(iter, kNumSettlers, found.home, max.look.around) { | |
#how many settlers found homes | |
perSet <- (found.home/kNumSettlers) * 100 | |
print(c(found.home," settled out of ", kNumSettlers, perSet, "%" ) ) | |
#avg # of steps per new settler | |
print(c("num of Settlers who hit max look around:", max.look.around)) | |
return(c(iter, found.home, kNumSettlers, perSet)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Genotype AA = 1, Aa = 2 and aa = 3 | |
# Gamete A =1 and a = 0 | |
#Uniformly distribute AA, Aa and aa | |
start.pop <- sample(1:3, kStartPop, replace=TRUE) |
OlderNewer