clipsruby 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clipsruby/agenda.c +1373 -0
  3. data/ext/clipsruby/agenda.h +169 -0
  4. data/ext/clipsruby/analysis.c +1142 -0
  5. data/ext/clipsruby/analysis.h +61 -0
  6. data/ext/clipsruby/argacces.c +526 -0
  7. data/ext/clipsruby/argacces.h +77 -0
  8. data/ext/clipsruby/bload.c +884 -0
  9. data/ext/clipsruby/bload.h +94 -0
  10. data/ext/clipsruby/bmathfun.c +557 -0
  11. data/ext/clipsruby/bmathfun.h +66 -0
  12. data/ext/clipsruby/bsave.c +634 -0
  13. data/ext/clipsruby/bsave.h +130 -0
  14. data/ext/clipsruby/classcom.c +976 -0
  15. data/ext/clipsruby/classcom.h +115 -0
  16. data/ext/clipsruby/classexm.c +1376 -0
  17. data/ext/clipsruby/classexm.h +97 -0
  18. data/ext/clipsruby/classfun.c +1392 -0
  19. data/ext/clipsruby/classfun.h +164 -0
  20. data/ext/clipsruby/classinf.c +1245 -0
  21. data/ext/clipsruby/classinf.h +94 -0
  22. data/ext/clipsruby/classini.c +843 -0
  23. data/ext/clipsruby/classini.h +75 -0
  24. data/ext/clipsruby/classpsr.c +957 -0
  25. data/ext/clipsruby/classpsr.h +73 -0
  26. data/ext/clipsruby/clips.h +133 -0
  27. data/ext/clipsruby/clipsruby.c +619 -0
  28. data/ext/clipsruby/clsltpsr.c +931 -0
  29. data/ext/clipsruby/clsltpsr.h +72 -0
  30. data/ext/clipsruby/commline.c +1217 -0
  31. data/ext/clipsruby/commline.h +131 -0
  32. data/ext/clipsruby/conscomp.c +1593 -0
  33. data/ext/clipsruby/conscomp.h +150 -0
  34. data/ext/clipsruby/constant.h +264 -0
  35. data/ext/clipsruby/constrct.c +1090 -0
  36. data/ext/clipsruby/constrct.h +216 -0
  37. data/ext/clipsruby/constrnt.c +554 -0
  38. data/ext/clipsruby/constrnt.h +132 -0
  39. data/ext/clipsruby/crstrtgy.c +1088 -0
  40. data/ext/clipsruby/crstrtgy.h +85 -0
  41. data/ext/clipsruby/cstrcbin.c +185 -0
  42. data/ext/clipsruby/cstrcbin.h +61 -0
  43. data/ext/clipsruby/cstrccmp.h +43 -0
  44. data/ext/clipsruby/cstrccom.c +1791 -0
  45. data/ext/clipsruby/cstrccom.h +115 -0
  46. data/ext/clipsruby/cstrcpsr.c +835 -0
  47. data/ext/clipsruby/cstrcpsr.h +97 -0
  48. data/ext/clipsruby/cstrnbin.c +282 -0
  49. data/ext/clipsruby/cstrnbin.h +55 -0
  50. data/ext/clipsruby/cstrnchk.c +826 -0
  51. data/ext/clipsruby/cstrnchk.h +91 -0
  52. data/ext/clipsruby/cstrncmp.c +238 -0
  53. data/ext/clipsruby/cstrncmp.h +57 -0
  54. data/ext/clipsruby/cstrnops.c +1176 -0
  55. data/ext/clipsruby/cstrnops.h +47 -0
  56. data/ext/clipsruby/cstrnpsr.c +1394 -0
  57. data/ext/clipsruby/cstrnpsr.h +88 -0
  58. data/ext/clipsruby/cstrnutl.c +564 -0
  59. data/ext/clipsruby/cstrnutl.h +54 -0
  60. data/ext/clipsruby/default.c +454 -0
  61. data/ext/clipsruby/default.h +57 -0
  62. data/ext/clipsruby/defins.c +971 -0
  63. data/ext/clipsruby/defins.h +127 -0
  64. data/ext/clipsruby/developr.c +677 -0
  65. data/ext/clipsruby/developr.h +69 -0
  66. data/ext/clipsruby/dffctbin.c +477 -0
  67. data/ext/clipsruby/dffctbin.h +76 -0
  68. data/ext/clipsruby/dffctbsc.c +308 -0
  69. data/ext/clipsruby/dffctbsc.h +72 -0
  70. data/ext/clipsruby/dffctcmp.c +297 -0
  71. data/ext/clipsruby/dffctcmp.h +44 -0
  72. data/ext/clipsruby/dffctdef.c +364 -0
  73. data/ext/clipsruby/dffctdef.h +104 -0
  74. data/ext/clipsruby/dffctpsr.c +179 -0
  75. data/ext/clipsruby/dffctpsr.h +49 -0
  76. data/ext/clipsruby/dffnxbin.c +520 -0
  77. data/ext/clipsruby/dffnxbin.h +67 -0
  78. data/ext/clipsruby/dffnxcmp.c +378 -0
  79. data/ext/clipsruby/dffnxcmp.h +54 -0
  80. data/ext/clipsruby/dffnxexe.c +241 -0
  81. data/ext/clipsruby/dffnxexe.h +58 -0
  82. data/ext/clipsruby/dffnxfun.c +1192 -0
  83. data/ext/clipsruby/dffnxfun.h +155 -0
  84. data/ext/clipsruby/dffnxpsr.c +514 -0
  85. data/ext/clipsruby/dffnxpsr.h +57 -0
  86. data/ext/clipsruby/dfinsbin.c +509 -0
  87. data/ext/clipsruby/dfinsbin.h +66 -0
  88. data/ext/clipsruby/dfinscmp.c +345 -0
  89. data/ext/clipsruby/dfinscmp.h +48 -0
  90. data/ext/clipsruby/drive.c +1191 -0
  91. data/ext/clipsruby/drive.h +65 -0
  92. data/ext/clipsruby/emathfun.c +1213 -0
  93. data/ext/clipsruby/emathfun.h +99 -0
  94. data/ext/clipsruby/engine.c +1568 -0
  95. data/ext/clipsruby/engine.h +203 -0
  96. data/ext/clipsruby/entities.h +276 -0
  97. data/ext/clipsruby/envrnbld.c +514 -0
  98. data/ext/clipsruby/envrnbld.h +40 -0
  99. data/ext/clipsruby/envrnmnt.c +257 -0
  100. data/ext/clipsruby/envrnmnt.h +112 -0
  101. data/ext/clipsruby/evaluatn.c +1736 -0
  102. data/ext/clipsruby/evaluatn.h +211 -0
  103. data/ext/clipsruby/expressn.c +494 -0
  104. data/ext/clipsruby/expressn.h +154 -0
  105. data/ext/clipsruby/exprnbin.c +538 -0
  106. data/ext/clipsruby/exprnbin.h +60 -0
  107. data/ext/clipsruby/exprnops.c +564 -0
  108. data/ext/clipsruby/exprnops.h +67 -0
  109. data/ext/clipsruby/exprnpsr.c +1112 -0
  110. data/ext/clipsruby/exprnpsr.h +98 -0
  111. data/ext/clipsruby/extconf.rb +2 -0
  112. data/ext/clipsruby/extnfunc.c +1015 -0
  113. data/ext/clipsruby/extnfunc.h +157 -0
  114. data/ext/clipsruby/factbin.c +447 -0
  115. data/ext/clipsruby/factbin.h +56 -0
  116. data/ext/clipsruby/factbld.c +1035 -0
  117. data/ext/clipsruby/factbld.h +63 -0
  118. data/ext/clipsruby/factcmp.c +386 -0
  119. data/ext/clipsruby/factcmp.h +46 -0
  120. data/ext/clipsruby/factcom.c +759 -0
  121. data/ext/clipsruby/factcom.h +80 -0
  122. data/ext/clipsruby/factfile.c +1761 -0
  123. data/ext/clipsruby/factfile.h +54 -0
  124. data/ext/clipsruby/factfun.c +682 -0
  125. data/ext/clipsruby/factfun.h +77 -0
  126. data/ext/clipsruby/factgen.c +1305 -0
  127. data/ext/clipsruby/factgen.h +229 -0
  128. data/ext/clipsruby/facthsh.c +438 -0
  129. data/ext/clipsruby/facthsh.h +81 -0
  130. data/ext/clipsruby/factlhs.c +250 -0
  131. data/ext/clipsruby/factlhs.h +54 -0
  132. data/ext/clipsruby/factmch.c +905 -0
  133. data/ext/clipsruby/factmch.h +68 -0
  134. data/ext/clipsruby/factmngr.c +3373 -0
  135. data/ext/clipsruby/factmngr.h +325 -0
  136. data/ext/clipsruby/factprt.c +498 -0
  137. data/ext/clipsruby/factprt.h +60 -0
  138. data/ext/clipsruby/factqpsr.c +796 -0
  139. data/ext/clipsruby/factqpsr.h +61 -0
  140. data/ext/clipsruby/factqury.c +1267 -0
  141. data/ext/clipsruby/factqury.h +112 -0
  142. data/ext/clipsruby/factrete.c +978 -0
  143. data/ext/clipsruby/factrete.h +70 -0
  144. data/ext/clipsruby/factrhs.c +667 -0
  145. data/ext/clipsruby/factrhs.h +55 -0
  146. data/ext/clipsruby/filecom.c +353 -0
  147. data/ext/clipsruby/filecom.h +137 -0
  148. data/ext/clipsruby/filertr.c +481 -0
  149. data/ext/clipsruby/filertr.h +94 -0
  150. data/ext/clipsruby/fileutil.c +1020 -0
  151. data/ext/clipsruby/fileutil.h +50 -0
  152. data/ext/clipsruby/generate.c +1079 -0
  153. data/ext/clipsruby/generate.h +57 -0
  154. data/ext/clipsruby/genrcbin.c +902 -0
  155. data/ext/clipsruby/genrcbin.h +69 -0
  156. data/ext/clipsruby/genrccmp.c +640 -0
  157. data/ext/clipsruby/genrccmp.h +59 -0
  158. data/ext/clipsruby/genrccom.c +2017 -0
  159. data/ext/clipsruby/genrccom.h +119 -0
  160. data/ext/clipsruby/genrcexe.c +737 -0
  161. data/ext/clipsruby/genrcexe.h +73 -0
  162. data/ext/clipsruby/genrcfun.c +890 -0
  163. data/ext/clipsruby/genrcfun.h +185 -0
  164. data/ext/clipsruby/genrcpsr.c +1618 -0
  165. data/ext/clipsruby/genrcpsr.h +80 -0
  166. data/ext/clipsruby/globlbin.c +458 -0
  167. data/ext/clipsruby/globlbin.h +71 -0
  168. data/ext/clipsruby/globlbsc.c +361 -0
  169. data/ext/clipsruby/globlbsc.h +83 -0
  170. data/ext/clipsruby/globlcmp.c +330 -0
  171. data/ext/clipsruby/globlcmp.h +52 -0
  172. data/ext/clipsruby/globlcom.c +289 -0
  173. data/ext/clipsruby/globlcom.h +63 -0
  174. data/ext/clipsruby/globldef.c +1087 -0
  175. data/ext/clipsruby/globldef.h +151 -0
  176. data/ext/clipsruby/globlpsr.c +530 -0
  177. data/ext/clipsruby/globlpsr.h +59 -0
  178. data/ext/clipsruby/immthpsr.c +431 -0
  179. data/ext/clipsruby/immthpsr.h +55 -0
  180. data/ext/clipsruby/incrrset.c +530 -0
  181. data/ext/clipsruby/incrrset.h +73 -0
  182. data/ext/clipsruby/inherpsr.c +850 -0
  183. data/ext/clipsruby/inherpsr.h +52 -0
  184. data/ext/clipsruby/inscom.c +2076 -0
  185. data/ext/clipsruby/inscom.h +182 -0
  186. data/ext/clipsruby/insfile.c +1764 -0
  187. data/ext/clipsruby/insfile.h +96 -0
  188. data/ext/clipsruby/insfun.c +1451 -0
  189. data/ext/clipsruby/insfun.h +134 -0
  190. data/ext/clipsruby/insmngr.c +2550 -0
  191. data/ext/clipsruby/insmngr.h +125 -0
  192. data/ext/clipsruby/insmoddp.c +1041 -0
  193. data/ext/clipsruby/insmoddp.h +91 -0
  194. data/ext/clipsruby/insmult.c +804 -0
  195. data/ext/clipsruby/insmult.h +62 -0
  196. data/ext/clipsruby/inspsr.c +602 -0
  197. data/ext/clipsruby/inspsr.h +60 -0
  198. data/ext/clipsruby/insquery.c +1278 -0
  199. data/ext/clipsruby/insquery.h +115 -0
  200. data/ext/clipsruby/insqypsr.c +729 -0
  201. data/ext/clipsruby/insqypsr.h +63 -0
  202. data/ext/clipsruby/iofun.c +2045 -0
  203. data/ext/clipsruby/iofun.h +116 -0
  204. data/ext/clipsruby/lgcldpnd.c +644 -0
  205. data/ext/clipsruby/lgcldpnd.h +75 -0
  206. data/ext/clipsruby/main.c +112 -0
  207. data/ext/clipsruby/match.h +142 -0
  208. data/ext/clipsruby/memalloc.c +481 -0
  209. data/ext/clipsruby/memalloc.h +197 -0
  210. data/ext/clipsruby/miscfun.c +1801 -0
  211. data/ext/clipsruby/miscfun.h +132 -0
  212. data/ext/clipsruby/modulbin.c +607 -0
  213. data/ext/clipsruby/modulbin.h +84 -0
  214. data/ext/clipsruby/modulbsc.c +347 -0
  215. data/ext/clipsruby/modulbsc.h +67 -0
  216. data/ext/clipsruby/modulcmp.c +499 -0
  217. data/ext/clipsruby/modulcmp.h +54 -0
  218. data/ext/clipsruby/moduldef.c +817 -0
  219. data/ext/clipsruby/moduldef.h +271 -0
  220. data/ext/clipsruby/modulpsr.c +1150 -0
  221. data/ext/clipsruby/modulpsr.h +69 -0
  222. data/ext/clipsruby/modulutl.c +1036 -0
  223. data/ext/clipsruby/modulutl.h +84 -0
  224. data/ext/clipsruby/msgcom.c +1221 -0
  225. data/ext/clipsruby/msgcom.h +125 -0
  226. data/ext/clipsruby/msgfun.c +1076 -0
  227. data/ext/clipsruby/msgfun.h +118 -0
  228. data/ext/clipsruby/msgpass.c +1441 -0
  229. data/ext/clipsruby/msgpass.h +103 -0
  230. data/ext/clipsruby/msgpsr.c +698 -0
  231. data/ext/clipsruby/msgpsr.h +73 -0
  232. data/ext/clipsruby/multifld.c +1404 -0
  233. data/ext/clipsruby/multifld.h +130 -0
  234. data/ext/clipsruby/multifun.c +2182 -0
  235. data/ext/clipsruby/multifun.h +102 -0
  236. data/ext/clipsruby/network.h +142 -0
  237. data/ext/clipsruby/objbin.c +1522 -0
  238. data/ext/clipsruby/objbin.h +79 -0
  239. data/ext/clipsruby/objcmp.c +1507 -0
  240. data/ext/clipsruby/objcmp.h +71 -0
  241. data/ext/clipsruby/object.h +260 -0
  242. data/ext/clipsruby/objrtbin.c +701 -0
  243. data/ext/clipsruby/objrtbin.h +79 -0
  244. data/ext/clipsruby/objrtbld.c +2393 -0
  245. data/ext/clipsruby/objrtbld.h +66 -0
  246. data/ext/clipsruby/objrtcmp.c +734 -0
  247. data/ext/clipsruby/objrtcmp.h +66 -0
  248. data/ext/clipsruby/objrtfnx.c +1330 -0
  249. data/ext/clipsruby/objrtfnx.h +222 -0
  250. data/ext/clipsruby/objrtgen.c +736 -0
  251. data/ext/clipsruby/objrtgen.h +63 -0
  252. data/ext/clipsruby/objrtmch.c +1524 -0
  253. data/ext/clipsruby/objrtmch.h +160 -0
  254. data/ext/clipsruby/parsefun.c +415 -0
  255. data/ext/clipsruby/parsefun.h +67 -0
  256. data/ext/clipsruby/pattern.c +1265 -0
  257. data/ext/clipsruby/pattern.h +163 -0
  258. data/ext/clipsruby/pprint.c +328 -0
  259. data/ext/clipsruby/pprint.h +79 -0
  260. data/ext/clipsruby/prccode.c +1478 -0
  261. data/ext/clipsruby/prccode.h +145 -0
  262. data/ext/clipsruby/prcdrfun.c +640 -0
  263. data/ext/clipsruby/prcdrfun.h +95 -0
  264. data/ext/clipsruby/prcdrpsr.c +1068 -0
  265. data/ext/clipsruby/prcdrpsr.h +79 -0
  266. data/ext/clipsruby/prdctfun.c +869 -0
  267. data/ext/clipsruby/prdctfun.h +77 -0
  268. data/ext/clipsruby/prntutil.c +878 -0
  269. data/ext/clipsruby/prntutil.h +125 -0
  270. data/ext/clipsruby/proflfun.c +827 -0
  271. data/ext/clipsruby/proflfun.h +118 -0
  272. data/ext/clipsruby/reorder.c +2082 -0
  273. data/ext/clipsruby/reorder.h +172 -0
  274. data/ext/clipsruby/reteutil.c +1732 -0
  275. data/ext/clipsruby/reteutil.h +111 -0
  276. data/ext/clipsruby/retract.c +710 -0
  277. data/ext/clipsruby/retract.h +74 -0
  278. data/ext/clipsruby/router.c +737 -0
  279. data/ext/clipsruby/router.h +147 -0
  280. data/ext/clipsruby/rulebin.c +1136 -0
  281. data/ext/clipsruby/rulebin.h +153 -0
  282. data/ext/clipsruby/rulebld.c +1328 -0
  283. data/ext/clipsruby/rulebld.h +62 -0
  284. data/ext/clipsruby/rulebsc.c +517 -0
  285. data/ext/clipsruby/rulebsc.h +91 -0
  286. data/ext/clipsruby/rulecmp.c +733 -0
  287. data/ext/clipsruby/rulecmp.h +63 -0
  288. data/ext/clipsruby/rulecom.c +1583 -0
  289. data/ext/clipsruby/rulecom.h +116 -0
  290. data/ext/clipsruby/rulecstr.c +892 -0
  291. data/ext/clipsruby/rulecstr.h +53 -0
  292. data/ext/clipsruby/ruledef.c +559 -0
  293. data/ext/clipsruby/ruledef.h +179 -0
  294. data/ext/clipsruby/ruledlt.c +599 -0
  295. data/ext/clipsruby/ruledlt.h +58 -0
  296. data/ext/clipsruby/rulelhs.c +1216 -0
  297. data/ext/clipsruby/rulelhs.h +52 -0
  298. data/ext/clipsruby/rulepsr.c +1073 -0
  299. data/ext/clipsruby/rulepsr.h +61 -0
  300. data/ext/clipsruby/scanner.c +856 -0
  301. data/ext/clipsruby/scanner.h +112 -0
  302. data/ext/clipsruby/setup.h +488 -0
  303. data/ext/clipsruby/sortfun.c +433 -0
  304. data/ext/clipsruby/sortfun.h +55 -0
  305. data/ext/clipsruby/strngfun.c +1173 -0
  306. data/ext/clipsruby/strngfun.h +96 -0
  307. data/ext/clipsruby/strngrtr.c +523 -0
  308. data/ext/clipsruby/strngrtr.h +97 -0
  309. data/ext/clipsruby/symblbin.c +648 -0
  310. data/ext/clipsruby/symblbin.h +64 -0
  311. data/ext/clipsruby/symblcmp.c +893 -0
  312. data/ext/clipsruby/symblcmp.h +61 -0
  313. data/ext/clipsruby/symbol.c +1961 -0
  314. data/ext/clipsruby/symbol.h +243 -0
  315. data/ext/clipsruby/sysdep.c +894 -0
  316. data/ext/clipsruby/sysdep.h +164 -0
  317. data/ext/clipsruby/textpro.c +1388 -0
  318. data/ext/clipsruby/textpro.h +77 -0
  319. data/ext/clipsruby/tmpltbin.c +609 -0
  320. data/ext/clipsruby/tmpltbin.h +108 -0
  321. data/ext/clipsruby/tmpltbsc.c +327 -0
  322. data/ext/clipsruby/tmpltbsc.h +87 -0
  323. data/ext/clipsruby/tmpltcmp.c +450 -0
  324. data/ext/clipsruby/tmpltcmp.h +57 -0
  325. data/ext/clipsruby/tmpltdef.c +584 -0
  326. data/ext/clipsruby/tmpltdef.h +155 -0
  327. data/ext/clipsruby/tmpltfun.c +2477 -0
  328. data/ext/clipsruby/tmpltfun.h +122 -0
  329. data/ext/clipsruby/tmpltlhs.c +379 -0
  330. data/ext/clipsruby/tmpltlhs.h +50 -0
  331. data/ext/clipsruby/tmpltpsr.c +819 -0
  332. data/ext/clipsruby/tmpltpsr.h +59 -0
  333. data/ext/clipsruby/tmpltrhs.c +595 -0
  334. data/ext/clipsruby/tmpltrhs.h +55 -0
  335. data/ext/clipsruby/tmpltutl.c +637 -0
  336. data/ext/clipsruby/tmpltutl.h +82 -0
  337. data/ext/clipsruby/userdata.c +156 -0
  338. data/ext/clipsruby/userdata.h +72 -0
  339. data/ext/clipsruby/userfunctions.c +70 -0
  340. data/ext/clipsruby/usrsetup.h +7 -0
  341. data/ext/clipsruby/utility.c +1594 -0
  342. data/ext/clipsruby/utility.h +250 -0
  343. data/ext/clipsruby/watch.c +865 -0
  344. data/ext/clipsruby/watch.h +124 -0
  345. data/lib/clipsruby.rb +1 -0
  346. metadata +388 -0
