JESS: Re: calculating benefit costs
"Derek Adams" <[email protected]>
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <24906_1294267906_p05MpYfI028244_AANLkTimC46adT0fuy2BinbqdFaX0+tmx51A7Jy6AD699@mail.gmail.com> |
the facts that I am working with are: (HrBenefitJoin (hrBenefitConfigId "00001-0000000073")(benefitJoinId ?bjid)(calculatedCost ?cost)(OBJECT ?obj)(coveredPersonId ?cPer)(payingPersonId ?pPer)(relationshipId ?rel)) (Person (personId ?cPer)(dob ?dob)(OBJECT ?objP)) ?rel is what identifies the "covered person" as spouse or employee. If ?rel is nil, it's employee, else it's spouse. So ?objP is my covered person (either spouse or employee). On Wed, Jan 5, 2011 at 3:36 PM, Wolfgang Laun <[email protected]>wrote: > With this kind of problem, there are (at least) two approaches. Given that > Employee and Spouse are represented as facts: > (deftemplate Spouse (slot name)(slot age)) > (deftemplate Employee (slot name)(slot age)(slot spouse)) > > (deffacts test-facts > (Employee (name "John Smith")(age 35)(spouse "Jane Smith")) > (Spouse (name "Jane Smith")(age 28)) > (Employee (name "Honey Rider")(age 39)(spouse "James Rider")) > (Spouse (name "James Rider")(age 45)) > ) > > (1) You can write one rule for each possible combination of age brackets. > > (defrule compute_1_1 > (Employee (name ?name){age >= 18 && age <= 29}(spouse ?spouse)) > (Spouse {name == ?spouse}{age >= 18 && age <= 29}) > => > (printout t "cost " ?name " " (+ 11.55 6.65) crlf) > ) > ... more boring code ... > (defrule compute_3_3 > (Employee (name ?name){age >= 40 && age <= 49}(spouse ?spouse)) > (Spouse {name == ?spouse}{age >= 40 && age <= 49}) > => > (printout t "cost " ?name " " (+ 38.35 20.05) crlf) > ) > > (2) You can represent the tables for the costs as facts: > (deftemplate CostEmployee (slot lo)(slot hi)(slot cost)) > (deftemplate CostSpouse (slot lo)(slot hi)(slot cost)) > > (deffacts costs > (CostEmployee (lo 18)(hi 29)(cost 11.55)) > (CostEmployee (lo 30)(hi 39)(cost 18.95)) > (CostEmployee (lo 40)(hi 49)(cost 38.35)) > (CostSpouse (lo 18)(hi 29)(cost 6.65)) > (CostSpouse (lo 30)(hi 39)(cost 10.35)) > (CostSpouse (lo 40)(hi 49)(cost 20.05)) > ) > > and use a single rule: > > (defrule compute > (Employee (name ?name)(age ?ageE)(spouse ?spouse)) > (Spouse {name == ?spouse}(age ?ageS)) > (CostEmployee {lo <= ?ageE}{hi >= ?ageE}(cost ?costE)) > (CostSpouse {lo <= ?ageS}{hi >= ?ageS}(cost ?costS)) > => > (printout t "cost " ?name " " (+ ?costE ?costS) crlf) > ) > > HTH > Wolfgang > > > > > > On 5 January 2011 22:30, Wolfgang Laun <[email protected]> wrote: > >> Sent on behalf of Derek Adams: >> >> >> Hey Jess Users! This is my first post, so I apologize for anything "noob" >> that I say/do... >> >> I'm very new to Jess. I understand the basics but applying my knowledge >> for the first time is proving more difficult than I anticipated. Here is >> the problem: >> >> I need to set up a rule in Jess that calculates the cost of a benefit >> based on age and enrollees. >> * >> Example: >> The Benefit Configuration is "Employee $10k / Spouse $5k" >> The enrollees are the employee (John Smith age 30) and spouse (Jane Smith >> and 28). >> The costs are calculated as follows: >> >> Age Employee Spouse >> 18-29 11.55 6.65 >> 30-39 18.95 10.35 >> 40-49 38.35 20.05* >> >> *So John's cost is 18.95 and Jane's cost is 6.65 for a total of 25.60*. >> >> Any advice would be greatly appreciated! >> >> Thanks, >> >> Derek Adams >> > > -- *Derek Adams* Lead Developer Arahant LLC Work: 615-376-5500 ext. 314 Cell: 270-543-0920