;**************************************************************************** ; Computer.clp ; ; There is one difference between WebComputer.clp and Computer.clp. ; In startup-rule of WebComputer.clp, the rule waits for some dummy data ; from the inbetween web server interface. Computer.clp doesn't have that ; wait in it. So when ComputerAdvice is in it's regular mode, nothing will ; happen when WebComputer.clp is executed. ;**************************************************************************** (clear) (watch rules) ; Global Variables (bind ?AmountToSpend 0) (bind ?MoneyBeforeRoundOfPurchases 0) ;****************************************************************************** ; Monitor selection rule ;****************************************************************************** (defrule choose-a-monitor-rule (choose a monitor) ?factnum <- (choose a monitor) => (retract ?factnum) ; Ask the user if they play games with their system (printout JavaApp "Do you want a large monitor (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (HWNeed Monitor med) ) else (assert (HWNeed Monitor std)) ) ) ;****************************************************************************** ; Rule for gaming applications ; ; MAX VideoCard ; MED CPU ; MED RAM ; MED MotherBoard ; MED SoundCard ; MED HD ; STD Speakers ; STD Network ;****************************************************************************** (defrule gaming-rule (application gaming) ?factnum <- (application gaming) => (retract ?factnum) (assert (HWNeed VideoCard max) ) (printout JavaApp "You need a MAX power video card for gaming" crlf) (assert (HWNeed CPU med) ) (printout JavaApp "You need a MED cpu for gaming" crlf) (assert (HWNeed RAM med) ) (printout JavaApp "You need MED RAM for gaming" crlf) (assert (HWNeed MotherBoard med) ) (printout JavaApp "You need a MED motherboard for gaming" crlf) (assert (HWNeed SoundCard med)) (printout JavaApp "You need a MED sound card for gaming" crlf) (assert (HWNeed HD med)) (printout JavaApp "You need a MED size hard drive for gaming" crlf) (assert (HWNeed Speakers std)) (printout JavaApp "You need STD speakers for gaming" crlf) (assert (HWNeed Network std)) (printout JavaApp "You need a STD network connection for gaming" crlf) ) ;****************************************************************************** ; Rule for internet surfing ; ; STD CPU ; MED RAM ; STD VideoCard ; STD Network ; STD SoundCard ; MED HD ; STD Printer ; STD Speakers ;****************************************************************************** (defrule internet-rule (application internet) ?factnum <- (application internet) => (retract ?factnum) (assert (HWNeed RAM med) ) (printout JavaApp "You need MED RAM for Internet surfing" crlf) (assert (HWNeed HD med) ) (printout JavaApp "You need a MED size hard drive for Internet surfing" crlf) (assert (HWNeed CPU std) ) (printout JavaApp "You need STD cpu for Internet surfing" crlf) (assert (HWNeed VideoCard std) ) (printout JavaApp "You need a STD power video card for Internet surfing" crlf) (assert (HWNeed Network std) ) (printout JavaApp "You need a STD network connection device for Internet surfing" crlf) (assert (HWNeed SoundCard std) ) (printout JavaApp "You need a STD sound card for Internet surfing" crlf) (assert (HWNeed Printer std) ) (printout JavaApp "You need a STD printer for Internet surfing" crlf) (assert (HWNeed Speakers std) ) (printout JavaApp "You need a STD speaker system for Internet surfing" crlf) ) ;****************************************************************************** ; Rule for software development ; MAX CPU ; MAX RAM ; STD VideoCard ; STD Network ; MED HD ; STD OpticalWriter ; STD Printer ;****************************************************************************** (defrule development-rule (application development) ?factnum <- (application development) => (retract ?factnum) (assert (HWNeed CPU max) ) (printout JavaApp "You need MAX CPU for software development" crlf) (assert (HWNeed RAM max) ) (printout JavaApp "You need MAX RAM for software development" crlf) (assert (HWNeed HD med) ) (printout JavaApp "You need MED size hard drive for software development" crlf) (assert (HWNeed VideoCard std) ) (printout JavaApp "You need STD video card for software development" crlf) (assert (HWNeed Network std) ) (printout JavaApp "You need STD network for software development" crlf) (assert (HWNeed OpticalWriter std) ) (printout JavaApp "You need STD optical writing device for software development" crlf) (assert (HWNeed Printer std) ) (printout JavaApp "You need STD printer for software development" crlf) ) ;****************************************************************************** ; Rule for audiophile ; MED CPU ; MAX SoundCard ; MED HD ; STD Optical ; MAX Speakers ;****************************************************************************** (defrule audiophile-rule (application audiophile) ?factnum <- (application audiophile) => (retract ?factnum) (assert (HWNeed Speakers max) ) (printout JavaApp "You need MAX speakers for an audiophile system" crlf) (assert (HWNeed SoundCard max) ) (printout JavaApp "You need MAX sound card for an audiophile system" crlf) (assert (HWNeed CPU med) ) (printout JavaApp "You need MED CPU for an audiophile system" crlf) (assert (HWNeed HD med) ) (printout JavaApp "You need MED size hard drive for an audiophile system" crlf) (assert (HWNeed Optical std) ) (printout JavaApp "You need STD optical reading device for an audiophile system" crlf) ) ;****************************************************************************** ; Rule for videoediting ; MAX CPU ; MED Case ; MAX MotherBoard ; MAX RAM ; MED VideoCard ; STD Network ; MED SoundCard ; MAX HD ; MED Optical ; MED OpticalWriter ; MED Speakers ; STD Capture ;****************************************************************************** (defrule videoediting-rule (application videoediting) ?factnum <- (application videoediting) => (retract ?factnum) (assert (HWNeed CPU max) ) (printout JavaApp "You need MAX CPU for video-editing" crlf) (assert (HWNeed MotherBoard max) ) (printout JavaApp "You need MAX mother board for video-editing" crlf) (assert (HWNeed RAM max) ) (printout JavaApp "You need MAX RAM for video-editing" crlf) (assert (HWNeed HD max) ) (printout JavaApp "You need MAX size hard drive for video-editing" crlf) (assert (HWNeed Case med) ) (printout JavaApp "You need MED case for video-editing" crlf) (assert (HWNeed VideoCard med) ) (printout JavaApp "You need MED video card for video-editing" crlf) (assert (HWNeed SoundCard med) ) (printout JavaApp "You need MED sound card for video-editing" crlf) (assert (HWNeed Optical med) ) (printout JavaApp "You need MED optical reading device for video-editing" crlf) (assert (HWNeed OpticalWriter med) ) (printout JavaApp "You need MED optical writing device for video-editing" crlf) (assert (HWNeed Speakers med) ) (printout JavaApp "You need MED speakers for video-editing" crlf) (assert (HWNeed Network std) ) (printout JavaApp "You need STD network for video-editing" crlf) (assert (HWNeed Capture std) ) (printout JavaApp "You need STD capture card for video-editing" crlf) ) ;****************************************************************************** ; Rule for office ; MED CPU ; MED RAM ; STD Network ; STD SoundCard ; MED HD ; STD Optical ; STD OpticalWriter ; MED Printer ; STD Scanner ; STD Speakers ;****************************************************************************** (defrule office-rule (application office) ?factnum <- (application office) => (retract ?factnum) (assert (HWNeed CPU med) ) (printout JavaApp "You need MED CPU for office applications" crlf) (assert (HWNeed RAM med) ) (printout JavaApp "You need MED RAM for office applications" crlf) (assert (HWNeed HD med) ) (printout JavaApp "You need MED size hard drive for office applications" crlf) (assert (HWNeed Printer med) ) (printout JavaApp "You need MED printer for office applications" crlf) (assert (HWNeed Network std) ) (printout JavaApp "You need STD network for office applications" crlf) (assert (HWNeed SoundCard std) ) (printout JavaApp "You need STD sound card for office applications" crlf) (assert (HWNeed Optical std) ) (printout JavaApp "You need STD optical reading device for office applications" crlf) (assert (HWNeed OpticalWriter std) ) (printout JavaApp "You need STD optical writing device for office applications" crlf) (assert (HWNeed Scanner std) ) (printout JavaApp "You need STD scanner for office applications" crlf) (assert (HWNeed Speakers std) ) (printout JavaApp "You need STD speakers for office applications" crlf) ) ;****************************************************************************** ; Rule for multimediaserver ; MED CPU ; MED Case ; MED MotherBoard ; MAX RAM ; MAX VideoCard ; STD Network ; MED SoundCard ; MAX HD ; MED Optical ; MED OpticalWriter ; STD Speakers ;****************************************************************************** (defrule multimediaserver-rule (application multimediaserver) ?factnum <- (application multimediaserver) => (retract ?factnum) (assert (HWNeed RAM max) ) (printout JavaApp "You need MAX RAM for a multimedia server" crlf) (assert (HWNeed VideoCard max) ) (printout JavaApp "You need MAX video card for a multimedia server" crlf) (assert (HWNeed HD max) ) (printout JavaApp "You need MAX size hard drive for a multimedia server" crlf) (assert (HWNeed CPU med) ) (printout JavaApp "You need MED CPU for a multimedia server" crlf) (assert (HWNeed Case med) ) (printout JavaApp "You need MED case for a multimedia server" crlf) (assert (HWNeed MotherBoard med) ) (printout JavaApp "You need MED motherboard for a multimedia server" crlf) (assert (HWNeed SoundCard med) ) (printout JavaApp "You need MED sound card for a multimedia server" crlf) (assert (HWNeed Optical med) ) (printout JavaApp "You need MED optical reading device for a multimedia server" crlf) (assert (HWNeed OpticalWriter med) ) (printout JavaApp "You need MED optical writing device for a multimedia server" crlf) (assert (HWNeed Network std) ) (printout JavaApp "You need STD network for a multimedia server" crlf) (assert (HWNeed Speakers std) ) (printout JavaApp "You need STD speakers for a multimedia server" crlf) ) ;****************************************************************************** ; Rule for webserver ; MAX CPU ; MAX Case ; MAX MotherBoard ; MAX RAM ; STD VideoCard ; STD Network ; MAX HD ;****************************************************************************** (defrule webserver-rule (application webserver) ?factnum <- (application webserver) => (retract ?factnum) (assert (HWNeed CPU max) ) (printout JavaApp "You need MAX CPU for a web server" crlf) (assert (HWNeed Case max) ) (printout JavaApp "You need MAX case for a web server" crlf) (assert (HWNeed MotherBoard max) ) (printout JavaApp "You need MAX motherboard for a web server" crlf) (assert (HWNeed RAM max) ) (printout JavaApp "You need MAX RAM for a web server" crlf) (assert (HWNeed HD max) ) (printout JavaApp "You need MAX size hard drive for a web server" crlf) (assert (HWNeed VideoCard std) ) (printout JavaApp "You need STD network for a web server" crlf) (assert (HWNeed Network std) ) (printout JavaApp "You need STD network for a web server" crlf) ) ;****************************************************************************** ; Rule for graphics ; MAX CPU ; MED MotherBoard ; MAX RAM ; MAX VideoCard ; MED HD ; STD Optical ; STD OpticalWriter ; MED Scanner ; MED Printer ;****************************************************************************** (defrule graphics-rule (application graphics) ?factnum <- (application graphics) => (retract ?factnum) (assert (HWNeed CPU max) ) (printout JavaApp "You need MAX CPU for graphics development" crlf) (assert (HWNeed RAM max) ) (printout JavaApp "You need MAX RAM for graphics development" crlf) (assert (HWNeed VideoCard max) ) (printout JavaApp "You need MAX video card for graphics development" crlf) (assert (HWNeed MotherBoard med) ) (printout JavaApp "You need MED mother board for graphics development" crlf) (assert (HWNeed HD med) ) (printout JavaApp "You need MED size hard drive for graphics development" crlf) (assert (HWNeed Scanner med) ) (printout JavaApp "You need MED scanner for graphics development" crlf) (assert (HWNeed Printer med) ) (printout JavaApp "You need MED printer for graphics development" crlf) (assert (HWNeed Optical std) ) (printout JavaApp "You need STD optical reading device for graphics development" crlf) (assert (HWNeed OpticalWriter std) ) (printout JavaApp "You need STD optical writing device for graphics development" crlf) ) ;****************************************************************************** ;****************************************************************************** ;****************************************************************************** ; ; Hardware Optimization Rules ; ;****************************************************************************** ;****************************************************************************** ;****************************************************************************** ;****************************************************************************** ; All In Wonder rule ; ; All In Wonder has both graphics and capture in one device ;****************************************************************************** (defrule all-in-wonder-std-rule (declare (salience -20)) (HWNeed VideoCard std) (HWNeed Capture std) ?factnum1 <- (HWNeed VideoCard std) ?factnum2 <- (HWNeed Capture std) => (retract ?factnum1) (retract ?factnum2) (assert (HWNeed AIW std)) (printout JavaApp "Hardware Optimization: All In Wonder STD video/capture card" crlf) ) (defrule all-in-wonder-med-rule (declare (salience -20)) (HWNeed VideoCard med) (HWNeed Capture std) ?factnum1 <- (HWNeed VideoCard med) ?factnum2 <- (HWNeed Capture std) => (retract ?factnum1) (retract ?factnum2) (assert (HWNeed AIW med)) (printout JavaApp "Hardware Optimization: All In Wonder MED video/capture card" crlf) ) (defrule all-in-wonder-max-rule (declare (salience -20)) (HWNeed VideoCard max) (HWNeed Capture std) ?factnum1 <- (HWNeed VideoCard max) ?factnum2 <- (HWNeed Capture std) => (retract ?factnum1) (retract ?factnum2) (assert (HWNeed AIW max)) (printout JavaApp "Hardware Optimization: All In Wonder MAX video/capture card" crlf) ) ;****************************************************************************** ; DDR Ram rule. ; ; DDR ram is good for high speed CPU, RAM, and MotherBoard combination. ;****************************************************************************** (defrule DDR-Ram-med-med-rule (declare (salience -20)) (HWNeed MotherBoard med) (HWNeed CPU med) (HWNeed RAM ?RamReq) ?factnum <- (HWNeed RAM ?RamReq) => ; (retract ?factnum) (assert (HWNeed DDRRAM ?RamReq)) (printout JavaApp "Hardware Optimization: " ?RamReq " DDR-RAM" crlf) ) (defrule DDR-Ram-med-max-rule (declare (salience -20)) (HWNeed MotherBoard med) (HWNeed CPU max) (HWNeed RAM ?RamReq) ?factnum <- (HWNeed RAM ?RamReq) => ; (retract ?factnum) (assert (HWNeed DDRRAM ?RamReq)) (printout JavaApp "Hardware Optimization: " ?RamReq " DDR-RAM" crlf) ) (defrule DDR-Ram-max-med-rule (declare (salience -20)) (HWNeed MotherBoard max) (HWNeed CPU med) (HWNeed RAM ?RamReq) ?factnum <- (HWNeed RAM ?RamReq) => ; (retract ?factnum) (assert (HWNeed DDRRAM ?RamReq)) (printout JavaApp "Hardware Optimization: " ?RamReq " DDR-RAM" crlf) ) (defrule DDR-Ram-max-max-rule (declare (salience -20)) (HWNeed MotherBoard max) (HWNeed CPU max) (HWNeed RAM ?RamReq) ?factnum <- (HWNeed RAM ?RamReq) => ; (retract ?factnum) (assert (HWNeed DDRRAM ?RamReq)) (printout JavaApp "Hardware Optimization: " ?RamReq " DDR-RAM" crlf) ) ;****************************************************************************** ; DDR MotherBoard rule. ; ; If DDR-RAM is used, a DDR supported motherboard should be used also ;****************************************************************************** (defrule ddr-motherboard-max-rule (declare (salience -20)) (HWNeed MotherBoard max) (HWNeed DDRRAM ?DontCare) ?factnum <- (HWNeed MotherBoard max) => (retract ?factnum) (assert (HWNeed DDRMotherBoard max)) (printout JavaApp "Hardware Optimization: MAX DDR Motherboard" crlf) ) (defrule ddr-motherboard-med-rule (declare (salience -20)) (HWNeed MotherBoard med) (HWNeed DDRRAM ?DontCare) ?factnum <- (HWNeed MotherBoard med) => (retract ?factnum) (assert (HWNeed DDRMotherBoard med)) (printout JavaApp "Hardware Optimization: MED DDR Motherboard" crlf) ) ;****************************************************************************** ; Wireless Optical Mouse ; ; Used if the user wants both a wireless mouse and optical mouse. ;****************************************************************************** (defrule wireless-optical-mouse-rule (declare (salience -20)) (HWNeed OpticalMouse std) (HWNeed WirelessMouse std) ?factnum1 <- (HWNeed OpticalMouse std) ?factnum2 <- (HWNeed WirelessMouse std) => (retract ?factnum1) (retract ?factnum2) (assert (HWNeed WirelessOpticalMouse std)) (printout JavaApp "Hardware Optimization: Wireless Optical Mouse" crlf) ) ;****************************************************************************** ; PrinterFaxScanner rule ; ; Used if the user needs both a nice scanner and printer. A cheap printer and ; cheap scanner is cheaper than a cheap printerscannerfax machine. ;****************************************************************************** (defrule printer-fax-scanner-rule (declare (salience -20)) (HWNeed Scanner med) (HWNeed Printer med) ?factnum1 <- (HWNeed Scanner med) ?factnum2 <- (HWNeed Printer med) => (retract ?factnum1) (retract ?factnum2) (assert (HWNeed PrinterFaxScanner med)) (printout JavaApp "Hardware Optimization: Printer/Scanner/Fax" crlf) ) ;****************************************************************************** ; Simplification rules ; ; I have no idea why the line where the fact number is found has to be a ; preposition for the rule. It will not work if moved into the conclusion. ;****************************************************************************** (defrule eliminate-med-rule (declare (salience 50)) (HWNeed ?hardware max) (HWNeed ?hardware med) ?factnum <- (HWNeed ?hardware med) => (retract ?factnum) ) (defrule eliminate-std-rule (declare (salience 50)) (HWNeed ?hardware max) (HWNeed ?hardware std) ?factnum <- (HWNeed ?hardware std) => (retract ?factnum) ) (defrule eliminate-std2-rule (declare (salience 50)) (HWNeed ?hardware med) (HWNeed ?hardware std) ?factnum <- (HWNeed ?hardware std) => (retract ?factnum) ) (defrule eliminate-pc133ram-rule (declare (salience 50)) (HWNeed RAM ?dimm) (HWNeed DDRRAM ?ddr) ?factnum <- (HWNeed RAM ?dimm) => (retract ?factnum) ) (defrule eliminate-mouse-rule1 (declare (salience 50)) (HWNeed Mouse ?stdmouse) (HWNeed OpticalMouse ?opticalmouse) ?factnum <- (HWNeed Mouse ?stdmouse) => (retract ?factnum) ) (defrule eliminate-mouse-rule2 (declare (salience 50)) (HWNeed Mouse ?stdmouse) (HWNeed WirelessMouse ?wirelessmouse) ?factnum <- (HWNeed Mouse ?stdmouse) => (retract ?factnum) ) (defrule eliminate-kb-rule (declare (salience 50)) (HWNeed KB ?stdkb) (HWNeed WirelessKB ?wirelesskb) ?factnum <- (HWNeed KB ?stdkb) => (retract ?factnum) ) ;****************************************************************************** ; Assert starting condition ;****************************************************************************** (assert (start selection) ) ;****************************************************************************** ; When the batch command is used to open the file, this is the first thing ; the user will see prompting them for inputs. ;****************************************************************************** (defrule startup-rule (start selection) ?factnum <- (start selection) => (retract ?factnum) ; Wait for the ComputerAdvice to signal its ready (bind ?userselection (read JavaApp)) ; Ask the user if they play games with their system (printout JavaApp "Do you use your computer for gaming? (y or n)" crlf) (printout JavaApp " Note: If the only games you play are 5 years old or older, answer no" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application gaming) ) ) ; Ask the user if they do video editing with their system (printout JavaApp "Do you use your computer for video-editing? (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application videoediting) ) ) ; Ask the user if they surf the internet (printout JavaApp "Do you surf the internet with your computer (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application internet) ) ) ; Ask the user if they do software development (printout JavaApp "Do you develop software with your computer (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application development) ) ) ; Ask the user if they are an audiophile (printout JavaApp "Would you consider yourself an audiophile (y or n)" crlf) (printout JavaApp " Example: You want to hear your speakers in surround sound" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application audiophile) ) ) ; Ask the user if they use home office applications (printout JavaApp "Do you use computer for home office applications (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application office) ) ) ; Ask the user if they need a multimedia server (printout JavaApp "Do want to use your computer as a multimedia server (y or n)" crlf) (printout JavaApp " Example: You want to play movies/music on your computer for the house" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application multimediaserver) ) ) ; Ask the user if want to create a webserver (printout JavaApp "Is this computer going to be a webserver (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application webserver) ) ) ; Ask the user if they will be doing graphics development (printout JavaApp "Will the computer be used for graphics development (y or n)" crlf) (printout JavaApp " Examples: Photoshop, AutoCAD, 3D Rendering" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (application graphics) ) ) ; Ask the user if they need a monitor (printout JavaApp "Do you need a monitor for your system (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (choose a monitor) ) ) ; Ask the user if want an optical mouse with their system (printout JavaApp "Do you want the mouse to be optical (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (HWNeed OpticalMouse std) ) ) ; Ask the user if they want wireless keyboard and mouse (printout JavaApp "Do you want the keyboard and mouse to be wireless (y or n)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?userselection (read JavaApp) ) (if (eq ?userselection y) then (assert (HWNeed WirelessKB std) ) ) (if (eq ?userselection y) then (assert (HWNeed WirelessMouse std) ) ) ; Assert the rule that asks the user to calculate the budget (assert (ready to ask for budget)) ; Assert the rules for must-have components (assert (HWNeed CPU std)) (assert (HWNeed Case std)) (assert (HWNeed MotherBoard std)) (assert (HWNeed RAM std)) (assert (HWNeed HD std)) (assert (HWNeed Optical std)) (assert (HWNeed Mouse std)) (assert (HWNeed KB std)) (assert (HWNeed Floppy std)) ) ;****************************************************************************** ; This rule is seperate from the other rules because it needs to run last. It ; can only run after the other rules, because this rule will fire off the rules ; that actually build the system. ;****************************************************************************** (defrule ask-for-budget-rule (declare (salience -100)) (ready to ask for budget) ?factnum <- (ready to ask for budget) => (retract ?factnum) ; Ask the user how much they have to spend on the new system (printout JavaApp "How much do you expect to spend on the new system? (integers only)" crlf) (printout JavaApp "JESS-PROMPT_USER" crlf) (bind ?AmountToSpend (read JavaApp) ) (printout JavaApp "Computer System Budget: " ?AmountToSpend crlf) (assert (purchase standard hardware)) ) ;****************************************************************************** ; This rule is fired only once. It purchases the standard hardware. This ; hardware is the very lowest needed, and the minimum is purchased. ;****************************************************************************** (defrule purchasing-standard-hardware (declare (salience -100)) (purchase standard hardware) ?factnum <- (purchase standard hardware) => (retract ?factnum) ; Buy one of everything! (assert (purchase Optical std)) (assert (purchase CPU std)) (assert (purchase RAM std)) (assert (purchase VideoCard std)) (assert (purchase Scanner std)) (assert (purchase Printer std)) (assert (purchase OpticalWriter std)) (assert (purchase Scanner std)) (assert (purchase Speakers std)) (assert (purchase SoundCard std)) (assert (purchase Printer std)) (assert (purchase Capture std)) (assert (purchase Case std)) (assert (purchase MotherBoard std)) (assert (purchase HD std)) (assert (purchase Network std)) (assert (purchase AIW std)) (assert (purchase DDRRAM std)) (assert (purchase DDRMotherBoard std)) (assert (purchase OpticalMouse std)) (assert (purchase WirelessKB std)) (assert (purchase WirelessMouse std)) (assert (purchase Mouse std)) (assert (purchase KB std)) (assert (purchase WirelessOpticalMouse std)) (assert (purchase Floppy std)) (assert (purchase PrinterFaxScanner std)) (assert (purchase Monitor std)) (assert (purchase max hardware one)) ) ;****************************************************************************** ; This is the state that purchases the max hardware components. State 1 in ; the purchasing loop. ;****************************************************************************** (defrule Purchase-Max-Hardware-First-State (declare (salience -100)) (purchase max hardware one) ?factnum <- (purchase max hardware one) => (retract ?factnum) ; Remember how much money was here when the hardware purchasing started. (bind ?MoneyBeforeRoundOfPurchases ?AmountToSpend) (assert (purchase Optical max)) (assert (purchase CPU max)) (assert (purchase RAM max)) (assert (purchase VideoCard max)) (assert (purchase Scanner max)) (assert (purchase Printer max)) (assert (purchase OpticalWriter max)) (assert (purchase Scanner max)) (assert (purchase Speakers max)) (assert (purchase SoundCard max)) (assert (purchase Printer max)) (assert (purchase Capture max)) (assert (purchase Case max)) (assert (purchase MotherBoard max)) (assert (purchase HD max)) (assert (purchase Network max)) (assert (purchase AIW max)) (assert (purchase DDRRAM max)) (assert (purchase DDRMotherBoard max)) (assert (purchase OpticalMouse max)) (assert (purchase WirelessKB max)) (assert (purchase WirelessMouse max)) (assert (purchase Mouse max)) (assert (purchase KB max)) (assert (purchase WirelessOpticalMouse max)) (assert (purchase Floppy max)) (assert (purchase PrinterFaxScanner max)) (assert (purchase Monitor max)) (assert (purchase med hardware)) ) ;****************************************************************************** ; This is the state that purchases the med hardware components. State 2 in ; the purchasing loop. ;****************************************************************************** (defrule Purchase-Med-Hardware (declare (salience -100)) (purchase med hardware) ?factnum <- (purchase med hardware) => (retract ?factnum) ; Remember how much money was here when the hardware purchasing started. (bind ?MoneyBeforeRoundOfPurchases ?AmountToSpend) (assert (purchase Optical med)) (assert (purchase CPU med)) (assert (purchase RAM med)) (assert (purchase VideoCard med)) (assert (purchase Scanner med)) (assert (purchase Printer med)) (assert (purchase OpticalWriter med)) (assert (purchase Scanner med)) (assert (purchase Speakers med)) (assert (purchase SoundCard med)) (assert (purchase Printer med)) (assert (purchase Capture med)) (assert (purchase Case med)) (assert (purchase MotherBoard med)) (assert (purchase HD med)) (assert (purchase Network med)) (assert (purchase AIW med)) (assert (purchase DDRRAM med)) (assert (purchase DDRMotherBoard med)) (assert (purchase OpticalMouse med)) (assert (purchase WirelessKB med)) (assert (purchase WirelessMouse med)) (assert (purchase Mouse med)) (assert (purchase KB med)) (assert (purchase WirelessOpticalMouse med)) (assert (purchase Floppy med)) (assert (purchase PrinterFaxScanner med)) (assert (purchase Monitor med)) (assert (purchase max hardware two)) ) ;****************************************************************************** ; This is the state that purchases the max hardware components. State 3 in ; the purchasing loop. ;****************************************************************************** (defrule Purchase-Max-Hardware-Second-State (declare (salience -100)) (purchase max hardware two) ?factnum <- (purchase max hardware two) => (retract ?factnum) (assert (purchase Optical max)) (assert (purchase CPU max)) (assert (purchase RAM max)) (assert (purchase VideoCard max)) (assert (purchase Scanner max)) (assert (purchase Printer max)) (assert (purchase OpticalWriter max)) (assert (purchase Scanner max)) (assert (purchase Speakers max)) (assert (purchase SoundCard max)) (assert (purchase Printer max)) (assert (purchase Capture max)) (assert (purchase Case max)) (assert (purchase MotherBoard max)) (assert (purchase HD max)) (assert (purchase Network max)) (assert (purchase AIW max)) (assert (purchase DDRRAM max)) (assert (purchase DDRMotherBoard max)) (assert (purchase OpticalMouse max)) (assert (purchase WirelessKB max)) (assert (purchase WirelessMouse max)) (assert (purchase Mouse max)) (assert (purchase KB max)) (assert (purchase WirelessOpticalMouse max)) (assert (purchase Floppy max)) (assert (purchase PrinterFaxScanner max)) (assert (purchase Monitor max)) (assert (decide purchase more hardware)) ) ;****************************************************************************** ; This is the rule that actually talks to ComputerAdvice Java application to ; purchase the hardware from the cost database. ;****************************************************************************** (defrule purchase-hardware (declare (salience 100)) (purchase ?ComponentName ?Level) (HWNeed ?ComponentName ?Level) ?factnum <- (purchase ?ComponentName ?B) => (retract ?factnum) (printout JavaApp "JESS-HWCDB:" ?ComponentName ":" ?AmountToSpend crlf) (bind ?AmountToSpend (read JavaApp)) ) ;****************************************************************************** ; Decide if more hardware should be purchased ;****************************************************************************** (defrule more-purchases (declare (salience -100)) (decide purchase more hardware) ?factnum <- (decide purchase more hardware) => (retract ?factnum) (if (eq ?AmountToSpend ?MoneyBeforeRoundOfPurchases) then (assert (print system info)) else (assert(purchase max hardware one)) ) ) ;****************************************************************************** ; Print out the system info and close down the Java front end. ;****************************************************************************** (defrule print-system-info (print system info) ?factnum <- (print system info) => (retract ?factnum) (printout JavaApp "JESS-PRINT_SYSTEM_INFO" crlf) (printout JavaApp "JESS-FINISHED" crlf) ) ; Create a socket connection to Computer Advice front end (socket 127.0.0.1 8034 JavaApp) (run) (facts) (rules)