@@ -32,19 +32,64 @@ tmt_mstdesign <- function(mstdesign, options = c("design", "simulation", "module
3232 # some possible misspecification
3333 checinput <- strsplit(mstdesign ," \n " )[[1 ]]
3434 checkinput <- gsub(" \\ s" ," " ,checinput )
35+ # misspecified <- c("\\=[^:]|\\=[^~~]|[^~~=]|~=|~~|~|<~|\\*")
3536 # 2020-03-27 updated list
3637 misspecified <- " =:|=~~|~~=|~=|~~|<~|\\ *|"
37-
38+ # miss_list <- list()
39+
40+ # checkinput[gregexpr("=:",checkinput, perl = TRUE)>0]
41+ # checkinput[gregexpr("=~~",checkinput, perl = TRUE)>0]
42+ # checkinput[gregexpr("~~=",checkinput, perl = TRUE)>0]
43+ # checkinput[gregexpr("~=",checkinput, perl = TRUE)>0]
44+ # checkinput[gregexpr("~~",checkinput, perl = TRUE)>0]
45+ # checkinput[gregexpr("~",checkinput, perl = TRUE)>0]
46+ # checkinput[gregexpr("<~",checkinput, perl = TRUE)>0]
47+ # checkinput[gregexpr("\\*",checkinput, perl = TRUE)>0]
48+
49+ # ein paar Beispiele ausprobieren
50+ # checkinput[length(checkinput)+1] <- "das=:istErsterTest"
51+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
52+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
53+ # checkinput[length(checkinput)+1] <- "das=~~istZweiterTest"
54+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
55+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
56+ # checkinput[length(checkinput)+1] <- "das~~=istDritterTest"
57+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
58+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
59+ # checkinput[length(checkinput)+1] <- "das~=istVierterTest"
60+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
61+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
62+ # checkinput[length(checkinput)+1] <- "das~~istFuenfterTest"
63+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
64+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
65+ # checkinput[length(checkinput)+1] <- "das~istSechsterTest"
66+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
67+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
68+ # checkinput[length(checkinput)+1] <- "das<~istSiebterTest"
69+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
70+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
71+ # checkinput[length(checkinput)+1] <- "das*istAchterTest"
72+ # checlocation <- gregexpr(misspecified,checkinput, perl = TRUE)
73+ # checkinput[unlist(lapply(checlocation,function(x) any(attr(x,"match.length")>0)))]
74+
3875 checlocation <- gregexpr(misspecified ,checkinput , perl = TRUE )
3976 result_misspecified <- checkinput [unlist(lapply(checlocation ,function (x ) any(attr(x ," match.length" )> 0 )))]
4077
78+ # gregexpr("\\+[^~]",checkinput)
79+ # "~|\\+[^=]|\\+\\="
80+
81+ # 2020-03-27 fixed loop
82+ # for(m in 1:length(misspecified)){
83+ # miss_list[[m]] <- grep(misspecified[m], checkinput, value = TRUE, perl = TRUE)
84+ # }
85+
4186 if (length(result_misspecified )> 0 ) {
4287 stop(" The submitted mstdesign is misspecified, please correct the following expression/s:\n " ,
4388 paste0(" - " ,result_misspecified ,collapse = " \n " )
4489 )
4590 }
4691
47- # ...................................................................................................
92+ # ...................................................................................................
4893
4994 # clean mstdesign input:
5095 tmt.syntax <- mstdesign
@@ -65,11 +110,22 @@ tmt_mstdesign <- function(mstdesign, options = c("design", "simulation", "module
65110 # create list for the simulation function
66111 # -----------------------------------
67112 # number of modules & branches
68-
113+
114+ # für tmtd muss schon überprüft werden, ob es preconditions gibt...dann muss die Simulationsfunktion angepasst werden und die Info in das Design übernommen werden
115+ # die Paths am besten reduzieren um die Einträge, dann gehen die übrigen Funktionen noch...Evtl. die Info in einer anderen Funktion aufbereiten und dann je nach Bedarf den output hinzufügen. Letztlich muss man allerdings darauf achten, dass die Anzahl der Zeilen dann bspw. im design-output um die preconditions ergänzt wird!!
116+
117+ # preconditions können mit ~ enden, aber auch mit +=...wie differenzieren? Müssen eingangs oben definiert werden?
118+
119+
120+
69121 n.modules <- length(grep(" =~" ,tmtd , fixed = TRUE ))
122+ # n.start <- length(grep("==",tmtd, fixed = TRUE))
70123 n.branches <- length(grep(" :=" ,tmtd , fixed = TRUE ))
124+
125+ # l.stages <- nchar(as.character(tmtd[grepl(":=",tmtd, fixed = TRUE)])) -
126+ # nchar( gsub("\\+", "", tmtd[grepl(":=",tmtd, perl = TRUE)]))
127+ # n.stages <- max(l.stages)
71128 n.preconditions <- length(grep(" ==" ,tmtd )) # grep only '~'
72-
73129 if (n.preconditions != 0 ) {
74130 c.preconditions <- grep(" ==" ,tmtd , value = TRUE )
75131 c.preconditions <- strsplit(c.preconditions ," ==" )
@@ -83,6 +139,7 @@ tmt_mstdesign <- function(mstdesign, options = c("design", "simulation", "module
83139 # ---------------------------
84140 preconditions_sim <- preconditions <- start <- simulation <- design <- items <- NULL
85141
142+
86143 modules <- hfun.modules(tmtd = tmtd ,
87144 n.branches = n.branches ,
88145 n.modules = n.modules )
@@ -93,6 +150,7 @@ tmt_mstdesign <- function(mstdesign, options = c("design", "simulation", "module
93150
94151 if (any(av.preconditions $ value %in% modules [," from" ])) stop(" The operator '==' is now used for the definition of preconditions!\n * Please integrate the start module into the mst design and \n * start the function again." )
95152
153+ # nur bei der kumulativen verzweigung muss das Design entsprechend angepasst werden
96154 routing_type <- hfun.preconditionoperator(tmtd = tmtd ,
97155 preconditions = av.preconditions )
98156
@@ -105,11 +163,60 @@ tmt_mstdesign <- function(mstdesign, options = c("design", "simulation", "module
105163 tmtd <- preconditions $ tmtd
106164 n.branches <- nrow(preconditions $ paths )
107165 preconditions_sim <- preconditions $ precondition_matrix
166+ # n.stages <- length(grep("module",colnames(preconditions$paths)))
108167 }
109168
110169 }
111170
112171
172+
173+
174+
175+
176+ # 2020-05-21 added for probabilistic-cumulative designs
177+ # branches <- tmtd[grepl(":=", tmtd, fixed = TRUE)]
178+ # if (any(grepl("+=",branches)) {
179+
180+
181+ # branches <- strsplit_storing(branches,":=")
182+ # colnames(branches) <- c("path","operator_0", "path_original")
183+ # branches <- strsplit_storing(variable = branches,
184+ # split = c("~","+=","+"),
185+ # cols = "path_original",
186+ # new_names = c("module","operator"))
187+
188+ # i <- 1
189+ # for (m in grep("module",colnames(branches),value=TRUE)){
190+ # branches <- strsplit_storing(branches,"\\(|\\)",m, fixed = FALSE, new_names = paste0(c("module_","rule_"),i), store_operator = FALSE)
191+ # i <- i + 1
192+ # }
193+ # # nun die rules durch die lenght der items ersetzen und dann jeweils um eines reduzieren
194+ # items <- unlist(regmatches(modules[,"items"], gregexpr( "(?<=\\().+?(?=\\))", modules[,"items"], perl = TRUE)))
195+ # possible_scores <- sapply(items,function(x) paste0("0:",length(strsplit(x,",")[[1]])) , simplify=TRUE,USE.NAMES=FALSE)
196+ # modules_score <- cbind(modules[,"from"],possible_scores)
197+ # colnames(modules_score) <- c("module","score")
198+
199+
200+ # for (o in seq(grep("rule",colnames(branches)))) {
201+ # pos_module <- match(c(branches[,paste0("module_",o)]), modules_score[,"module"])
202+ # branches[,paste0("rule_",o)] <- modules_score[,"score"][pos_module]
203+ # }
204+
205+ # # nur für die mittleren Fälle
206+ # cases <- grep("rule",colnames(branches), value = TRUE)
207+ # cases <- cases[-length(cases)]
208+
209+ # branches_expand <- expand.matrix(variable = branches,
210+ # names = cases)
211+ # branches_expand <- branches_expand[,seq(grep(cases,colnames(branches_expand))+2)]
212+
213+
214+ # operator_check <- rowSums(apply(branches_expand[,grep(cases, colnames(branches_expand))+1,drop=FALSE],2,function(x) x%in%"+="))
215+ # branches_expand <- branches_expand[operator_check==length(cases),]
216+
217+ # }
218+
219+
113220 if (" simulation" %in% options ) simulation <- hfun.simulation(modules = modules ,
114221 tmtd = tmtd_sim ,
115222 preconditions = preconditions_sim )
0 commit comments