@@ -52,9 +52,10 @@ rules <- validator( x > 0)
5252is_infeasible(rules )
5353# > [1] FALSE
5454
55- rules <- validator( rule1 = x > 0
56- , rule2 = x < 0
57- )
55+ rules <- validator(
56+ rule1 = x > 0 ,
57+ rule2 = x < 0
58+ )
5859is_infeasible(rules )
5960# > [1] TRUE
6061
@@ -71,10 +72,15 @@ is_contradicted_by(rules, "rule1", verbose=TRUE)
7172# > [1] "rule2"
7273
7374# we prefer to keep rule1, so we can give rule1 Inf weight
74- detect_infeasible_rules(rules , weight = c(rule1 = Inf ), verbose = TRUE )
75+ detect_infeasible_rules(
76+ rules ,
77+ weight = c(rule1 = Inf ),
78+ verbose = TRUE
79+ )
7580# > Found:
7681# > rule2: x < 0
7782# > [1] "rule2"
83+
7884make_feasible(rules , weight = c(rule1 = Inf ), verbose = TRUE )
7985# > Found:
8086# > rule2: x < 0
@@ -141,34 +147,39 @@ methods:
141147### Value substitution
142148
143149``` r
144- rules <- validator( rule1 = height > 5
145- , rule2 = max_height > = height
150+ rules <- validator( rule1 = height > 4
151+ , rule2 = height < = max_height
146152 , rule3 = if (gender == " male" ) weight > 100
147153 , rule4 = gender %in% c(" male" , " female" )
148154 )
149- substitute_values(rules , height = 6 , gender = " male" )
150- # > Object of class 'validator' with 4 elements:
151- # > rule2 : max_height >= 6
152- # > rule3 : weight > 100
153- # > .const_height: height == 6
154- # > .const_gender: gender == "male"
155+ substitute_values(rules , max_height = 6 , gender = " male" )
156+ # > Object of class 'validator' with 5 elements:
157+ # > rule1 : height > 4
158+ # > rule2 : height <= 6
159+ # > rule3 : weight > 100
160+ # > .const_max_height: max_height == 6
161+ # > .const_gender : gender == "male"
155162```
156163
157164### Finding fixed values
158165
159166``` r
160- rules <- validator( rule1 = x > = 0 , rule2 = x < = 0 )
167+ rules <- validator(
168+ rule1 = x > = 0 ,
169+ rule2 = x < = 0
170+ )
161171detect_fixed_variables(rules )
162172# > $x
163173# > [1] 0
164174simplify_fixed_variables(rules )
165175# > Object of class 'validator' with 1 elements:
166176# > .const_x: x == 0
167177
168- rules <- validator( rule1 = x1 + x2 + x3 == 0
169- , rule2 = x1 + x2 > = 0
170- , rule3 = x3 > = 0
171- )
178+ rules <- validator(
179+ rule1 = x1 + x2 + x3 == 0 ,
180+ rule2 = x1 + x2 > = 0 ,
181+ rule3 = x3 > = 0
182+ )
172183simplify_fixed_variables(rules )
173184# > Object of class 'validator' with 3 elements:
174185# > rule1 : x1 + x2 + 0 == 0
@@ -180,9 +191,10 @@ simplify_fixed_variables(rules)
180191
181192``` r
182193# non-relaxing clause
183- rules <- validator( r1 = if (income > 0 ) age > = 16
184- , r2 = age < 12
185- )
194+ rules <- validator(
195+ r1 = if (income > 0 ) age > = 16 ,
196+ r2 = age < 12
197+ )
186198# age > 16 is always FALSE so r1 can be simplified
187199simplify_conditional(rules )
188200# > Object of class 'validator' with 2 elements:
@@ -191,9 +203,10 @@ simplify_conditional(rules)
191203
192204
193205# non-constraining clause
194- rules <- validator( rule1 = if (age < 16 ) income == 0
195- , rule2 = if (age > = 16 ) income > = 0
196- )
206+ rules <- validator(
207+ rule1 = if (age < 16 ) income == 0 ,
208+ rule2 = if (age > = 16 ) income > = 0
209+ )
197210simplify_conditional(rules )
198211# > Object of class 'validator' with 2 elements:
199212# > rule1: age >= 16 | (income == 0)
@@ -203,9 +216,10 @@ simplify_conditional(rules)
203216### Removing redundant rules
204217
205218``` r
206- rules <- validator( rule1 = age > 12
207- , rule2 = age > 18
208- )
219+ rules <- validator(
220+ rule1 = age > 12 ,
221+ rule2 = age > 18
222+ )
209223
210224# rule1 is superfluous
211225remove_redundancy(rules , verbose = TRUE )
@@ -214,8 +228,9 @@ remove_redundancy(rules, verbose=TRUE)
214228# > Object of class 'validator' with 1 elements:
215229# > rule2: age > 18
216230
217- rules <- validator( rule1 = age > 12
218- , rule2 = age > 12
231+ rules <- validator(
232+ rule1 = age > 12 ,
233+ rule2 = age > 12
219234)
220235
221236# standout: rule1 and rule2, first rule wins
0 commit comments