[Ruler-commits] r14 - pkg

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 20 00:29:45 CEST 2012


Author: merysionek
Date: 2012-07-20 00:29:45 +0200 (Fri, 20 Jul 2012)
New Revision: 14

Added:
   pkg/New.R
Modified:
   pkg/.RData
   pkg/.Rhistory
Log:
a new approach - finally managed to figure out how to combine rules :)

Modified: pkg/.RData
===================================================================
(Binary files differ)

Modified: pkg/.Rhistory
===================================================================
--- pkg/.Rhistory	2012-07-17 15:27:05 UTC (rev 13)
+++ pkg/.Rhistory	2012-07-19 22:29:45 UTC (rev 14)
@@ -1,512 +1,512 @@
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99), 1,replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99), replace = T) # generating a constant for functions that would use it
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99), replace = T)
-)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99)), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99),99), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99),0.7), replace = T)
-length(c(1:99,0))
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:99,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/99,99),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T)
-generate
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(f,s)
-fun<-sample(rulenames,1) #generating function from the list of functions
-generate(iii,fun,c)
-fun
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(f,s)
-fun<-eval(parse(text=sample(rulenames,1))) #generating function from the list of functions
-generate(iii,fun,c)
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-eval(parse(text=sample(rulenames,1))) #generating function from the list of functions and evaluating it by its name
-generate(iii,fun,c)
-iii
-fun
-f
-s
-c
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-generate(iii,eval(parse(text=fun),c)
-)
-fun
-s
-f
-c
-p<-generate(iii,eval(parse(text=fun),c))
-p
-as.numeric(unlist(p))
-as.numeric(unlist(p))
-p<-as.numeric(unlist(p))
-p
-p[1]
-p[2]
-p<-generate(iii,eval(parse(text=fun),c))
-p
-unlist(p)
-as.numeric(unlist(p))
-as.vector(unlist(p))
-as.vector(unlist(p))[1]
-help(unlist)
-as.vector(unlist(p),recursive=F)
-as.vector(unlist(p),recursive=FALSE)
-print(unlist(p),collapse="")
-help(print)
-paste(unlist(p),collapse="")
-as.numeric(paste(unlist(p),collapse=""))
-paste(unlist(p),collapse="")
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="")
-seq1
-seq2
-as.numeric(seq2)
-as.float(seq2)
-typeof(seq2)
-seq2
-as.long(seq2)
-long(seq2)
-seq2
-help(typeof)
-as.numeric(seq2)
-numeric(seq2)
-help(numeric)
-numeric
-as.integer(seq2)
-seq2
-is.double(as.numeric(seq2))
-is.real(as.numeric(seq2))
-seq2
-typeof(seq2)
-g=123325698888888888233556
-g
-typeof(g)
-g<-as.numeric(seq2)
-g
-g==7893105111114120
-g==7893105111114121
-g==7893105111114124
-g==789310511111124
-seq2
-seq1
-seq3<-as.numeric(seq2)
-seq2
-seq3
-newtree <- function(firstval,inc) {
-m <- matrix(rep(NA,inc*3),nrow=inc,ncol=3)
-m[1,3] <- firstval
-return(list(mat=m,nxt=2,inc=inc))
 }
