I think PECK, JOSH (SBCSI) wrote:
>
> Rules:
>
> Rules exist that disallow, require, or modify Package and Product
> description.
>
> Rule-1: If customer has Package-1 they CANNOT select Products w and
> q separately, or in another Package.
> Rule-2: If customer has Package-1 they CANNOT select Package-10
> Rule-3: If customer has Package-4 they MUST have Package-1
> Rule-4: Customers in California can only have Packages-1 through
> Package-5
> Rule-5: Customers with promo code 12345 get a 10% discount on
> Package-3
> etc....
So, as a first rough cut, this implies that customers could be a
deftemplate like
(deftemplate customer
(slot name) (slot state)
(multislot packages) (multislot products))
and packages might be like
(deftemplate package (slot name) (multislot products))
Here is one way to encode some of these rules (I'm assuming that
packages will be listed in numeric order to simplify rules a bit.)
Rule-1 is really two rules; you could use an "or" to write it as one
if you wanted to, but I like it better this way.
(defrule Rule-1-unbundled
"Customer has Package-1 plus unbundled w or q."
(customer (packages $? Package-1 $?) (products $? w|q $?))
=>
(report-conflict "Your explanation goes here"))
(defrule Rule-1-bundled
"Customer has Package-1 plus bundled w or q."
(customer (packages Package-1 $? ?other $?)
(package (name ?other) (products $? w|q $?))
=>
(report-conflict "Your explanation goes here"))
(defrule Rule-2
"Customer has Package-1 plus Package-10"
(customer (packages Package-1 $? Package-10))
=>
(report-conflict "Your explanation goes here."))
(defrule Rule-3
"Customer has package 1, but not package 4"
(customer (packages Package-1 $?rest&:(not (member$ Package-4 ?rest))))
=>
(report-conflict "Your explanation goes here."))
(defrule Rule-4
"California customer can only have pkgs 1-5"
(customer (state California) (packages $? ?p $?))
(test (not (member$ ?p (create$ Package-1 Package-2 Package-3 Package-4 Package-5))))
=>
(report-conflict "Your explanation goes here."))
Rule-5 introduces promo codes and charges, and hence new slots for the
deftemplates, so I won't do it here -- but it's no more complex, just
more of the same.
>
> Output:
>
> 1) TRUE: Everything matches ok, no need to change selection
> 2) FALSE: There are some conflicts. These are: (list some text or code
> that describes conflict)
"report-conflict" in the above is a function you write, which does
whatever you need it to do to report the errors.
>
> I know that JESS can tackle this problem, but will it be relatively
> efficient (as compared to just writing it in straight Java, looping over
> if/thens, etc) ?
Absolutely, especially if there are lots of options. Also, maintaining
the rules is much easier than maintaining the Java code would be.
>
>
> P.s. So far I've found the system very easy to use and very well documented.
> Installing JESS and running the examples was a breeze. I'm really impressed
> with the tool so far! Very nicely done. I really hope that I can use it
> for my application.
>
Great, thanks!
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------