[Ruler-commits] r25 - pkg

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 31 12:06:59 CEST 2012


Author: merysionek
Date: 2012-07-31 12:06:58 +0200 (Tue, 31 Jul 2012)
New Revision: 25

Modified:
   pkg/New.R
Log:
Added Philipp's double rules

Modified: pkg/New.R
===================================================================
--- pkg/New.R	2012-07-31 09:46:41 UTC (rev 24)
+++ pkg/New.R	2012-07-31 10:06:58 UTC (rev 25)
@@ -159,10 +159,37 @@
             return(y-z)
           })
 
+#[4] DIVIDING TWO NUMBERS (Philipp)
 
+setClass("DivDoubleRule",contains="DoubleRule",S3methods=TRUE)
 
+setMethod("calculateDoubleSpecific", 
+          signature(x="DivDoubleRule", y="numeric", z="numeric"),
+          function(x,y,z){
+            return(y%/%z)
+          })
 
+#[5] MODULO (Philipp)
 
+setClass("ModuloDoubleRule",contains="DoubleRule",S3methods=TRUE)
+
+setMethod("calculateDoubleSpecific", 
+          signature(x="ModuloDoubleRule", y="numeric", z="numeric"),
+          function(x,y,z){
+            return(y%%z)
+          })
+
+#[6] EXPONENTIAL FUNCTION (Philipp)
+setClass("ExpDoubleRule", contains="DoubleRule",S3methods=TRUE)
+
+setMethod("calculateDoubleSpecific", 
+          signature(x="ExpDoubleRule", y="numeric", z="numeric"),
+          function(x,y,z){
+            return(y^z)
+          })
+
+
+
 #EXECUTING RULES OPERATING ON TWO ARGUMENTS
 
 #calculate <- function(x,y,z){stop ("No function to execute this.")} #throw a mistake, because you should execute just single functions contained by cladd DoubleRule
@@ -256,18 +283,11 @@
 #-------------------------------------------------------------------------------------------
 
 #a list of single rules 
-singleRules<-list(list(ruleName="IdenSingleRule",argumentName=c("previousRule"), argumentType= c("SingleRule")),
-list(ruleName="AddConstSingleRule",argumentName=c("previousRule","constantVal"), argumentType= c("SingleRule","numeric")),
-list(ruleName="MultConstSingleRule",argumentName=c("previousRule","constantVal"), argumentType= c("SingleRule","numeric")),
-list(ruleName="SubsConstSingleRule",argumentName=c("previousRule","constantVal"), argumentType= c("SingleRule","numeric")),
-list(ruleName="DigSumSingleRule",argumentName=c("previousRule"), argumentType= c("SingleRule")),
-list(ruleName="NegativeSingleRule",argumentName=c("previousRule"), argumentType= c("SingleRule")))
+singleRules<-list("IdenSingleRule","AddConstSingleRule","MultConstSingleRule","SubsConstSingleRule","DigSumSingleRule","NegativeSingleRule")
 
 
 #a list of double rules
-doubleRules<-list(list(ruleName="AddDoubleRule",argumentName=c("firstRule","secondRule","nextSingle"), argumentType= c("SingleRule","SingleRule","SingleRule")),
-list(ruleName="MultDoubleRule",argumentName=c("firstRule","secondRule","nextSingle"), argumentType= c("SingleRule","SingleRule","SingleRule")),
-list(ruleName="SubsDoubleRule",argumentName=c("firstRule","secondRule","nextSingle"), argumentType= c("SingleRule","SingleRule","SingleRule")))
+doubleRules<-list("AddDoubleRule","MultDoubleRule","SubsDoubleRule")
 
 
 
@@ -292,7 +312,7 @@
                      } # generate 'n' if it is set as null with different probabilities
       
       
-      if("constantVal"%in%singleRules[[a1]]$argumentName){m<-new(singleRules[[a1]]$ruleName,constantVal=cv1)} else{m<-new(singleRules[[a1]]$ruleName)}
+      if("constantVal"%in%slotNames(singleRules[[a1]])){m<-new(singleRules[[a1]],constantVal=cv1)} else{m<-new(singleRules[[a1]])}
       
       if(n!=0) {createSR(p[[1]],p[[2]],n-1,p[-c(1,2)]); m at previousRule<-k
       }else{return(m)}
@@ -316,7 +336,7 @@
                               if(!inherits(ns,"singleRule") && !is.null(ns))stop(paste("'ns' argument must inherit from class singleRule"))
                               
                               if(is.null(a)) a<-sample(1:length(doubleRules),1) #generate an index of a doubleRule from the list of doubleRules
-                              a<-doubleRules[[a]]$ruleName
+                              a<-doubleRules[[a]]
                               #print(a)
                               
                               if(is.null(fr)) fr<-sample(c(k=createSR(),k=new("IdenSingleRule")),1,prob=c(0.5,0.5))# firstRule is chosen from an automatically generated SingleRule or identical rule returning the input
@@ -523,3 +543,6 @@
                                 if("nextSingle"%in%slotNames(x)){cat("\n NEXT SINGLE:"); x<-x at nextSingle;print.SingleRule(x)}
                             
                                 }
+
+
+



More information about the Ruler-commits mailing list