-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplify_contradiction.R
62 lines (45 loc) · 1.24 KB
/
simplify_contradiction.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
simplify_contradiction <- function(A, B,
attributes,
pos_id,
verbose = FALSE) {
negB <- negate(B)
AcapnegB <- A * negB
BcapnegB <- B * negB
change <- FALSE
A_orig <- A
B_orig <- B
if (sum(AcapnegB) > 0) {
x <- which(as.matrix(A) > 0)[1]
A[x] <- 0
xbar <- negate_id(x, pos_id)
B <- empty_set(nrow(B))
# B[B == 1] <- 0
B[xbar] <- 1
change <- TRUE
if (verbose) {
cat("^ Applied [Cont']\n")
cat("^ Changed:\n")
cat("^ from:", .implication_to_string(A_orig, B_orig, attributes), "\n")
cat("^ to:", .implication_to_string(A, B, attributes), "\n")
}
}
if (sum(BcapnegB) > 0) {
if (sum(A) == 0) {
return(list(A, B, FALSE))
}
x <- which(as.matrix(A) > 0)[1]
A[x] <- 0
xbar <- negate_id(x, pos_id)
# B[B == 1] <- 0
B <- empty_set(nrow(B))
B[xbar] <- 1
change <- TRUE
if (verbose) {
cat("^ Applied [Cont'']\n")
cat("^ Changed:\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, change))
}