-ins <- function(hdidx,tr,newval) {
-dir <- if (newval <= tr$mat[hdidx,3]) 1 else 2 # which direction will this new node go, left or right?
-# if null link in that direction, place the new node here, otherwise
-# recurse
-if (is.na(tr$mat[hdidx,dir])) {
-newidx <- tr$nxt # where new node goes
-if (tr$nxt == nrow(tr$mat) + 1) {# check for room to add a new element
-tr$mat <- rbind(tr$mat, matrix(rep(NA,tr$inc*3),nrow=tr$inc,ncol=3))
+#[1] RULE 1 - ADDING A CONSTANT
+setClass("AddConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="AddConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal+y)
+})
+#[2] RULE 2 - MULTIPLYING BY A CONSTANT
+setClass("MultConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="MultConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal*y)
+})
+#EXECUTING RULES REFERING TO SINGLE ARGUMENT
+setMethod("wylicz",signature=c(x="SingleRule", y="numeric"), #both [1] and [2] inherit from class 'SingleRule'
+function(x, y){
+result<-y
+if(!is.null(x at previousRule)){
+result <- wylicz(x at previousRule,result)
 }
-tr$mat[newidx,3] <- newval # insert new tree node
-tr$mat[hdidx,dir] <- newidx# link to the new node
-tr$nxt <- tr$nxt + 1 # ready for next insert
-return(tr)
-} else tr <- ins(tr$mat[hdidx,dir],tr,newval)
+return(wyliczSpecific(x,result))
+})
+##------------------------------------------------DoubleRules---------------------------
+setClass("DoubleRule", representation = representation(firstRule="SingleRule", secondRule="SingleRule"),
+S3methods=TRUE)
+setClass("AddDoubleRule", contains="DoubleRule",S3methods=TRUE)
+setClass("MultDoubleRule",contains="DoubleRule",S3methods=TRUE)
+wyliczDoubleSpecific <- function(x,y,z){return(18)}
+wyliczDouble <- function(x,y,z){return(17)}
+setMethod("wyliczDoubleSpecific",signature(x="AddDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y+z)
+})
+setMethod("wyliczDoubleSpecific",signature(x="MultDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y*z)
+})
+setMethod("wyliczDouble",signature(x="DoubleRule", y="numeric", z="numeric"),
+function(x, y, z){
+firstArg <- y
+secondArg <-z
+if(!is.null(x at firstRule)){
+firstArg <- wylicz(x at firstRule,firstArg)
 }
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(seq2)
+if(!is.null(x at secondRule)){
+secondArg <- wylicz(x at secondRule,secondArg)
 }
+return(wyliczDoubleSpecific(x,firstArg, secondArg))
+})
+##test
+p<-new("AddConstSingleRule", constantVal=6)
+q<-new("MultConstSingleRule", constantVal=10, previousRule=p)
+inherits(p,"SingleRule")
+inherits(q,"SingleRule")
+wylicz(p,4)
+wylicz(q,4)
+r<-new("AddDoubleRule")
+inherits(r,"DoubleRule")
+wyliczDouble(r,3,2)
+s<-new("MultDoubleRule", firstRule=p)
+wyliczDouble(s,2,2)
+# tu masz podwó jne reguły też
+# pobaw się i zobacz czy rozumiesz
+##------------------------------SingleRules----------------------------
+#VIRTUAL CLASS FOR RULES USING SINGLE ARGUMENTS
+setClass("SingleRule",
+representation = representation(previousRule="SingleRule"),
+S3methods=TRUE)
+wyliczSpecific <- function(x,y){
+return(y)
 }
-createSequence()
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(seq2)
+setMethod("wyliczSpecific",signature(x="SingleRule", y="numeric"),
+function(x,y){
+return(y)
+})
+wylicz <- function(x,y){
+return(y)
 }
+#[1] RULE 1 - ADDING A CONSTANT
+setClass("AddConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="AddConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal+y)
+})
+#[2] RULE 2 - MULTIPLYING BY A CONSTANT
+setClass("MultConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="MultConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal*y)
+})
+#EXECUTING RULES REFERING TO SINGLE ARGUMENT
+setMethod("wylicz",signature(x="SingleRule", y="numeric"), #both [1] and [2] inherit from class 'SingleRule'
+function(x, y){
+result<-y
+if(!is.null(x at previousRule)){
+result <- wylicz(x at previousRule,result)
 }
-createSequence()
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(seq1)
+return(wyliczSpecific(x,result))
+})
+##------------------------------------------------DoubleRules---------------------------
+setClass("DoubleRule", representation = representation(firstRule="SingleRule", secondRule="SingleRule"),
+S3methods=TRUE)
+setClass("AddDoubleRule", contains="DoubleRule",S3methods=TRUE)
+setClass("MultDoubleRule",contains="DoubleRule",S3methods=TRUE)
+wyliczDoubleSpecific <- function(x,y,z){return(18)}
+wyliczDouble <- function(x,y,z){return(17)}
+setMethod("wyliczDoubleSpecific",signature(x="AddDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y+z)
+})
+setMethod("wyliczDoubleSpecific",signature(x="MultDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y*z)
+})
+setMethod("wyliczDouble",signature(x="DoubleRule", y="numeric", z="numeric"),
+function(x, y, z){
+firstArg <- y
+secondArg <-z
+if(!is.null(x at firstRule)){
+firstArg <- wylicz(x at firstRule,firstArg)
 }
+if(!is.null(x at secondRule)){
+secondArg <- wylicz(x at secondRule,secondArg)
 }
-createSequence()
-createSequence()
-createSequence()
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(paste("generation",i,"is\n",seq1))
+return(wyliczDoubleSpecific(x,firstArg, secondArg))
+})
+##test
+p<-new("AddConstSingleRule", constantVal=6)
+q<-new("MultConstSingleRule", constantVal=10, previousRule=p)
+inherits(p,"SingleRule")
+inherits(q,"SingleRule")
+wylicz(p,4)
+wylicz(q,4)
+r<-new("AddDoubleRule")
+inherits(r,"DoubleRule")
+wyliczDouble(r,3,2)
+s<-new("MultDoubleRule", firstRule=p)
+wyliczDouble(s,2,2)
+# tu masz podwó jne reguły też
+# pobaw się i zobacz czy rozumiesz
+##------------------------------SingleRules----------------------------
+#VIRTUAL CLASS FOR RULES USING SINGLE ARGUMENTS
+setClass("SingleRule",
+representation = representation(previousRule="SingleRule"),
+S3methods=TRUE)
+wyliczSpecific <- function(x,y){
+return(y)
 }
