Skip to content

Commit bfcbb66

Browse files
committed
adding fix domain
1 parent 3cf7df5 commit bfcbb66

10 files changed

Lines changed: 58 additions & 8 deletions

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ Description: Rule sets with validation rules may contain redundancies or contrad
1212
Depends: validate
1313
License: MIT + file LICENSE
1414
Encoding: UTF-8
15-
LazyData: true
1615
URL: https://github.com/data-cleaning/validatetools
1716
BugReports: https://github.com/data-cleaning/validatetools/issues
1817
Imports: methods, stats, utils, lpSolveAPI
1918
Suggests: testthat,
2019
covr
21-
RoxygenNote: 7.2.3
20+
RoxygenNote: 7.3.2

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
S3method("[",dnf)
44
S3method(as.character,dnf)
5+
S3method(as.character,mip_rule)
56
S3method(as.expression,dnf)
67
S3method(print,dnf)
78
S3method(print,mip_rule)

R/detect_boundary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @example ./examples/detect_boundary.R
1212
#' @export
1313
#' @param x \code{\link{validator}} object, rule set to be checked
14-
#' @param eps detected fixed values will have this precission.
14+
#' @param eps detected fixed values will have this precision.
1515
#' @param ... currently not used
1616
#' @family feasibility
1717
#' @return \code{\link{data.frame}} with columns "variable", "lowerbound", "upperbound".

R/dnf.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,36 @@ to_miprules <- function(x, ...){
237237
to_lp <- function(x, objective = NULL, eps = 0.001){
238238
check_validator(x, check_infeasible = FALSE)
239239
rules <- to_miprules(x)
240+
rules <- fix_cat_domain(rules)
240241
translate_mip_lp(rules = rules, objective = objective, eps = eps)
241242
}
242243

244+
# make sure that the values of each categorical variable are exclusive
245+
# which is not guaranteed when no domain is given
246+
fix_cat_domain <- function(rules){
247+
type <- get_mr_type(rules)
248+
binvars <- names(type)[type == "binary"]
249+
if (length(binvars) == 0){
250+
return(rules)
251+
}
252+
253+
catvars <-
254+
strsplit(binvars, INFIX_CAT_NAME)
255+
256+
catvars <- sapply(catvars, function(x){
257+
x[[1]]
258+
})
259+
260+
cv <-
261+
split(binvars, catvars) |>
262+
lapply(function(x){
263+
a <- sapply(x, \(x) 1)
264+
type <- sapply(x, \(x) "binary")
265+
mip_rule(a = a, op = "<=", b = 1, rule = "domain", type = type)
266+
})
267+
c(rules, unname(cv))
268+
}
269+
243270
# as_dnf(quote(!(gender == "male") | x > 6))
244271
# as_dnf(quote(if (y == 1) x > 6))
245272
# as_dnf(quote( !(gender %in% "male" & y > 3) | x > 6))

R/feasible.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ detect_infeasible_rules <- function(x, weight = numeric(), ...){
6666
}
6767

6868
mr <- to_miprules(x)
69+
mr <- fix_cat_domain(mr)
6970

7071
is_equality <- sapply(mr, function(m){
7172
m$op == "==" && all(m$type == "double")
@@ -87,7 +88,6 @@ detect_infeasible_rules <- function(x, weight = numeric(), ...){
8788

8889
# make all rules soft rules
8990
objective <- numeric()
90-
9191
mr <- lapply(mr , function(r){
9292
is_lin <- all(r$type == "double")
9393
is_cat <- all(r$type == "binary")

R/mip_lpsolve.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ translate_mip_lp <- function( rules
1010
, objective=NULL
1111
, eps = 1e-3
1212
){
13-
#browser()
13+
1414
lc <- get_mr_matrix(rules)
1515
type <- get_mr_type(rules)
1616

R/mip_rule.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mip_rule <- function(a, op, b, rule, type, weight=Inf, ...){
1818
)
1919
}
2020

21+
#' @export
2122
as.character.mip_rule <- function(x, ...){
2223
a <- paste0(x$a, "*", names(x$a), collapse= ' + ')
2324

R/validatetools-package.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@
3737
#' @importFrom stats setNames
3838
#' @importFrom utils head tail
3939
#' @import validate
40-
#' @docType package
41-
NULL
40+
"_PACKAGE"

man/detect_boundary_num.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/validatetools.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)