-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplify_composition.R
124 lines (99 loc) · 2.74 KB
/
simplify_composition.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
simplify_composition <- function(A, B, C, D,
attributes,
pos_id,
verbose = FALSE) {
change <- FALSE
A_orig <- A
B_orig <- B
C_orig <- C
D_orig <- D
if ((sum(B) == 1) && .subset(B, D)[1]) {
x_candidates <- which(as.matrix(A) > 0)
y_candidates <- which(as.matrix(C) > 0)
for (x in x_candidates) {
for (y in y_candidates) {
Anotx <- A
Anotx[x] <- 0
Cnoty <- C
Cnoty[y] <- 0
if (.equal_sets(Anotx, Cnoty)[1]) {
b <- which(as.matrix(B) > 0)
bbar <- negate_id(b, pos_id)
xbar <- negate_id(x, pos_id)
ybar <- negate_id(y, pos_id)
A <- Anotx
A[bbar] <- 1
B <- empty_set(nrow(B))
# B[B == 1] <- 0
B[c(xbar, ybar)] <- 1
C <- C
D[b] <- 0
if (verbose) {
cat("^ Applied [MixComp]\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")
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")
}
return(list(A, B, C, D, TRUE))
}
}
}
}
# if ((sum(D) == 1) && .subset(D, B)[1]) {
#
# x_candidates <- which(as.matrix(C) > 0)
# y_candidates <- which(as.matrix(A) > 0)
#
# for (x in x_candidates) {
#
# for (y in y_candidates) {
#
# Anotx <- C
# Anotx[x] <- 0
#
# Cnoty <- A
# Cnoty[y] <- 0
#
# if (.equal_sets(Anotx, Cnoty)[1]) {
#
# b <- which(as.matrix(D) > 0)
# bbar <- negate_id(b, pos_id)
#
# xbar <- negate_id(x, pos_id)
# ybar <- negate_id(y, pos_id)
#
# C <- Anotx
# C[bbar] <- 1
# D <- 0 * D
# D[c(xbar, ybar)] <- 1
# A <- A
# B[b] <- 0
#
# if (verbose) {
#
# cat("^ Applied [MixComp]\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")
#
# 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")
#
# }
#
# return(list(A, B, C, D, TRUE))
#
#
# }
#
# }
#
# }
#
# }
return(list(A, B, C, D, change))
}