+setMethod("wyliczSpecific",signature(x="SingleRule", y="numeric"),
+function(x,y){
+return(y)
+})
+#[1] RULE 1 - ADDING A CONSTANT
+setClass("AddConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="AddConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal+y)
+})
+#[2] RULE 2 - MULTIPLYING BY A CONSTANT
+setClass("MultConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="MultConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal*y)
+})
+#EXECUTING RULES REFERING TO SINGLE ARGUMENT
+wylicz <- function(x,y){
+return(y)
 }
-createSequence()
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(paste("generation",i,"is/n",seq1))
+setMethod("wylicz",signature(x="SingleRule", y="numeric"), #both [1] and [2] inherit from class 'SingleRule'
+function(x, y){
+result<-y
+if(!is.null(x at previousRule)){ #there are some rules nested inside 'x'
+result <- wylicz(x at previousRule,result) #
 }
+return(wyliczSpecific(x,result))
+})
+##------------------------------------------------DoubleRules---------------------------
+setClass("DoubleRule", representation = representation(firstRule="SingleRule", secondRule="SingleRule"),
+S3methods=TRUE)
+setClass("AddDoubleRule", contains="DoubleRule",S3methods=TRUE)
+setClass("MultDoubleRule",contains="DoubleRule",S3methods=TRUE)
+wyliczDoubleSpecific <- function(x,y,z){return(18)}
+wyliczDouble <- function(x,y,z){return(17)}
+setMethod("wyliczDoubleSpecific",signature(x="AddDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y+z)
+})
+setMethod("wyliczDoubleSpecific",signature(x="MultDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y*z)
+})
+setMethod("wyliczDouble",signature(x="DoubleRule", y="numeric", z="numeric"),
+function(x, y, z){
+firstArg <- y
+secondArg <-z
+if(!is.null(x at firstRule)){
+firstArg <- wylicz(x at firstRule,firstArg)
 }
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(paste("generation",i,"is",seq1))
+if(!is.null(x at secondRule)){
+secondArg <- wylicz(x at secondRule,secondArg)
 }
+return(wyliczDoubleSpecific(x,firstArg, secondArg))
+})
+##test
+p<-new("AddConstSingleRule", constantVal=6)
+q<-new("MultConstSingleRule", constantVal=10, previousRule=p)
+inherits(p,"SingleRule")
+inherits(q,"SingleRule")
+wylicz(p,4)
+wylicz(q,4)
+r<-new("AddDoubleRule")
+inherits(r,"DoubleRule")
+wyliczDouble(r,3,2)
+s<-new("MultDoubleRule", firstRule=p)
+wyliczDouble(s,2,2)
+# tu masz podwó jne reguły też
+# pobaw się i zobacz czy rozumiesz
+##------------------------------SingleRules-------------------------------------------------
+#VIRTUAL CLASS FOR RULESOPERATING ON SINGLE ARGUMENTS
+setClass("SingleRule",
+representation = representation(previousRule="SingleRule"),
+S3methods=TRUE)
+wyliczSpecific <- function(x,y){
+return(y)
 }
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(paste("generation",i,"is"/n,seq1,))
+setMethod("wyliczSpecific",signature(x="SingleRule", y="numeric"),
+function(x,y){
+return(y)
+})
+#[1] RULE 1 - ADDING A CONSTANT
+setClass("AddConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="AddConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal+y)
+})
+#[2] RULE 2 - MULTIPLYING BY A CONSTANT
+setClass("MultConstSingleRule",
+contains="SingleRule",
+representation(constantVal="numeric"),
+S3methods=TRUE)
+setMethod("wyliczSpecific",signature(x="MultConstSingleRule", y="numeric"),
+function(x,y){
+return(x at constantVal*y)
+})
+#EXECUTING RULES REFERING TO SINGLE ARGUMENT
+wylicz <- function(x,y){
+return(y)
 }
