Search code examples
clips

CLIPS - How to relate 2 different deftemplates types when creating a defrule


I am using CLIPS 6.3 to develop a simple production management algorithm. Currently I have a deftemplate for product orders and another one for product details.

(deftemplate orderSheets
  (slot orderID (type INTEGER))
  (slot orderDate (type INTEGER))
  (slot product (type STRING))
  (slot quantity (type INTEGER))
  (slot deliverDate (type INTEGER))
)

(deftemplate productInfoSheets
  (slot productID (type STRING))
  (slot productStock (type INTEGER))
  (slot prodTime (type INTEGER))
  (slot maximumProduction (type INTEGER))
)

My doubt is how can I create a rule that relates the product order quantity (available in orderSheets) vs the available stock (available in productInfoSheets.

Thank you for your support, Joan


Solution

  • Here's an example rule comparing order quantity to available stock:

    (defrule not-enough
       (orderSheets (quantity ?quantity))
       (productInfoSheets (productStock ?stock))
       (test (> ?quantity ?stock))
       =>)