-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplify_gen.R
82 lines (52 loc) · 1.76 KB
/
simplify_gen.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
simplify_gen <- function(A, B, C, D, attributes, pos_id, verbose = FALSE) {
change <- FALSE
A_orig <- A
B_orig <- B
C_orig <- C
D_orig <- D
AcapC <- .intersection(A, C)
if (sum(AcapC) > 0) {
x_candidates <- which(as.matrix(AcapC) > 0)
b_candidates <- which(as.matrix(B) > 0)
d_candidates <- which(as.matrix(D) > 0)
for (x in x_candidates) {
for (b in b_candidates) {
for (d in d_candidates) {
bbar <- negate_id(b, pos_id)
dbar <- negate_id(d, pos_id)
Anotx_bbar <- A
Anotx_bbar[x] <- 0
Anotx_bbar[bbar] <- 1
Cnotx_dbar <- C
Cnotx_dbar[x] <- 0
Cnotx_dbar[dbar] <- 1
if (.subset(Anotx_bbar, Cnotx_dbar)[1]) {
change <- TRUE
D[d] <- 0
if (verbose) {
cat("^ Applied [MixGen]\n")
cat("^ Changed C -> D:\n")
cat("^ from:", .implication_to_string(C_orig, D_orig, attributes), "\n")
cat("^ to:", .implication_to_string(C, D, attributes), "\n")
cat("^ -> since x = ", attributes[x], ", b = ",
attributes[b], " and d = ", attributes[d], "\n")
}
return(list(A, B, C, D, TRUE))
}
if (.subset(Cnotx_dbar, Anotx_bbar)[1]) {
change <- TRUE
B[b] <- 0
if (verbose) {
cat("^ Applied [MixGen]\n")
cat("^ Changed A -> B:\n")
cat("^ from:", .implication_to_string(A_orig, B_orig, attributes), "\n")
cat("^ to:", .implication_to_string(A, B, attributes), "\n")
}
return(list(A, B, C, D, TRUE))
}
}
}
}
}
return(list(A, B, C, D, FALSE))
}