+setMethod("wylicz",signature(x="SingleRule", y="numeric"), #both [1] and [2] inherit from class 'SingleRule'
+function(x, y){
+result<-y
+if(!is.null(x at previousRule)){ # if there are some rules nested inside 'x'
+result <- wylicz(x at previousRule,result)
 }
-createSequence()
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(paste("generation",i,"is"\n,seq1,))
+return(wyliczSpecific(x,result)) # if there are no more nested functions, execute
+})
+##------------------------------------------------DoubleRules-------------------------------
+#VIRTUAL CLASS FOR RULES OPERATING ON TWO ARGUMENTS
+setClass("DoubleRule", representation = representation(firstRule="SingleRule", secondRule="SingleRule"),
+S3methods=TRUE)
+wyliczDoubleSpecific <- function(x,y,z){stop ("No method to calculate it.")} #throw a mistake
+wyliczDouble <- function(x,y,z){stop ("No function to execute this.")} #throw a mistake
+#[1] ADD TWO PREVIOUS EXPRESSIONS
+setClass("AddDoubleRule", contains="DoubleRule",S3methods=TRUE)
+setMethod("wyliczDoubleSpecific",signature(x="AddDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y+z)
+})
+#[2] MULTIPLY TWO PREVIOUS EXPRESSIONS
+setClass("MultDoubleRule",contains="DoubleRule",S3methods=TRUE)
+setMethod("wyliczDoubleSpecific",signature(x="MultDoubleRule", y="numeric", z="numeric"),
+function(x,y,z){
+return(y*z)
+})
+#EXECUTING RULES OPERATING ON TWO ARGUMENTS
+setMethod("wyliczDouble",signature(x="DoubleRule", y="numeric", z="numeric"),
+function(x, y, z){
+firstArg <- y
+secondArg <-z
+if(!is.null(x at firstRule)){
+firstArg <- wylicz(x at firstRule,firstArg)
 }
+if(!is.null(x at secondRule)){
+secondArg <- wylicz(x at secondRule,secondArg)
 }
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-print(paste("generation",i,"is \n",seq1,))
+return(wyliczDoubleSpecific(x,firstArg, secondArg))
+})
+##--------------------------test--------------------------------------------------------------
+p<-new("AddConstSingleRule", constantVal=6)
+q<-new("MultConstSingleRule", constantVal=10, previousRule=p)
+inherits(p,"SingleRule")
+inherits(q,"SingleRule")
+wylicz(p,4)
+wylicz(q,4)
+r<-new("AddDoubleRule")
+inherits(r,"DoubleRule")
+wyliczDouble(r,3,2)
+s<-new("MultDoubleRule", firstRule=p)
+wyliczDouble(s,2,2)
+# tu masz podwó jne reguły też
+# pobaw się i zobacz czy rozumiesz
+wyliczDouble <- function(x,y,z){stop ("No function to execute this.")} #throw a mistake
+setMethod("wyliczDouble",signature(x="DoubleRule", y="numeric", z="numeric"),
+function(x, y, z){
+firstArg <- y
+secondArg <-z
+if(!is.null(x at firstRule)){
+firstArg <- wylicz(x at firstRule,firstArg)
 }
+if(!is.null(x at secondRule)){
+secondArg <- wylicz(x at secondRule,secondArg)
 }
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-createSequence()
-print("jvuviiv \n nbubobob")
-print(paste("jvuviiv"," \n","nbubobob"))
-print(paste("jvuviiv"," /n","nbubobob"))
-cat("hello\nworld\n")
-createSequence<-function(n=6){          #a function to creates n sequences (default number of sequences is 6)
-for(i in 1:n){
-f<-sample(c(1:99), 1,replace = T) # argument 'first' for object from class "Item" generated from between 1 and 99. All numers are chosen at the same probability
-s<-sample(c(1:99,0), 1, prob = c(rep(0.3/99,99),0.7), replace = T) # argument 'second' for object from class "Item" generated from between . Zero should be chosen with greater probability
-c<-sample(c(1:50,0), 1,prob = c(rep(0.3/50,50),0.7), replace = T) # generating a constant for functions that would use it
-iii<-createItem(first=f,second=s) #creating an item named 'iii' where first=f and second=s
-fun<-sample(rulenames,1) #generating function from the list of functions and evaluating it by its name
-seq1<-generate(iii,eval(parse(text=fun),c)) #generating the random sequence
-seq2<-paste(unlist(seq1),collapse="") #transorming a sequence into a single number (that can be stored in a tree)
-seq3<-as.numeric(seq2) # in this form I will save the sequence in a tree
-cat(paste("generation",i,"is \n",seq1,))
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/ruler -r 14


More information about the Ruler-commits mailing list