Hello everyone, I'm programming thermostat control example from Negnevitsky's "Artificial Intelligence..." in Jess. The rule base consists of simple rules like:
Rule 1: if the day is Monday or Tuesday or Wednesday or Thursday or Friday then today is a workday. Rule 2: if the day is Saturday or Sunday then today is weekend. ... I'm struggling to make the example work with use of 'logical' operator. I got it working with "manual" retraction and assertion of facts: (bind ?*workdays* (create$ Monday Tuesday Wednesday Thursday Friday)) (bind ?*weekend-days* (create$ Saturday Sunday)) (defrule workday-if-M-F (day ?d&:(member$ ?d ?*workdays*)) ?dow <- (day ?d) => (assert (workday)) (retract ?dow) (bind ?*WEEKDAY* ?d) (bind ?*WEEKEND* False) ) (defrule workday-if-M-F2 (day ?d&:(member$ ?d ?*workdays*)) ?weekend <- (weekend) ?dow <- (day ?d) => (assert (workday)) (retract ?weekend) (retract ?dow) (bind ?*WEEKDAY* ?d) (bind ?*WEEKEND* False) ) (defrule wekeend-if-S-S (day ?d&:(member$ ?d ?*weekend-days*)) ?dow <- (day ?d) => (assert (weekend)) (retract ?dow) (bind ?*WEEKDAY* ?d) (bind ?*WEEKEND* True) ) (defrule wekeend-if-S-S2 (day ?d&:(member$ ?d ?*weekend-days*)) ?workday <- (workday) ?dow <- (day ?d) => (assert (weekend)) (retract ?workday) (retract ?dow) (bind ?*WEEKDAY* ?d) (bind ?*WEEKEND* True) ) Now I *have* to retract "day ..." facts; consider what happens if I don't do that and assert two days simultaneously, like Monday and Saturday: the rule weekend-if-S-S asserts it's weekend and retracts 'workday' fact, and the rule workday-if-M-F asserts it's workday and retracts 'weekend' fact (I managed to kick Jess into infinite loop with the first version this way, heh). I wonder if there is a way to automatically retract 'weekend' / 'workday' with the use of 'logical' operator? I remember it worked very nicely. The problem is the problem at hand requires using condition of variable belonging to a list in a fact that weekend / workday depends on instead of simple dependence on another fact. Regards, Marcin -------------------------------------------------------------------- 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] --------------------------------------------------------------------
