I know, I know -- rtfm. I HAVE. I don't see it. This problem probably doesn't need the scrutiny of Dr. Friedman-Hill, but... I am completely mystified by whatever I am doing wrong. If anyone could be so kind as to degne to share a few pearls with me, they will undoubledly attain much good karma. ------------------------ Jess> (batch AVIS\\avis-proto.clp) Jess reported an error in routine ValueVector.get while executing (batch AVIS\avis-rules-proto-rules.clp) while executing (batch AVIS\avis-proto.clp). Message: Bad index -3 in call to get() on this vector: (name nil -1 loc nil -1 s 1 days-required nil -1 rate-type nil -1 res-num nil -1 car-group-name nil -1). Program text: ( batch AVIS\avis-proto.clp ) at line 1. at jess.ValueVector.get(Unknown Source) at jess.Deftemplate.getSlotType(Unknown Source) at jess.Jesp.a(Unknown Source) at jess.Jesp.int(Unknown Source) at jess.Jesp.case(Unknown Source) at jess.Jesp.do(Unknown Source) at jess.Jesp.char(Unknown Source) at jess.Jesp.parse(Unknown Source) at jess.Batch.batch(Unknown Source) at jess.Batch.call(Unknown Source) at jess.d2.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.Jesp.a(Unknown Source) at jess.Jesp.char(Unknown Source) at jess.Jesp.parse(Unknown Source) at jess.Batch.batch(Unknown Source) at jess.Batch.call(Unknown Source) at jess.d2.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.Jesp.a(Unknown Source) at jess.Jesp.char(Unknown Source) at jess.Jesp.parse(Unknown Source) at jess.Main.execute(Unknown Source) at jess.Main.main(Unknown Source) Jess> ----------------------------- rules.clp file attached. Regards. Michael __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/
;; ATTRIBUTE DEFINITIONS ;;; JESS Rules Prototype for EU-Rental Corporation ;;; ;;; ;; attribute used to find daily rate (deftemplate find (slot daily-rate) ) ;; attribute used to compute one way trip (deftemplate owt (slot miles-driven) ) ;; attribute used to represent a car group (deftemplate car-group-item (slot car-group-name) (slot description) (slot daily-rate) (slot three-day-rate) (slot FL-daily-rate) (slot FL-three-day-rate) (slot mileage-limit) ) ;; reservation attribute (deftemplate reservation (slot name) (slot loc) (slot start-date) (slot wizard) (slot corp-account) (slot days-required) (slot rate-type) (slot res-num) (slot car-group-name) ) ;; check out object (deftemplate checkout (slot res-num) (slot car-group-name) (slot date) (slot check-out-loc) (slot mileage) (multislot equip) ) ;; checkin object (deftemplate checkin (slot res-num) (slot car-group-name) (slot date) (slot check-in-loc) (slot mileage) (multislot equip) ) ;; location attribute (deftemplate location-item (slot loc-prefix) (slot loc-special-charges)) (deftemplate misc-charges-item (slot item-name) (slot daily-rate) (slot usage-mins) (slot monthly-rate)) (deftemplate one-way-trip-row (slot band) (slot s-distance ) (slot e-distance ) (slot per-mile-charge) (slot additional-charge) ) (deftemplate product (slot product-name) (slot product-type) (slot product-description) ) (deffacts control-information (phase reservation) (phase-after reservation checkout) (phase-after checkout checkin) (phase-after checkin reservation) ) (deffacts current-day (current-date 06-12-2001) ) (deffacts person-at-counter (current-name EMMcConnell) ) (deffacts OWT-Schedule "Charge Schedule for Unscheduled One-Way Trip " (one-way-trip-row (band A) (s-distance 0 ) (e-distance 100 ) (per-mile-charge 0.25) (additional-charge 50.0) ) (one-way-trip-row (band B) (s-distance 101) (e-distance 300) (per-mile-charge 0.5) (additional-charge 200.0)) (one-way-trip-row (band C) (s-distance 301) (e-distance 2000) (per-mile-charge 0.75) (additional-charge 1500)) (one-way-trip-row (band D) (s-distance 2001) (e-distance 100000) (per-mile-charge 1.50) (additional-charge 2000))) (deffacts car-group-rates (car-group-item (car-group-name B) (description "Compact" ) (daily-rate 51.38) (three-day-rate 50.38) (FL-daily-rate 49.13) (FL-three-day-rate 48.13) (mileage-limit nil) ) (car-group-item (car-group-name C) (description "intermediate") (daily-rate 54.38 ) (three-day-rate 53.38 ) (FL-daily-rate 52.13 ) (FL-three-day-rate 48.13) (mileage-limit nil) ) (car-group-item (car-group-name D) (description "full-size 2dr") (daily-rate 55.88 ) (three-day-rate 54.88 ) (FL-daily-rate 53.63 ) (FL-three-day-rate 48.13 ) (mileage-limit nil) ) (car-group-item (car-group-name E) (description "full-size 4dr") (daily-rate 55.88 ) (three-day-rate 54.88 ) (FL-daily-rate 53.63 ) (FL-three-day-rate 48.13 ) (mileage-limit nil) ) (car-group-item (car-group-name G) (description "Premium") (daily-rate 63.38 ) (three-day-rate 62.88 ) (FL-daily-rate 61.13 ) (FL-three-day-rate 48.13 ) (mileage-limit nil) ) (car-group-item (car-group-name H) (description "Luxury") (daily-rate 68.63 ) (three-day-rate 62.38 ) (FL-daily-rate 66.38 ) (FL-three-day-rate 48.13 ) (mileage-limit 100) ) (car-group-item (car-group-name V) (description "Mini-van") (daily-rate 73.13 ) (three-day-rate 67.63 ) (FL-daily-rate 70.88 ) (FL-three-day-rate 48.13 ) (mileage-limit 100) ) (car-group-item (car-group-name W) (description "SUV-4wd") (daily-rate 73.13 ) (three-day-rate 67.63 ) (FL-daily-rate 70.88 ) (FL-three-day-rate 48.13 ) (mileage-limit 100) ) ) ;---------------------------------------------------- ;; RULE DEFINITIONS ;---------------------------------------------------- ;; Initialize reservation rule (defrule rule1_InitReservation ?r1 <- (reservation (car-group-name ?car-group-name) (days-required ?days-required)) => (if (and (<= 4 ?days-required ) (<= ?days-required 30 )) then (modify (reservation ( ?rate-type weekly))) ) (if (<= 30 ?days-required) then (modify (reservation (?rate-type monthly))) ) (bind (?cgn ?car-group-name) (?dr ?days-required)) (retract ?r1) (retract ?phase) (assert (reservation (car-group-name ?cgn) (days-required ?dr) (rate-type ?rate-type))) (assert (phase checkout)) ) ;------End of Rule ---------------------- ;; Move from reservation state to checkout state (defrule rule2_ReservationToCheckout (current-name ?current-name) (reservation (start-date ?start-date)(days-requested ?days-requested) (name ?name) (loc ?loc) (rate-type ?rate-type)) (test (eq (?name ?current-name))) => (if (and (>= (?days-requested 4)) (< (?days-requested 30))) then (bind ?rate-type weekly) ) (if (>= (?days-requested 30)) then (bind ?rate-type monthly) ) (modify start-date ?current-date) ) ;------End of Rule ---------------------- ;; Compute rate at checkout time (defrule rule3_ComputeCheckoutDailyRate (reservation (rate-type ?rate-type) (car-group-name ?car-group-name)) (car-group-item (car-group-name ?car-group-name) (daily-rate ?daily-rate) ) => (if (eq (?rate-type weekly)) then (bind daily-rate (/ (* ?daily-rate 5.75) 7)) else (if (eq (?rate-type monthly)) then (bind daily-rate (/ (* ?daily-rate 25.5) 30)) ) ) ) ;------End of Rule ---------------------- ;; Find Daily Rate rule (defrule rule4_FindDailyRate (find (daily-rate ?daily-rate)) (car-group-item (car-group-name ?car-group-name) (daily-rate ?daily-rate)) => (printout t " car-group: " ?car-group-name " a(n) " ?description " has a daily rate of: " ?daily-rate crlf) ) ;------End of Rule ---------------------- ;; Calculate One Way Charges Rule (defrule rule4_CalculateOneWayTripCharges (owt (miles-driven ?miles-driven)) (one-way-trip-row (s-distance ?s-distance) (e-distance ?e-distance) (per-mile-charge ?per-mile-charge) (additional-charge ?additional-charge)) (test (and (<= ?s-distance ?miles-driven) (<= ?miles-driven ?e-distance))) => (bind ?owt-charges (+ (* ?miles-driven ?per-mile-charge) ?additional-charge)) (printout t "Unscheduled One-Way Trip charges are: $" ?owt-charges "." crlf " (Charge Breakdown:" crlf " Per-Mile-Charge: $" ?per-mile-charge crlf " Additional charges: $" ?additional-charge ")" crlf) (assert (one-way-trip-charges ?owt-charges)) ) ;------End of Rule ---------------------- ;;; ----------------------------------------------------------------------- (reset) (facts)