|
1 | 1 | #' Check the feasibility of a rule set |
2 | 2 | #' |
3 | 3 | #' An infeasible rule set cannot be satisfied by any data because of internal |
4 | | -#' contradictions. This function checks whether the record-wise linear, |
| 4 | +#' contradictions: the combination of the rules make it inconsistent. |
| 5 | +#' This function checks whether the record-wise linear, |
5 | 6 | #' categorical and conditional rules in a rule set are consistent. |
6 | | -#' Note that is it always wise to also check `detect_contradicting_if_rules()`. |
| 7 | +#' Note that is it wise to also check `detect_contradicting_if_rules()`: |
| 8 | +#' conditional If-rules |
| 9 | +#' may not be strictly inconsistent, but can be semantically inconsistent. |
7 | 10 | #' |
8 | 11 | #' @example ./examples/feasible.R |
9 | 12 | #' @param x `validator` object with validation rules. |
10 | 13 | #' @param ... not used |
| 14 | +#' @param verbose if `TRUE` print information to the console |
11 | 15 | #' @family feasibility |
12 | 16 | #' @return TRUE or FALSE |
13 | 17 | #' @export |
14 | | -is_infeasible <- function(x, ...){ |
| 18 | +is_infeasible <- function(x, ..., verbose = interactive()){ |
15 | 19 | lp <- to_lp(x) # TODO find out how to treat eps for linear inequalities... |
16 | 20 | lpSolveAPI::lp.control(lp, presolve="rows", break.at.first = TRUE) |
17 | 21 | res <- solve(lp) |
18 | 22 | # any of the following means that there is a solution found by lpSolveAPI: |
19 | 23 | # TODO generate errors if the lpSolveAPI gives other return values... |
20 | | - !(res %in% c(0,1,4,12)) |
| 24 | + i <- !(res %in% c(0,1,4,12)) |
| 25 | + |
| 26 | + if (isTRUE(verbose)){ |
| 27 | + if (i){ |
| 28 | + message( |
| 29 | + "The rule set is infeasible:\n", |
| 30 | + " use `detect_infeasible_rules()` and `is_contradicted_by` to find out\n", |
| 31 | + " which rules are causing infeasibility.", |
| 32 | + " or `make_feasible()` to make the rule set feasible." |
| 33 | + ) |
| 34 | + } else { |
| 35 | + message( |
| 36 | + "The rule set is feasible,\n", |
| 37 | + " but may contain contradictions in conditional if-rules.\n", |
| 38 | + " use `detect_contradicting_if_rules()` to find out whether there are \n", |
| 39 | + " contradictions in the if-clauses." |
| 40 | + ) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + i |
21 | 45 | } |
22 | 46 |
|
23 | 47 | is_feasible <- function(x, ...){ |
@@ -70,7 +94,7 @@ make_feasible <- function(x, ..., verbose = interactive()){ |
70 | 94 | #' @return `character` with the names of the rules that are causing infeasibility. |
71 | 95 | detect_infeasible_rules <- function(x, weight = numeric(), ..., verbose = interactive()){ |
72 | 96 | # browser() |
73 | | - if (!is_infeasible(x)){ |
| 97 | + if (!is_infeasible(x, verbose=FALSE)){ |
74 | 98 | return(character()) |
75 | 99 | } |
76 | 100 | # browser() |
|
0 commit comments