Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. ;=======================================================
  2. ; quick sort
  3.  
  4.  
  5. (deftemplate qsplit
  6. (multislot in)
  7. (slot pivot)
  8. (multislot left)
  9. (multislot right)
  10. (multislot tmp))
  11.  
  12. (deftemplate qsol
  13. (multislot in)
  14. (multislot out))
  15.  
  16. (deftemplate qsort_sol
  17. (multislot in)
  18. (multislot out))
  19.  
  20. (deftemplate qtree
  21. (multislot fat)
  22. (slot pivot)
  23. (multislot left)
  24. (multislot right))
  25.  
  26. (defrule q1
  27. (qsort $?Z)
  28. =>
  29. (if (empty $?Z) then (assert (qsort_sol (in $?Z) (out $?Z)))
  30. else (assert (qsplit (in $?Z) (pivot (nth$ 1 $?Z)) (tmp (rest$ $?Z)) (left) (right)))))
  31.  
  32. (defrule q2
  33. ?I<- (qsplit (in $?Z) (tmp $?W) (pivot ?P) (left $?A) (right $?B))
  34. =>
  35. (retract ?I)
  36. (if (empty $?W) then (assert (qgoal $?A) (qgoal $?B) (qtree (fat $?Z)
  37. (pivot ?P)
  38. (left $?A )
  39. (right $?B)))
  40. else (if (< (nth$ 1 $?W) ?P) then (assert (qsplit (in $?Z)
  41. (tmp (rest$ $?W))
  42. (pivot ?P)
  43. (left $?A (nth$ 1 $?W))
  44. (right $?B)))
  45. else (assert (qsplit (in $?Z)
  46. (tmp (rest$ $?W))
  47. (pivot ?P)
  48. (left $?A)
  49. (right $?B (nth$ 1 $?W))))
  50. )))
  51.  
  52. (defrule q3
  53. ?I<-(qgoal $?Z)
  54. =>
  55. (retract ?I)
  56. (if (empty $?Z) then (assert (qsol (in $?Z) (out $?Z)))
  57. else (assert (qsplit (in $?Z) (pivot (nth$ 1 $?Z)) (tmp (rest$ $?Z)) (left) (right)))))
  58.  
  59. ;potialto som rozpajal pole
  60.  
  61. (defrule q4
  62. ?I<-(qtree (fat $?Z) (pivot ?P) (left $?A) (right $?B))
  63. (qsol (in $?A) (out $?VA))
  64. (qsol (in $?B) (out $?VB))
  65. =>
  66. (retract ?I)
  67. (assert (qsol (in $?Z) (out $?VA ?P $?VB))))
  68.  
  69. (defrule q5
  70. (qsort $?Z)
  71. (qsol (in $?Z) (out $?VZ))
  72. =>
  73. (assert (qsort_sol (in $?Z) (out $?VZ))))
  74.  
  75. (defrule q6 (declare (salience -1))
  76. ?I<-(qsol)
  77. =>
  78. (retract ?I))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement