I have two rules in CLIPS which I want to combine if they're both true...not sure how to do it though. I have an attribute which is called grant-eligible
....I was thinking if I set it to TRUE
then I could read the next rule, and then set the 'grant-eligible'
to FALSE
....but it seems that my code is getting into an infinite loop when I do this...
So here are my rules:
(defrule complete "rule for app completeness"
?f <- (application (transcript-received Yes) (app-complete FALSE)
(gpa
?v_gpa&:(
> ?v_gpa 0)))
=>
(modify ?f (app-complete TRUE)))
(defrule denied "rule for admission - DENIED"
?f <- (application (app-complete TRUE) (app-decision FALSE)
(gpa
?v_gpa&:(
< ?v_gpa 3.0))
(ssat
?v_ssat&:(
>= ?v_ssat 0.0))
)
=>
(modify ?f (app-decision DENIED))
)
(defrule accepted "rule for admission - ACCEPTED"
?f <- (application (app-complete TRUE) (app-decision FALSE)
(gpa
?v_gpa&:(
>= ?v_gpa 3.5))
(ssat
?v_ssat&:(
>= ?v_ssat 1500))
)
=>
(modify ?f (app-decision ACCEPTED))
)
This is the ones I am trying to implement now
(defrule female-finaid "rule for finaid applications for female students"
?f <- (application (app-decision ACCEPTED)
(gender F) (grade-entry Freshman) (country USA)
(grant-eligible TRUE)
(grant ?v_grant)
)
=>
(modify ?f
(grant (+ ?v_grant 5000))
(grant-eligible TRUE)
)
)
(defrule great-students-finaid "rule for finaid applications for female students"
?f <- (application (app-decision ACCEPTED)
(country USA)
(grant-eligible TRUE)
(grant ?v_grant)
(gpa
?v_gpa&:(
>= ?v_gpa 4.0))
)
=>
(modify ?f
(grant (+ ?v_grant 4500))
(grant-eligible FALSE)
)
)
If both of these rules are true, the grant awarded should be 9500, or it could be 5000 or it could be 4500...Any ideas?
The solution: (where ff-grant-eligible
and es-grant-eligible
are my control facts...they stand for ff=female finaid, and es=excellent student)
(defrule female-finaid "rule for finaid applications for female students"
?f <- (application (app-decision ACCEPTED) (ff-grant-eligible TRUE)
(gender F) (grade-entry Freshman) (country USA)
(grant ?v_grant)
)
=>
(modify ?f
(grant (+ ?v_grant 5000))
(ff-grant-eligible FALSE)
)
)
(defrule great-students-finaid "rule for finaid applications for female students"
?f <- (application (app-decision ACCEPTED) (es-grant-eligible TRUE)
(country USA)
(grant ?v_grant)
(gpa
?v_gpa&:(
>= ?v_gpa 4.0))
)
=>
(modify ?f
(grant (+ ?v_grant 4500))
(es-grant-eligible FALSE)
)
)