@@ -0,0 +1,1088 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 08/25/16 */
5
+ /* */
6
+ /* CONFLICT RESOLUTION STRATEGY MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Used to determine where a new activation is */
11
+ /* placed on the agenda based on the current conflict */
12
+ /* resolution strategy (depth, breadth, mea, lex, */
13
+ /* simplicity, or complexity). Also provides the */
14
+ /* set-strategy and get-strategy commands. */
15
+ /* */
16
+ /* Principal Programmer(s): */
17
+ /* Gary D. Riley */
18
+ /* */
19
+ /* Contributing Programmer(s): */
20
+ /* */
21
+ /* Revision History: */
22
+ /* */
23
+ /* 6.23: Corrected compilation errors for files */
24
+ /* generated by constructs-to-c. DR0861 */
25
+ /* */
26
+ /* 6.24: Removed CONFLICT_RESOLUTION_STRATEGIES */
27
+ /* compilation flag. */
28
+ /* */
29
+ /* 6.30: Added salience groups to improve performance */
30
+ /* with large numbers of activations of different */
31
+ /* saliences. */
32
+ /* */
33
+ /* Removed pseudo-facts used for not CEs. */
34
+ /* */
35
+ /* Changed integer type/precision. */
36
+ /* */
37
+ /* Added const qualifiers to remove C++ */
38
+ /* deprecation warnings. */
39
+ /* */
40
+ /* Converted API macros to function calls. */
41
+ /* */
42
+ /* 6.40: Pragma once and other inclusion changes. */
43
+ /* */
44
+ /* Added support for booleans with <stdbool.h>. */
45
+ /* */
46
+ /* Removed use of void pointers for specific */
47
+ /* data structures. */
48
+ /* */
49
+ /* ALLOW_ENVIRONMENT_GLOBALS no longer supported. */
50
+ /* */
51
+ /* UDF redesign. */
52
+ /* */
53
+ /*************************************************************/
54
+
55
+ #include <stdio.h>
56
+ #include <string.h>
57
+
58
+ #include "setup.h"
59
+
60
+ #if DEFRULE_CONSTRUCT
61
+
62
+ #include "agenda.h"
63
+ #include "argacces.h"
64
+ #include "constant.h"
65
+ #include "envrnmnt.h"
66
+ #include "memalloc.h"
67
+ #include "pattern.h"
68
+ #include "reteutil.h"
69
+
70
+ #include "crstrtgy.h"
71
+
72
+ #define GetMatchingItem(x,i) ((x->basis->binds[i].gm.theMatch != NULL) ? \
73
+ (x->basis->binds[i].gm.theMatch->matchingItem) : NULL)
74
+
75
+ /***************************************/
76
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
77
+ /***************************************/
78
+
79
+ static Activation *PlaceDepthActivation(Activation *,struct salienceGroup *);
80
+ static Activation *PlaceBreadthActivation(Activation *,struct salienceGroup *);
81
+ static Activation *PlaceLEXActivation(Environment *,Activation *,struct salienceGroup *);
82
+ static Activation *PlaceMEAActivation(Environment *,Activation *,struct salienceGroup *);
83
+ static Activation *PlaceComplexityActivation(Activation *,struct salienceGroup *);
84
+ static Activation *PlaceSimplicityActivation(Activation *,struct salienceGroup *);
85
+ static Activation *PlaceRandomActivation(Activation *,struct salienceGroup *);
86
+ static int ComparePartialMatches(Environment *,Activation *,Activation *);
87
+ static const char *GetStrategyName(StrategyType);
88
+ static unsigned long long *SortPartialMatch(Environment *,struct partialMatch *);
89
+
90
+ /******************************************************************/
91
+ /* PlaceActivation: Coordinates placement of an activation on the */
92
+ /* Agenda based on the current conflict resolution strategy. */
93
+ /******************************************************************/
94
+ void PlaceActivation(
95
+ Environment *theEnv,
96
+ Activation **whichAgenda,
97
+ Activation *newActivation,
98
+ struct salienceGroup *theGroup)
99
+ {
100
+ Activation *placeAfter = NULL;
101
+
102
+ /*================================================*/
103
+ /* Set the flag which indicates that a change has */
104
+ /* been made to the agenda. */
105
+ /*================================================*/
106
+
107
+ SetAgendaChanged(theEnv,true);
108
+
109
+ /*=============================================*/
110
+ /* Determine the location where the activation */
111
+ /* should be placed in the agenda based on the */
112
+ /* current conflict resolution strategy. */
113
+ /*==============================================*/
114
+
115
+ if (*whichAgenda != NULL)
116
+ {
117
+ switch (AgendaData(theEnv)->Strategy)
118
+ {
119
+ case DEPTH_STRATEGY:
120
+ placeAfter = PlaceDepthActivation(newActivation,theGroup);
121
+ break;
122
+
123
+ case BREADTH_STRATEGY:
124
+ placeAfter = PlaceBreadthActivation(newActivation,theGroup);
125
+ break;
126
+
127
+ case LEX_STRATEGY:
128
+ placeAfter = PlaceLEXActivation(theEnv,newActivation,theGroup);
129
+ break;
130
+
131
+ case MEA_STRATEGY:
132
+ placeAfter = PlaceMEAActivation(theEnv,newActivation,theGroup);
133
+ break;
134
+
135
+ case COMPLEXITY_STRATEGY:
136
+ placeAfter = PlaceComplexityActivation(newActivation,theGroup);
137
+ break;
138
+
139
+ case SIMPLICITY_STRATEGY:
140
+ placeAfter = PlaceSimplicityActivation(newActivation,theGroup);
141
+ break;
142
+
143
+ case RANDOM_STRATEGY:
144
+ placeAfter = PlaceRandomActivation(newActivation,theGroup);
145
+ break;
146
+ }
147
+ }
148
+ else
149
+ {
150
+ theGroup->first = newActivation;
151
+ theGroup->last = newActivation;
152
+ }
153
+
154
+ /*==============================================================*/
155
+ /* Place the activation at the appropriate place in the agenda. */
156
+ /*==============================================================*/
157
+
158
+ if (placeAfter == NULL) /* then place it at the beginning of then agenda. */
159
+ {
160
+ newActivation->next = *whichAgenda;
161
+ *whichAgenda = newActivation;
162
+ if (newActivation->next != NULL) newActivation->next->prev = newActivation;
163
+ }
164
+ else /* insert it in the agenda. */
165
+ {
166
+ newActivation->next = placeAfter->next;
167
+ newActivation->prev = placeAfter;
168
+ placeAfter->next = newActivation;
169
+ if (newActivation->next != NULL)
170
+ { newActivation->next->prev = newActivation; }
171
+ }
172
+ }
173
+
174
+ /*******************************************************************/
175
+ /* PlaceDepthActivation: Determines the location in the agenda */
176
+ /* where a new activation should be placed for the depth */
177
+ /* strategy. Returns a pointer to the activation after which */
178
+ /* the new activation should be placed (or NULL if the */
179
+ /* activation should be placed at the beginning of the agenda). */
180
+ /*******************************************************************/
181
+ static Activation *PlaceDepthActivation(
182
+ Activation *newActivation,
183
+ struct salienceGroup *theGroup)
184
+ {
185
+ Activation *lastAct, *actPtr;
186
+ unsigned long long timetag;
187
+
188
+ /*============================================*/
189
+ /* Set up initial information for the search. */
190
+ /*============================================*/
191
+
192
+ timetag = newActivation->timetag;
193
+ if (theGroup->prev == NULL)
194
+ { lastAct = NULL; }
195
+ else
196
+ { lastAct = theGroup->prev->last; }
197
+
198
+ /*=========================================================*/
199
+ /* Find the insertion point in the agenda. The activation */
200
+ /* is placed before activations of lower salience and */
201
+ /* after activations of higher salience. Among activations */
202
+ /* of equal salience, the activation is placed before */
203
+ /* activations with an equal or lower timetag (yielding */
204
+ /* depth first traversal). */
205
+ /*=========================================================*/
206
+
207
+ actPtr = theGroup->first;
208
+ while (actPtr != NULL)
209
+ {
210
+ if (timetag < actPtr->timetag)
211
+ {
212
+ lastAct = actPtr;
213
+ if (actPtr == theGroup->last)
214
+ { break; }
215
+ else
216
+ { actPtr = actPtr->next; }
217
+ }
218
+ else
219
+ { break; }
220
+ }
221
+
222
+ /*========================================*/
223
+ /* Update the salience group information. */
224
+ /*========================================*/
225
+
226
+ if ((lastAct == NULL) ||
227
+ ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))
228
+ { theGroup->first = newActivation; }
229
+
230
+ if ((theGroup->last == NULL) || (theGroup->last == lastAct))
231
+ { theGroup->last = newActivation; }
232
+
233
+ /*===========================================*/
234
+ /* Return the insertion point in the agenda. */
235
+ /*===========================================*/
236
+
237
+ return(lastAct);
238
+ }
239
+
240
+ /*******************************************************************/
241
+ /* PlaceBreadthActivation: Determines the location in the agenda */
242
+ /* where a new activation should be placed for the breadth */
243
+ /* strategy. Returns a pointer to the activation after which */
244
+ /* the new activation should be placed (or NULL if the */
245
+ /* activation should be placed at the beginning of the agenda). */
246
+ /*******************************************************************/
247
+ static Activation *PlaceBreadthActivation(
248
+ Activation *newActivation,
249
+ struct salienceGroup *theGroup)
250
+ {
251
+ unsigned long long timetag;
252
+ Activation *lastAct, *actPtr;
253
+
254
+ /*============================================*/
255
+ /* Set up initial information for the search. */
256
+ /*============================================*/
257
+
258
+ timetag = newActivation->timetag;
259
+ if (theGroup->last == NULL)
260
+ {
261
+ if (theGroup->prev == NULL)
262
+ { lastAct = NULL; }
263
+ else
264
+ { lastAct = theGroup->prev->last; }
265
+ }
266
+ else
267
+ { lastAct = theGroup->last; }
268
+
269
+ /*=========================================================*/
270
+ /* Find the insertion point in the agenda. The activation */
271
+ /* is placed before activations of lower salience and */
272
+ /* after activations of higher salience. Among activations */
273
+ /* of equal salience, the activation is placed after */
274
+ /* activations with a lessor timetag (yielding breadth */
275
+ /* first traversal). */
276
+ /*=========================================================*/
277
+
278
+ actPtr = theGroup->last;
279
+ while (actPtr != NULL)
280
+ {
281
+ if (timetag < actPtr->timetag)
282
+ {
283
+ if (actPtr == theGroup->first)
284
+ {
285
+ if (theGroup->prev == NULL)
286
+ { lastAct = NULL; }
287
+ else
288
+ { lastAct = theGroup->prev->last; }
289
+ break;
290
+ }
291
+ else
292
+ { actPtr = actPtr->prev; }
293
+ }
294
+ else
295
+ {
296
+ lastAct = actPtr;
297
+ break;
298
+ }
299
+ }
300
+
301
+ /*========================================*/
302
+ /* Update the salience group information. */
303
+ /*========================================*/
304
+
305
+ if ((lastAct == NULL) ||
306
+ ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))
307
+ { theGroup->first = newActivation; }
308
+
309
+ if ((theGroup->last == NULL) || (theGroup->last == lastAct))
310
+ { theGroup->last = newActivation; }
311
+
312
+ /*===========================================*/
313
+ /* Return the insertion point in the agenda. */
314
+ /*===========================================*/
315
+
316
+ return lastAct;
317
+ }
318
+
319
+ /*******************************************************************/
320
+ /* PlaceLEXActivation: Determines the location in the agenda */
321
+ /* where a new activation should be placed for the lex */
322
+ /* strategy. Returns a pointer to the activation after which */
323
+ /* the new activation should be placed (or NULL if the */
324
+ /* activation should be placed at the beginning of the agenda). */
325
+ /*******************************************************************/
326
+ static Activation *PlaceLEXActivation(
327
+ Environment *theEnv,
328
+ Activation *newActivation,
329
+ struct salienceGroup *theGroup)
330
+ {
331
+ unsigned long long timetag;
332
+ Activation *lastAct, *actPtr;
333
+ int flag;
334
+
335
+ /*============================================*/
336
+ /* Set up initial information for the search. */
337
+ /*============================================*/
338
+
339
+ timetag = newActivation->timetag;
340
+ if (theGroup->prev == NULL)
341
+ { lastAct = NULL; }
342
+ else
343
+ { lastAct = theGroup->prev->last; }
344
+
345
+ /*================================================*/
346
+ /* Look first at the very end of the group to see */
347
+ /* if the activation should be placed there. */
348
+ /*================================================*/
349
+
350
+ actPtr = theGroup->last;
351
+ if (actPtr != NULL)
352
+ {
353
+ flag = ComparePartialMatches(theEnv,actPtr,newActivation);
354
+
355
+ if ((flag == LESS_THAN) ||
356
+ ((flag == EQUAL) && (timetag > actPtr->timetag)))
357
+ {
358
+ theGroup->last = newActivation;
359
+
360
+ return actPtr;
361
+ }
362
+ }
363
+
364
+ /*=========================================================*/
365
+ /* Find the insertion point in the agenda. The activation */
366
+ /* is placed before activations of lower salience and */
367
+ /* after activations of higher salience. Among activations */
368
+ /* of equal salience, the OPS5 lex strategy is used for */
369
+ /* determining placement. */
370
+ /*=========================================================*/
371
+
372
+ actPtr = theGroup->first;
373
+ while (actPtr != NULL)
374
+ {
375
+ flag = ComparePartialMatches(theEnv,actPtr,newActivation);
376
+
377
+ if (flag == LESS_THAN)
378
+ {
379
+ lastAct = actPtr;
380
+ if (actPtr == theGroup->last)
381
+ { break; }
382
+ else
383
+ { actPtr = actPtr->next; }
384
+ }
385
+ else if (flag == GREATER_THAN)
386
+ { break; }
387
+ else /* flag == EQUAL */
388
+ {
389
+ if (timetag > actPtr->timetag)
390
+ {
391
+ lastAct = actPtr;
392
+ if (actPtr == theGroup->last)
393
+ { break; }
394
+ else
395
+ { actPtr = actPtr->next; }
396
+ }
397
+ else
398
+ { break; }
399
+ }
400
+ }
401
+
402
+ /*========================================*/
403
+ /* Update the salience group information. */
404
+ /*========================================*/
405
+
406
+ if ((lastAct == NULL) ||
407
+ ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))
408
+ { theGroup->first = newActivation; }
409
+
410
+ if ((theGroup->last == NULL) || (theGroup->last == lastAct))
411
+ { theGroup->last = newActivation; }
412
+
413
+ /*===========================================*/
414
+ /* Return the insertion point in the agenda. */
415
+ /*===========================================*/
416
+
417
+ return lastAct;
418
+ }
419
+
420
+ /*******************************************************************/
421
+ /* PlaceMEAActivation: Determines the location in the agenda */
422
+ /* where a new activation should be placed for the mea */
423
+ /* strategy. Returns a pointer to the activation after which */
424
+ /* the new activation should be placed (or NULL if the */
425
+ /* activation should be placed at the beginning of the agenda). */
426
+ /*******************************************************************/
427
+ static Activation *PlaceMEAActivation(
428
+ Environment *theEnv,
429
+ Activation *newActivation,
430
+ struct salienceGroup *theGroup)
431
+ {
432
+ unsigned long long timetag;
433
+ Activation *lastAct, *actPtr;
434
+ int flag;
435
+ unsigned long long cWhoset = 0, oWhoset = 0;
436
+ bool cSet, oSet;
437
+
438
+ /*============================================*/
439
+ /* Set up initial information for the search. */
440
+ /*============================================*/
441
+
442
+ timetag = newActivation->timetag;
443
+ if (theGroup->prev == NULL)
444
+ { lastAct = NULL; }
445
+ else
446
+ { lastAct = theGroup->prev->last; }
447
+
448
+ /*================================================*/
449
+ /* Look first at the very end of the group to see */
450
+ /* if the activation should be placed there. */
451
+ /*================================================*/
452
+
453
+ actPtr = theGroup->last;
454
+ if (actPtr != NULL)
455
+ {
456
+ if (GetMatchingItem(newActivation,0) != NULL)
457
+ {
458
+ cWhoset = GetMatchingItem(newActivation,0)->timeTag;
459
+ cSet = true;
460
+ }
461
+ else
462
+ { cSet = false; }
463
+
464
+ if (GetMatchingItem(actPtr,0) != NULL)
465
+ {
466
+ oWhoset = GetMatchingItem(actPtr,0)->timeTag;
467
+ oSet = true;
468
+ }
469
+ else
470
+ { oSet = false; }
471
+
472
+ if ((cSet == false) && (oSet == false))
473
+ { flag = ComparePartialMatches(theEnv,actPtr,newActivation); }
474
+ else if ((cSet == true) && (oSet == false))
475
+ { flag = GREATER_THAN; }
476
+ else if ((cSet == false) && (oSet == true))
477
+ { flag = LESS_THAN; }
478
+ else if (oWhoset < cWhoset)
479
+ { flag = GREATER_THAN; }
480
+ else if (oWhoset > cWhoset)
481
+ { flag = LESS_THAN; }
482
+ else
483
+ { flag = ComparePartialMatches(theEnv,actPtr,newActivation); }
484
+
485
+ if ((flag == LESS_THAN) ||
486
+ ((flag == EQUAL) && (timetag > actPtr->timetag)))
487
+ {
488
+ theGroup->last = newActivation;
489
+
490
+ return actPtr;
491
+ }
492
+ }
493
+
494
+ /*=========================================================*/
495
+ /* Find the insertion point in the agenda. The activation */
496
+ /* is placed before activations of lower salience and */
497
+ /* after activations of higher salience. Among activations */
498
+ /* of equal salience, the OPS5 mea strategy is used for */
499
+ /* determining placement. */
500
+ /*=========================================================*/
501
+
502
+ actPtr = theGroup->first;
503
+ while (actPtr != NULL)
504
+ {
505
+ cWhoset = 0;
506
+ oWhoset = 0;
507
+ if (GetMatchingItem(newActivation,0) != NULL)
508
+ { cWhoset = GetMatchingItem(newActivation,0)->timeTag; }
509
+
510
+ if (GetMatchingItem(actPtr,0) != NULL)
511
+ { oWhoset = GetMatchingItem(actPtr,0)->timeTag; }
512
+
513
+ if (oWhoset < cWhoset)
514
+ {
515
+ if (cWhoset > 0) flag = GREATER_THAN;
516
+ else flag = LESS_THAN;
517
+ }
518
+ else if (oWhoset > cWhoset)
519
+ {
520
+ if (oWhoset > 0) flag = LESS_THAN;
521
+ else flag = GREATER_THAN;
522
+ }
523
+ else
524
+ { flag = ComparePartialMatches(theEnv,actPtr,newActivation); }
525
+
526
+ if (flag == LESS_THAN)
527
+ {
528
+ lastAct = actPtr;
529
+ if (actPtr == theGroup->last)
530
+ { break; }
531
+ else
532
+ { actPtr = actPtr->next; }
533
+ }
534
+ else if (flag == GREATER_THAN)
535
+ { break; }
536
+ else /* flag == EQUAL */
537
+ {
538
+ if (timetag > actPtr->timetag)
539
+ {
540
+ lastAct = actPtr;
541
+ if (actPtr == theGroup->last)
542
+ { break; }
543
+ else
544
+ { actPtr = actPtr->next; }
545
+ }
546
+ else
547
+ { break; }
548
+ }
549
+ }
550
+
551
+ /*========================================*/
552
+ /* Update the salience group information. */
553
+ /*========================================*/
554
+
555
+ if ((lastAct == NULL) ||
556
+ ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))
557
+ { theGroup->first = newActivation; }
558
+
559
+ if ((theGroup->last == NULL) || (theGroup->last == lastAct))
560
+ { theGroup->last = newActivation; }
561
+
562
+ /*===========================================*/
563
+ /* Return the insertion point in the agenda. */
564
+ /*===========================================*/
565
+
566
+ return lastAct;
567
+ }
568
+
569
+ /*********************************************************************/
570
+ /* PlaceComplexityActivation: Determines the location in the agenda */
571
+ /* where a new activation should be placed for the complexity */
572
+ /* strategy. Returns a pointer to the activation after which the */
573
+ /* new activation should be placed (or NULL if the activation */
574
+ /* should be placed at the beginning of the agenda). */
575
+ /*********************************************************************/
576
+ static Activation *PlaceComplexityActivation(
577
+ Activation *newActivation,
578
+ struct salienceGroup *theGroup)
579
+ {
580
+ unsigned int complexity;
581
+ unsigned long long timetag;
582
+ Activation *lastAct, *actPtr;
583
+
584
+ /*========================================*/
585
+ /* Set up initial information for search. */
586
+ /*========================================*/
587
+
588
+ timetag = newActivation->timetag;
589
+ complexity = newActivation->theRule->complexity;
590
+ if (theGroup->prev == NULL)
591
+ { lastAct = NULL; }
592
+ else
593
+ { lastAct = theGroup->prev->last; }
594
+
595
+ /*=========================================================*/
596
+ /* Find the insertion point in the agenda. The activation */
597
+ /* is placed before activations of lower salience and */
598
+ /* after activations of higher salience. Among activations */
599
+ /* of equal salience, the activation is placed before */
600
+ /* activations of equal or lessor complexity. */
601
+ /*=========================================================*/
602
+
603
+ actPtr = theGroup->first;
604
+ while (actPtr != NULL)
605
+ {
606
+ if (complexity < actPtr->theRule->complexity)
607
+ {
608
+ lastAct = actPtr;
609
+ if (actPtr == theGroup->last)
610
+ { break; }
611
+ else
612
+ { actPtr = actPtr->next; }
613
+ }
614
+ else if (complexity > actPtr->theRule->complexity)
615
+ { break; }
616
+ else if (timetag > actPtr->timetag)
617
+ {
618
+ lastAct = actPtr;
619
+ if (actPtr == theGroup->last)
620
+ { break; }
621
+ else
622
+ { actPtr = actPtr->next; }
623
+ }
624
+ else
625
+ { break; }
626
+ }
627
+
628
+ /*========================================*/
629
+ /* Update the salience group information. */
630
+ /*========================================*/
631
+
632
+ if ((lastAct == NULL) ||
633
+ ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))
634
+ { theGroup->first = newActivation; }
635
+
636
+ if ((theGroup->last == NULL) || (theGroup->last == lastAct))
637
+ { theGroup->last = newActivation; }
638
+
639
+ /*===========================================*/
640
+ /* Return the insertion point in the agenda. */
641
+ /*===========================================*/
642
+
643
+ return lastAct;
644
+ }
645
+
646
+ /*********************************************************************/
647
+ /* PlaceSimplicityActivation: Determines the location in the agenda */
648
+ /* where a new activation should be placed for the simplicity */
649
+ /* strategy. Returns a pointer to the activation after which the */
650
+ /* new activation should be placed (or NULL if the activation */
651
+ /* should be placed at the beginning of the agenda). */
652
+ /*********************************************************************/
653
+ static Activation *PlaceSimplicityActivation(
654
+ Activation *newActivation,
655
+ struct salienceGroup *theGroup)
656
+ {
657
+ unsigned int complexity;
658
+ unsigned long long timetag;
659
+ Activation *lastAct, *actPtr;
660
+
661
+ /*============================================*/
662
+ /* Set up initial information for the search. */
663
+ /*============================================*/
664
+
665
+ timetag = newActivation->timetag;
666
+ complexity = newActivation->theRule->complexity;
667
+ if (theGroup->prev == NULL)
668
+ { lastAct = NULL; }
669
+ else
670
+ { lastAct = theGroup->prev->last; }
671
+
672
+ /*=========================================================*/
673
+ /* Find the insertion point in the agenda. The activation */
674
+ /* is placed before activations of lower salience and */
675
+ /* after activations of higher salience. Among activations */
676
+ /* of equal salience, the activation is placed after */
677
+ /* activations of equal or greater complexity. */
678
+ /*=========================================================*/
679
+
680
+ actPtr = theGroup->first;
681
+ while (actPtr != NULL)
682
+ {
683
+ if (complexity > actPtr->theRule->complexity)
684
+ {
685
+ lastAct = actPtr;
686
+ if (actPtr == theGroup->last)
687
+ { break; }
688
+ else
689
+ { actPtr = actPtr->next; }
690
+ }
691
+ else if (complexity < actPtr->theRule->complexity)
692
+ { break; }
693
+ else if (timetag > actPtr->timetag)
694
+ {
695
+ lastAct = actPtr;
696
+ if (actPtr == theGroup->last)
697
+ { break; }
698
+ else
699
+ { actPtr = actPtr->next; }
700
+ }
701
+ else
702
+ { break; }
703
+ }
704
+
705
+ /*========================================*/
706
+ /* Update the salience group information. */
707
+ /*========================================*/
708
+
709
+ if ((lastAct == NULL) ||
710
+ ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))
711
+ { theGroup->first = newActivation; }
712
+
713
+ if ((theGroup->last == NULL) || (theGroup->last == lastAct))
714
+ { theGroup->last = newActivation; }
715
+
716
+ /*===========================================*/
717
+ /* Return the insertion point in the agenda. */
718
+ /*===========================================*/
719
+
720
+ return(lastAct);
721
+ }
722
+
723
+ /*******************************************************************/
724
+ /* PlaceRandomActivation: Determines the location in the agenda */
725
+ /* where a new activation should be placed for the random */
726
+ /* strategy. Returns a pointer to the activation after which */
727
+ /* the new activation should be placed (or NULL if the */
728
+ /* activation should be placed at the beginning of the agenda). */
729
+ /*******************************************************************/
730
+ static Activation *PlaceRandomActivation(
731
+ Activation *newActivation,
732
+ struct salienceGroup *theGroup)
733
+ {
734
+ int randomID;
735
+ unsigned long long timetag;
736
+ Activation *lastAct, *actPtr;
737
+
738
+ /*============================================*/
739
+ /* Set up initial information for the search. */
740
+ /*============================================*/
741
+
742
+ timetag = newActivation->timetag;
743
+ randomID = newActivation->randomID;
744
+ if (theGroup->prev == NULL)
745
+ { lastAct = NULL; }
746
+ else
747
+ { lastAct = theGroup->prev->last; }
748
+
749
+ /*=========================================================*/
750
+ /* Find the insertion point in the agenda. The activation */
751
+ /* is placed before activations of lower salience and */
752
+ /* after activations of higher salience. Among activations */
753
+ /* of equal salience, the placement of the activation is */
754
+ /* determined through the generation of a random number. */
755
+ /*=========================================================*/
756
+
757
+ actPtr = theGroup->first;
758
+ while (actPtr != NULL)
759
+ {
760
+ if (randomID > actPtr->randomID)
761
+ {
762
+ lastAct = actPtr;
763
+ if (actPtr == theGroup->last)
764
+ { break; }
765
+ else
766
+ { actPtr = actPtr->next; }
767
+ }
768
+ else if (randomID < actPtr->randomID)
769
+ { break; }
770
+ else if (timetag > actPtr->timetag)
771
+ {
772
+ lastAct = actPtr;
773
+ if (actPtr == theGroup->last)
774
+ { break; }
775
+ else
776
+ { actPtr = actPtr->next; }
777
+ }
778
+ else
779
+ { break; }
780
+ }
781
+
782
+ /*========================================*/
783
+ /* Update the salience group information. */
784
+ /*========================================*/
785
+
786
+ if ((lastAct == NULL) ||
787
+ ((theGroup->prev != NULL) && (theGroup->prev->last == lastAct)))
788
+ { theGroup->first = newActivation; }
789
+
790
+ if ((theGroup->last == NULL) || (theGroup->last == lastAct))
791
+ { theGroup->last = newActivation; }
792
+
793
+ /*===========================================*/
794
+ /* Return the insertion point in the agenda. */
795
+ /*===========================================*/
796
+
797
+ return(lastAct);
798
+ }
799
+
800
+ /*********************************************************/
801
+ /* SortPartialMatch: Creates an array of sorted timetags */
802
+ /* in ascending order from a partial match. */
803
+ /*********************************************************/
804
+ static unsigned long long *SortPartialMatch(
805
+ Environment *theEnv,
806
+ struct partialMatch *binds)
807
+ {
808
+ unsigned long long *nbinds;
809
+ unsigned long long temp;
810
+ bool flag;
811
+ unsigned short j, k;
812
+
813
+ /*====================================================*/
814
+ /* Copy the array. Use 0 to represent the timetags of */
815
+ /* negated patterns. Patterns matching fact/instances */
816
+ /* should have timetags greater than 0. */
817
+ /*====================================================*/
818
+
819
+ nbinds = (unsigned long long *) get_mem(theEnv,sizeof(long long) * binds->bcount);
820
+
821
+ for (j = 0; j < binds->bcount; j++)
822
+ {
823
+ if ((binds->binds[j].gm.theMatch != NULL) &&
824
+ (binds->binds[j].gm.theMatch->matchingItem != NULL))
825
+ { nbinds[j] = binds->binds[j].gm.theMatch->matchingItem->timeTag; }
826
+ else
827
+ { nbinds[j] = 0; }
828
+ }
829
+
830
+ /*=================*/
831
+ /* Sort the array. */
832
+ /*=================*/
833
+
834
+ for (flag = true, k = binds->bcount - 1;
835
+ flag == true;
836
+ k--)
837
+ {
838
+ flag = false;
839
+ for (j = 0 ; j < k ; j++)
840
+ {
841
+ if (nbinds[j] < nbinds[j + 1])
842
+ {
843
+ temp = nbinds[j];
844
+ nbinds[j] = nbinds[j+1];
845
+ nbinds[j+1] = temp;
846
+ flag = true;
847
+ }
848
+ }
849
+ }
850
+
851
+ /*===================*/
852
+ /* Return the array. */
853
+ /*===================*/
854
+
855
+ return nbinds;
856
+ }
857
+
858
+ /**************************************************************************/
859
+ /* ComparePartialMatches: Compares two activations using the lex conflict */
860
+ /* resolution strategy to determine which activation should be placed */
861
+ /* first on the agenda. This lexicographic comparison function is used */
862
+ /* for both the lex and mea strategies. */
863
+ /**************************************************************************/
864
+ static int ComparePartialMatches(
865
+ Environment *theEnv,
866
+ Activation *actPtr,
867
+ Activation *newActivation)
868
+ {
869
+ unsigned cCount, oCount, mCount, i;
870
+ unsigned long long *basis1, *basis2;
871
+
872
+ /*=================================================*/
873
+ /* If the activation already on the agenda doesn't */
874
+ /* have a set of sorted timetags, then create one. */
875
+ /*=================================================*/
876
+
877
+ basis1 = SortPartialMatch(theEnv,newActivation->basis);
878
+ basis2 = SortPartialMatch(theEnv,actPtr->basis);
879
+
880
+ /*==============================================================*/
881
+ /* Determine the number of timetags in each of the activations. */
882
+ /* The number of timetags to be compared is the lessor of these */
883
+ /* two numbers. */
884
+ /*==============================================================*/
885
+
886
+ cCount = newActivation->basis->bcount;
887
+ oCount = actPtr->basis->bcount;
888
+
889
+ if (oCount > cCount) mCount = cCount;
890
+ else mCount = oCount;
891
+
892
+ /*===========================================================*/
893
+ /* Compare the sorted timetags one by one until there are no */
894
+ /* more timetags to compare or the timetags being compared */
895
+ /* are not equal. If the timetags aren't equal, then the */
896
+ /* activation containing the larger timetag is placed before */
897
+ /* the activation containing the smaller timetag. */
898
+ /*===========================================================*/
899
+
900
+ for (i = 0 ; i < mCount ; i++)
901
+ {
902
+ if (basis1[i] < basis2[i])
903
+ {
904
+ rtn_mem(theEnv,sizeof(long long) * cCount,basis1);
905
+ rtn_mem(theEnv,sizeof(long long) * oCount,basis2);
906
+ return(LESS_THAN);
907
+ }
908
+ else if (basis1[i] > basis2[i])
909
+ {
910
+ rtn_mem(theEnv,sizeof(long long) * cCount,basis1);
911
+ rtn_mem(theEnv,sizeof(long long) * oCount,basis2);
912
+ return(GREATER_THAN);
913
+ }
914
+ }
915
+
916
+ rtn_mem(theEnv,sizeof(long long) * cCount,basis1);
917
+ rtn_mem(theEnv,sizeof(long long) * oCount,basis2);
918
+
919
+ /*==========================================================*/
920
+ /* If the sorted timetags are identical up to the number of */
921
+ /* timetags contained in the smaller partial match, then */
922
+ /* the activation containing more timetags should be */
923
+ /* placed before the activation containing fewer timetags. */
924
+ /*==========================================================*/
925
+
926
+ if (cCount < oCount) return(LESS_THAN);
927
+ else if (cCount > oCount) return(GREATER_THAN);
928
+
929
+ /*=========================================================*/
930
+ /* If the sorted partial matches for both activations are */
931
+ /* identical (containing the same number and values of */
932
+ /* timetags), then the activation associated with the rule */
933
+ /* having the highest complexity is placed before the */
934
+ /* other partial match. */
935
+ /*=========================================================*/
936
+
937
+ if (newActivation->theRule->complexity < actPtr->theRule->complexity)
938
+ { return(LESS_THAN); }
939
+ else if (newActivation->theRule->complexity > actPtr->theRule->complexity)
940
+ { return(GREATER_THAN); }
941
+
942
+ /*================================================*/
943
+ /* The two partial matches are equal for purposes */
944
+ /* of placement on the agenda for the lex and mea */
945
+ /* conflict resolution strategies. */
946
+ /*================================================*/
947
+
948
+ return(EQUAL);
949
+ }
950
+
951
+ /***********************************/
952
+ /* SetStrategy: C access routine */
953
+ /* for the set-strategy command. */
954
+ /***********************************/
955
+ StrategyType SetStrategy(
956
+ Environment *theEnv,
957
+ StrategyType value)
958
+ {
959
+ StrategyType oldStrategy;
960
+
961
+ oldStrategy = AgendaData(theEnv)->Strategy;
962
+ AgendaData(theEnv)->Strategy = value;
963
+
964
+ if (oldStrategy != AgendaData(theEnv)->Strategy)
965
+ { ReorderAllAgendas(theEnv); }
966
+
967
+ return oldStrategy;
968
+ }
969
+
970
+ /***********************************/
971
+ /* GetStrategy: C access routine */
972
+ /* for the get-strategy command. */
973
+ /***********************************/
974
+ StrategyType GetStrategy(
975
+ Environment *theEnv)
976
+ {
977
+ return AgendaData(theEnv)->Strategy;
978
+ }
979
+
980
+ /********************************************/
981
+ /* GetStrategyCommand: H/L access routine */
982
+ /* for the get-strategy command. */
983
+ /********************************************/
984
+ void GetStrategyCommand(
985
+ Environment *theEnv,
986
+ UDFContext *context,
987
+ UDFValue *returnValue)
988
+ {
989
+ returnValue->lexemeValue = CreateSymbol(theEnv,GetStrategyName(GetStrategy(theEnv)));
990
+ }
991
+
992
+ /********************************************/
993
+ /* SetStrategyCommand: H/L access routine */
994
+ /* for the set-strategy command. */
995
+ /********************************************/
996
+ void SetStrategyCommand(
997
+ Environment *theEnv,
998
+ UDFContext *context,
999
+ UDFValue *returnValue)
1000
+ {
1001
+ UDFValue theArg;
1002
+ const char *argument;
1003
+ StrategyType oldStrategy;
1004
+
1005
+ /*=======================*/
1006
+ /* Set the return value. */
1007
+ /*=======================*/
1008
+
1009
+ oldStrategy = GetStrategy(theEnv);
1010
+ returnValue->lexemeValue = CreateSymbol(theEnv,GetStrategyName(oldStrategy));
1011
+
1012
+ /*=========================================*/
1013
+ /* Check for the correct type of argument. */
1014
+ /*=========================================*/
1015
+
1016
+ if (! UDFFirstArgument(context,SYMBOL_BIT,&theArg))
1017
+ { return; }
1018
+
1019
+ /*=============================================*/
1020
+ /* Set the strategy to the specified strategy. */
1021
+ /*=============================================*/
1022
+
1023
+ argument = theArg.lexemeValue->contents;
1024
+
1025
+ if (strcmp(argument,"depth") == 0)
1026
+ { SetStrategy(theEnv,DEPTH_STRATEGY); }
1027
+ else if (strcmp(argument,"breadth") == 0)
1028
+ { SetStrategy(theEnv,BREADTH_STRATEGY); }
1029
+ else if (strcmp(argument,"lex") == 0)
1030
+ { SetStrategy(theEnv,LEX_STRATEGY); }
1031
+ else if (strcmp(argument,"mea") == 0)
1032
+ { SetStrategy(theEnv,MEA_STRATEGY); }
1033
+ else if (strcmp(argument,"complexity") == 0)
1034
+ { SetStrategy(theEnv,COMPLEXITY_STRATEGY); }
1035
+ else if (strcmp(argument,"simplicity") == 0)
1036
+ { SetStrategy(theEnv,SIMPLICITY_STRATEGY); }
1037
+ else if (strcmp(argument,"random") == 0)
1038
+ { SetStrategy(theEnv,RANDOM_STRATEGY); }
1039
+ else
1040
+ {
1041
+ UDFInvalidArgumentMessage(context,
1042
+ "symbol with value depth, breadth, lex, mea, complexity, simplicity, or random");
1043
+ }
1044
+ }
1045
+
1046
+ /**********************************************************/
1047
+ /* GetStrategyName: Given the integer value corresponding */
1048
+ /* to a specified strategy, return a character string */
1049
+ /* of the strategy's name. */
1050
+ /**********************************************************/
1051
+ static const char *GetStrategyName(
1052
+ StrategyType strategy)
1053
+ {
1054
+ const char *sname;
1055
+
1056
+ switch (strategy)
1057
+ {
1058
+ case DEPTH_STRATEGY:
1059
+ sname = "depth";
1060
+ break;
1061
+ case BREADTH_STRATEGY:
1062
+ sname = "breadth";
1063
+ break;
1064
+ case LEX_STRATEGY:
1065
+ sname = "lex";
1066
+ break;
1067
+ case MEA_STRATEGY:
1068
+ sname = "mea";
1069
+ break;
1070
+ case COMPLEXITY_STRATEGY:
1071
+ sname = "complexity";
1072
+ break;
1073
+ case SIMPLICITY_STRATEGY:
1074
+ sname = "simplicity";
1075
+ break;
1076
+ case RANDOM_STRATEGY:
1077
+ sname = "random";
1078
+ break;
1079
+ default:
1080
+ sname = "unknown";
1081
+ break;
1082
+ }
1083
+
1084
+ return(sname);
1085
+ }
1086
+
1087
+ #endif /* DEFRULE_CONSTRUCT */
1088
+