(load fish.dat) (load fish2.dat) (load fish3.dat) (load fish4.dat) (reset) (focus FISH) (defrule FISH::getdate => ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf ) ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf ) ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf ) ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf ) ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf ) ( printout t crlf "Enter the Date" crlf "What is the Month (as an integer) ==>") (bind ?month (read) ) (printout t crlf "What is the Day (as an integer)==> ") (bind ?day (read) ) (bind ?day2 (+ ?day 10000)) (bind ?month2 (+ (* ?month 100) 10000)) (assert (date (categ today) (month ?month) (day ?day) (dateint (+ ?month2 ?day2)))) ) (defrule FISH::whatsonthemenu (fish (species ?sp) (open_season ?open) (close_season ?close) (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm) (fishing_type ?tp) (fishing_location ?loc) (best_trip $?dn) (desireability ?ds )) (date (dateint ?today)) (test ( openseason ?open ?close ?today)) => (assert (menu (species ?sp) (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm) (fishing_type ?tp) (fishing_location ?loc) (best_trip $?dn) (desireability ?ds ) (bonus OFF))) (printout t crlf ?sp " is open now. They are currently at " ?hb " and best fished during the " ?sa " season. " crlf ) (printout t "We can fish for them by " ?tp " fishing " ?loc ". " crlf ) (printout t "You can have " ?lm " fish and it is best to fish for them during the " $?dn " trip(s). " crlf ) (printout t "On a scale of 1-5 they are desireable: " ?ds crlf crlf ) ) (defrule FISH::testrule (menu (seasonal_availability $sa3)) => (printout t "==> " $sa3 crlf) ) (defrule FISH::goodseason ?f1 <- (menu (species ?sp) (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm) (fishing_type ?tp) (fishing_location ?loc) (best_trip $?dn) (desireability ?ds )(bonus OFF)) (date (dateint ?today)) (season ( description ?sa )(start_date ?open) (end_date ?close)) (test ( openseason ?open ?close ?today)) => (bind ?ds (+ ?ds 2)) ; GOOD SEASON MORE DESIRABLE BY 2 (retract ?f1) (assert (menu (species ?sp) (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm) (fishing_type ?tp) (fishing_location ?loc) (best_trip ?dn) (desireability ?ds ) (bonus ON) ) ) (printout t "Oh we are in Season - even better. This is " ?sa " SEASON" crlf ) (printout t ?sp " is open now. They are currently at " ?hb " and best fished NOW!. " crlf ) (printout t "We can fish for them by " ?tp " fishing " ?loc ". " crlf ) (printout t "You can have " ?lm " fish and it is best to fish for them during the " $?dn " trip(s). " crlf ) (printout t "and they are now at desireable level: " ?ds crlf crlf ) ) ;WEATHER MODULE (focus WEATHER) (defrule WEATHER::WAVEHEIGHT => (printout t "What is the expected Wave Heights today =>" crlf ) (bind ?height (read)) (assert (wave_height ( height ?height ))) ) (defrule WEATHER::SWELL => (printout t "What Swell Period in Seconds =>" crlf ) (bind ?sec (read)) (assert (swells( seconds ?sec ))) ) (defrule WEATHER::WIND => (printout t "What is the expected wind speed in knots =>" crlf ) (bind ?speed (read)) (printout t "From what direction is the wind from? (NORTH SOUTH EAST or WEST) =>" crlf ) (bind ?direction (read)) (assert (wind_speed (speed ?speed)(dir ?direction))) ) (defrule WEATHER::CANCEL (or (wave_height (height ?ht&:(>= ?ht 10))) (wind_speed (speed ?sp&:(>= ?sp 30))) (wind_speed (speed ?sp&:(>= ?sp 20)) (dir EAST)) (swells (seconds ?sec&:(>= ?sec 6))) ) => (assert (acceptable_condition (locale cancel))) (printout t "Weather is too harsh to fish" crlf ) (exit) ) (defrule WEATHER::HIGHWINDS (wind_speed (speed ?sp&:(and (>= ?sp 20 ) (< ?sp 30 ))) (dir ~EAST)) => (assert (acceptable_condition (locale inshore) (fsh_type bottom))) ) (defrule WEATHER::MODERATEWINDS (wind_speed (speed ?sp&:(and(>= ?sp 15) (< ?sp 20))) (dir WEST)) => (assert (acceptable_condition (locale offshore) (fsh_type bottom))) (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type bottom))) (assert (acceptable_condition(locale inshore) (fsh_type bottom))) (assert (acceptable_condition(locale inshore) (fsh_type game))) (assert (acceptable_condition(locale inshore) (fsh_type jigging))) (assert (acceptable_condition(locale inshore) (fsh_type wreck))) ) (defrule WEATHER::MODERATE_HARSH_WINDS (wind_speed (speed ?sp&:(and(>= ?sp 15) (< ?sp 20))) (dir ~WEST)) => (assert (acceptable_condition(locale inshore) (fsh_type game))) (assert (acceptable_condition(locale inshore) (fsh_type bottom))) ) (defrule WEATHER::CALMSEAS (wind_speed (speed ?sp&:(< ?sp 15))) => (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type bottom))) (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type game))) (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type jigging))) (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type wreck))) (assert (acceptable_condition (locale offshore) (fsh_type bottom))) (assert (acceptable_condition (locale offshore) (fsh_type game))) (assert (acceptable_condition (locale offshore) (fsh_type jigging))) (assert (acceptable_condition (locale offshore) (fsh_type wreck))) (assert (acceptable_condition (locale inshore) (fsh_type bottom))) (assert (acceptable_condition (locale inshore) (fsh_type game))) (assert (acceptable_condition (locale inshore) (fsh_type jigging))) (assert (acceptable_condition (locale inshore) (fsh_type wreck))) (assert (acceptable_condition (locale open_ocean) (fsh_type bottom))) (assert (acceptable_condition (locale open_ocean) (fsh_type game))) (assert (acceptable_condition (locale open_ocean) (fsh_type jigging))) (assert (acceptable_condition (locale open_ocean) (fsh_type wreck))) ) (focus TRIP) (defrule TRIP::all_possible_trips ?f1 <- (menu (species ?spec) (habitat $?hab) (size_min ?min) (limit ?lim) (fishing_type ?ft) (fishing_location ?loc) (best_trip $?) (desireability ?ds)) ?f2 <- (acceptable_condition (locale ?loc) (fsh_type ?ft)) => (retract ?f1) (assert (all_trips (location ?loc) (method ?ft) (species ?spec) (desireability ?ds) (check 1))) ) (defrule TRIP::make_table ?f1 <- (all_trips (location ?s_loc) (method ?s_ft) ) => (assert (table (location ?s_loc) (method ?s_ft) )) ) (defrule TRIP::eval_function_new ?f1 <- (table (location ?s_loc) (method ?s_ft)) ?f2 <- (all_trips (location ?s_loc) (method ?s_ft) (species $?spec) (desireability ?ds) (check 1)) (not (exists (trips (location ?s_loc ) (method ?s_ft)))) ;restrict to new entries only => (modify ?f2 (check -1)); (assert (trips (location ?s_loc ) (method ?s_ft) (species ?spec ) (desireability ?ds))) ) (defrule TRIP::eval_function_cont ?f3 <- (trips (location ?s_loc ) (method ?s_ft) (species $?species ) (desireability ?sum)) ;current data in trips ?f1 <- (table (location ?s_loc) (method ?s_ft)) ?f2 <- (all_trips (location ?s_loc) (method ?s_ft) (species $?spec) (desireability ?ds) (check 1)) => (modify ?f2 (check -1)) (retract ?f3) (assert (trips (location ?s_loc ) (method ?s_ft) (species =(create$ ?species ?spec )) (desireability =(+ ?sum ?ds)))) ; unify old data with new data ) (defrule TRIP::send_report (not (exists (menu (species ?)))) (not (exists(all_trips (check 1 ))));all trips processed (all_trips (check -1)); and at least one finished ?f1 <- (print_report (value off)) => (modify ?f1 (value on)) (printout t "TURNING ON REPORT" crlf) ) (focus REPORT) ( defrule REPORT::MAXIE ?f2 <- (report_phase header) ?f1 <- (tops ?) (trips (location ?s_loc) (method ?s_ft) (species $?species) (desireability ?MAX)) (not (trips (desireability ?LOWER&:(< ?MAX ?LOWER)))) => (retract ?f2) (retract ?f1) (assert (report_phase choice)) (assert (tops ?MAX )) (printout t "MAX PROFIT Points is ==>" ?MAX crlf crlf crlf crlf) (printout t "*********Best Trip**********" crlf ) ) ( defrule REPORT::MAXIE_PRINT ?f2<-(report_phase choice) ?f1<-(tops ?MAX) (trips (location ?s_loc) (method ?s_ft) (species $?species) (desireability ?MAX)) => (retract ?f2) (assert (report_phase body)) (format t "Trip: %-25s Method: %-6s Species: %-25s" ?s_loc ?s_ft (implode$ ?species) ) (printout t crlf "*********Best Trip**********" crlf crlf crlf "-----------------------------------------------------------------------------" crlf ) ) (defrule REPORT::final_report (report_phase body) (trips (location ?s_loc) (method ?s_ft) (species $?species) (desireability ?ds)) => (format t "Trip: %-25s Method: %-6s Species: %-25s" ?s_loc ?s_ft (implode$ ?species) ) (printout t crlf) (format t "Profit Points: %4d" ?ds) (printout t crlf crlf ) ) (get-focus-stack) (clear-focus-stack) (reset) (focus FISH WEATHER TRIP REPORT) (run)