-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment_initialization.R
50 lines (44 loc) · 2.07 KB
/
environment_initialization.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#DUMMY LIST OF INSTRUCTIONS
DummyList <- list(
DummyInstruction0 = function(x) {return(x)},
DummyInstruction1 = function(x) {return(paste(x, "b", sep=""))},
DummyInstruction2 = function(x) {return(paste(x, "a", sep=""))},
DummyInstruction3 = function(x) {return(paste(x, "o", sep=""))}
)
#THE LIST CONTAINING WRAPPERS TO THE FUNDAMENTAL INSTRUCTIONS
InstructionsList <- lapply(DummyList, function(x) {
Instruction_Class$new(instruction=x)
}
)
#names <- paste ("Fun",1:3, sep="")
#invisible(mapply(function(x,y) { x$name <- y}, InstructionsList,names))
names(InstructionsList) = paste("Instruction", seq_along(DummyList), sep="")
#DEFINITION OF THE ALTERNATIVES FOR EACH INSTRUCTION
InstructionsList[[1]]$set_alt(InstructionsList[-1])
InstructionsList[[2]]$set_alt(InstructionsList[-2])
InstructionsList[[3]]$set_alt(InstructionsList[-3])
InstructionsList[[4]]$set_alt(InstructionsList[-4])
#THE FITNESS FUNCTION
fit_ley <- function(s) {
require("RecordLinkage")
return(levenshteinSim(s,"baobab"))
}
#THE HAPLOTYPE
MyHAP <- Haplotype_class$new(HAP=sample(InstructionsList,6, replace=T),
mutated=F
)
#THE ENGINE
MyEngine <- Engine_Class$new(population=list(),
mutation.rate=0.1,
fitness.function=fit_ley,
step = 1L
)
#THE ENGINE'S POPULATION
MyEngine$population <- lapply(rep(NA,200), function(x) {Individual_Class$new(
genome=MyHAP,
age=0L,min.fit=Inf,
fit.sum=0L,
local.engine=MyEngine
)
}
)