1 (load fish.dat)
  2 (load fish2.dat)
  3 (load fish3.dat)
  4 (load fish4.dat)
  5 (reset)
  6 (focus FISH)
  7 (defrule FISH::getdate
  8    =>
  9  ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf )
 10  ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf )
 11  ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf )
 12  ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf )
 13  ( printout t crlf crlf crlf crlf crlf crlf crlf crlf crlf crlf )
 14  ( printout t crlf "Enter the Date" crlf "What is the Month (as an integer) ==>")
 15  (bind ?month (read) )
 16  (printout t crlf "What is the Day (as an integer)==> ")
 17  (bind ?day (read) )
 18  (bind ?day2 (+ ?day  10000))
 19  (bind ?month2 (+ (* ?month  100) 10000))
 20  (assert (date (categ today) (month ?month) (day ?day) (dateint (+ ?month2 ?day2))))
 21 )
 22 
 23 (defrule FISH::whatsonthemenu
 24  (fish (species ?sp) (open_season ?open) (close_season ?close)
 25        (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm)
 26          (fishing_type ?tp) (fishing_location ?loc) (best_trip $?dn) (desireability ?ds ))
 27  (date (dateint ?today))
 28  (test ( openseason ?open ?close ?today))
 29   =>
 30   (assert (menu (species ?sp) (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm)
 31          (fishing_type ?tp) (fishing_location ?loc) (best_trip $?dn) (desireability ?ds ) (bonus OFF)))
 32   (printout t crlf ?sp " is open now. They are currently at " ?hb  " and best fished during the " ?sa  " season. " crlf )
 33   (printout t "We can fish for them by " ?tp " fishing " ?loc ". " crlf   )
 34   (printout t "You can have " ?lm  " fish and it is best to fish for them during the " $?dn " trip(s). " crlf )
 35   (printout t "On a scale of 1-5 they are desireable: " ?ds crlf crlf )
 36 )
 37 
 38 (defrule FISH::testrule
 39  (menu (seasonal_availability $sa3))
 40  =>
 41  (printout t  "==> " $sa3 crlf)
 42 )
 43 
 44 (defrule FISH::goodseason
 45  ?f1 <- (menu (species ?sp) (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm)
 46         (fishing_type ?tp) (fishing_location ?loc) (best_trip $?dn) (desireability ?ds )(bonus OFF))
 47  (date (dateint ?today))
 48  (season ( description ?sa )(start_date ?open) (end_date ?close))
 49  (test ( openseason ?open ?close ?today))
 50  =>
 51  (bind ?ds (+ ?ds 2)) ; GOOD SEASON MORE DESIRABLE BY 2
 52  (retract ?f1)
 53  (assert (menu (species ?sp) (habitat $?hb) (seasonal_availability ?sa) (size_min ?min) (limit ?lm)
 54                         (fishing_type ?tp) (fishing_location ?loc) (best_trip ?dn) (desireability ?ds ) (bonus ON) )
 55  )
 56  (printout t "Oh we are in Season - even better. This is " ?sa " SEASON"  crlf )
 57  (printout t ?sp " is open now. They are currently at " ?hb  " and best fished NOW!. " crlf )
 58  (printout t "We can fish for them by " ?tp " fishing " ?loc ". " crlf   )
 59  (printout t "You can have " ?lm  " fish and it is best to fish for them during the " $?dn " trip(s). " crlf )
 60  (printout t "and they are now at desireable level: " ?ds crlf crlf )
 61 )
 62 
 63 ;WEATHER MODULE
 64 (focus WEATHER)
 65 
 66 (defrule WEATHER::WAVEHEIGHT
 67    =>
 68    (printout t "What is the expected Wave Heights today =>" crlf )
 69    (bind ?height (read))
 70    (assert (wave_height ( height ?height )))
 71 )
 72 
 73 (defrule WEATHER::SWELL
 74    =>
 75    (printout t "What Swell Period in Seconds =>" crlf )
 76    (bind ?sec (read))
 77    (assert (swells( seconds ?sec )))
 78 )
 79 
 80 (defrule WEATHER::WIND
 81    =>
 82    (printout t "What is the expected wind speed in knots =>" crlf  )
 83    (bind ?speed (read))
 84    (printout t "From what direction is the wind from? (NORTH SOUTH EAST or WEST) =>" crlf  )
 85    (bind ?direction (read))
 86    (assert (wind_speed (speed ?speed)(dir ?direction)))
 87 )
 88 
 89 (defrule WEATHER::CANCEL
 90       (or (wave_height (height ?ht&:(>= ?ht 10)))
 91          (wind_speed (speed ?sp&:(>= ?sp 30)))
 92          (wind_speed (speed ?sp&:(>= ?sp 20)) (dir EAST))
 93          (swells (seconds ?sec&:(>= ?sec 6)))
 94       )
 95 =>
 96    (assert (acceptable_condition (locale cancel)))
 97    (printout t "Weather is too harsh to fish" crlf )
 98    (exit)
 99 )
100 
101 (defrule WEATHER::HIGHWINDS
102    (wind_speed (speed ?sp&:(and (>= ?sp 20 ) (< ?sp 30 ))) (dir ~EAST))
103  =>
104    (assert (acceptable_condition (locale inshore) (fsh_type bottom)))
105 )
106 
107 (defrule WEATHER::MODERATEWINDS
108  (wind_speed (speed ?sp&:(and(>= ?sp 15) (< ?sp 20))) (dir WEST))
109  =>
110   (assert (acceptable_condition (locale offshore) (fsh_type bottom)))
111   (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type bottom)))
112   (assert (acceptable_condition(locale inshore) (fsh_type bottom)))
113   (assert (acceptable_condition(locale inshore) (fsh_type game)))
114   (assert (acceptable_condition(locale inshore) (fsh_type jigging)))
115   (assert (acceptable_condition(locale inshore) (fsh_type wreck)))
116  )
117 
118 (defrule WEATHER::MODERATE_HARSH_WINDS
119  (wind_speed (speed ?sp&:(and(>= ?sp 15) (< ?sp 20))) (dir ~WEST))
120  =>
121   (assert (acceptable_condition(locale inshore) (fsh_type game)))
122   (assert (acceptable_condition(locale inshore) (fsh_type bottom)))
123 )
124 
125 (defrule WEATHER::CALMSEAS
126  (wind_speed (speed ?sp&:(< ?sp 15)))
127  =>
128   (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type bottom)))
129   (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type game)))
130   (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type jigging)))
131   (assert (acceptable_condition (locale offshore_federal_waters) (fsh_type wreck)))
132   (assert (acceptable_condition (locale offshore) (fsh_type bottom)))
133   (assert (acceptable_condition (locale offshore) (fsh_type game)))
134   (assert (acceptable_condition (locale offshore) (fsh_type jigging)))
135   (assert (acceptable_condition (locale offshore) (fsh_type wreck)))
136   (assert (acceptable_condition (locale inshore) (fsh_type bottom)))
137   (assert (acceptable_condition (locale inshore) (fsh_type game)))
138   (assert (acceptable_condition (locale inshore) (fsh_type jigging)))
139   (assert (acceptable_condition (locale inshore) (fsh_type wreck)))
140   (assert (acceptable_condition (locale open_ocean) (fsh_type bottom)))
141   (assert (acceptable_condition (locale open_ocean) (fsh_type game)))
142   (assert (acceptable_condition (locale open_ocean) (fsh_type jigging)))
143   (assert (acceptable_condition (locale open_ocean) (fsh_type wreck)))
144 )
145 
146 (focus TRIP)
147 (defrule TRIP::all_possible_trips
148     ?f1 <- (menu (species ?spec) (habitat $?hab) (size_min ?min)
149        (limit ?lim) (fishing_type ?ft) (fishing_location ?loc) (best_trip $?) (desireability ?ds))
150     ?f2 <- (acceptable_condition (locale ?loc) (fsh_type ?ft))
151 
152     =>
153     (retract ?f1)
154     (assert (all_trips (location ?loc) (method ?ft) (species ?spec) (desireability ?ds) (check 1)))
155 )
156 
157 
158 (defrule TRIP::make_table
159    ?f1 <- (all_trips (location ?s_loc) (method ?s_ft) )
160    =>
161    (assert (table (location ?s_loc) (method ?s_ft) ))
162 )
163 
164 (defrule TRIP::eval_function_new
165  ?f1 <- (table (location ?s_loc) (method ?s_ft))
166  ?f2 <- (all_trips (location ?s_loc) (method ?s_ft) (species $?spec) (desireability ?ds) (check 1))
167  (not (exists (trips (location ?s_loc ) (method ?s_ft)))) ;restrict to new entries only
168  =>
169  (modify ?f2 (check -1));
170  (assert (trips (location ?s_loc ) (method ?s_ft) (species ?spec ) (desireability ?ds)))
171  )
172 
173 (defrule TRIP::eval_function_cont
174  ?f3 <- (trips (location ?s_loc ) (method ?s_ft) (species $?species ) (desireability ?sum)) ;current data in trips
175  ?f1 <- (table (location ?s_loc) (method ?s_ft))
176  ?f2 <- (all_trips (location ?s_loc) (method ?s_ft) (species $?spec) (desireability ?ds) (check 1))
177  =>
178  (modify ?f2 (check -1))
179  (retract ?f3)
180  (assert (trips (location ?s_loc ) (method ?s_ft) (species =(create$ ?species ?spec )) (desireability =(+ ?sum  ?ds)))) ; unify old data with new data
181  )
182 
183 (defrule TRIP::send_report
184    (not (exists (menu (species ?))))
185    (not (exists(all_trips (check 1 ))));all trips processed
186    (all_trips (check -1)); and at least one finished
187    ?f1 <- (print_report (value off))
188 =>
189    (modify ?f1 (value on))
190    (printout t "TURNING ON REPORT" crlf)
191 )
192 
193 (focus REPORT)
194 
195 
196 ( defrule REPORT::MAXIE
197    ?f2 <- (report_phase header)
198    ?f1 <- (tops ?)
199    (trips (location ?s_loc) (method ?s_ft) (species $?species) (desireability ?MAX))
200    (not (trips (desireability ?LOWER&:(< ?MAX ?LOWER))))
201 =>
202    (retract ?f2)
203    (retract ?f1)
204    (assert (report_phase choice))
205    (assert (tops  ?MAX ))
206    (printout t "MAX PROFIT Points is ==>" ?MAX   crlf crlf crlf crlf)
207    (printout t "*********Best Trip**********"   crlf )
208 )
209 
210 ( defrule REPORT::MAXIE_PRINT
211    ?f2<-(report_phase choice)
212    ?f1<-(tops ?MAX)
213    (trips (location ?s_loc) (method ?s_ft) (species $?species) (desireability ?MAX))
214 =>
215    (retract ?f2)
216    (assert (report_phase body))
217    (format t "Trip: %-25s Method: %-6s  Species: %-25s" ?s_loc ?s_ft (implode$ ?species) )
218    (printout t crlf "*********Best Trip**********"   crlf crlf crlf "-----------------------------------------------------------------------------" crlf  )
219 )
220 
221 (defrule REPORT::final_report
222    (report_phase body)
223    (trips (location ?s_loc) (method ?s_ft) (species $?species) (desireability ?ds))
224 =>
225    (format t "Trip: %-25s Method: %-6s  Species: %-25s" ?s_loc ?s_ft (implode$ ?species) )
226    (printout t crlf)
227    (format t "Profit Points: %4d" ?ds)
228    (printout t crlf crlf  )
229 )
230 
231 
232 (get-focus-stack)
233 (clear-focus-stack)
234 (reset)
235 (focus FISH WEATHER TRIP REPORT)
236 (run)
237 
238