2015-02-12 59 views
0

我爲一個學校項目編寫了我的第一個CLIPS代碼,但我不熟悉CLIPS(我使用C#和Python作爲主要語言)。第一個CLIPS代碼不起作用

這是我的代碼,我剛開錯誤:

(defrule determine-closing-date 
    (not (day-to-close ?)) 
    (billing-size ?) 
    (unpaid-invoices-number ?) 
    => 
    (if 
     (or 
      (< billing-size 1000000) 
      (< unpaid-invoices-number 1000000) 
     ) 
     then (assert (day-to-close MtTh)) 
     else (assert (day-to-close friday)) 
    ) 

(defrule determine-billing-size "" 
    (not (billing-size ?)) 
    (not (day-to-close ?)) 
    => 
    (printout t "¿Cuál es el tamaño de la facturacion?") 
    (assert (billing-size ?size (read)))) 

(defrule determine-unpaid-invoices-number "" 
    (not (unpaid-invoices-number ?)) 
    (not (day-to-close ?)) 
    => 
    (printout t "¿Cuál es la cantidad de facturas no pagadas") 
    (assert (unpaid-invoices-number ?size (read)))) 

(defrule determine-friday-load "" 
    (day-to-close friday) 
    (not (friday-load ?)) 
    => 
    (printout t "¿Cuál es la carga de cierres para el viernes?") 
    (assert (friday-load ?load (read)))) 

(defrule determine-saturday-closing "" 
    (day-to-close friday) 
    (not(< friday-load 1000000)) 
    => 
    (assert (day-to-close saturday))) 

(defrule day-to-close-conclulssion "" 
    (day-to-close ?) 
    => 
    (if (eq day-to-close MtTh) 
     then (printout t "Se puede cerrar de Lunes a Jueves") 
     else (
      if (eq day-to-close friday) 
       then (printout t "Se debe cerrar viernes.") 
       else (printout t "Se debe cerrar sabado.") 
      ) 
    )) 

的errores是:

[ARGACCES5]功能<預期參數#1爲整數類型的或浮動

[PRCCODE3]在defrule的RHS中引用的未定義的變量大小。

[CSTRCPSR1]警告:重新定義defrule:確定-星期六閉+ J + J + J

[CSTRCPSR1]警告:重新定義defrule:一天到近距離conclulssion + J + J

回答

2

有人建議修改:

(defrule determine-closing-date 
    (not (day-to-close ?)) 
    (billing-size ?billing-size) 
    (unpaid-invoices-number ?unpaid-invoices-number) 
    => 
    (if (or (< ?billing-size 1000000) 
      (< ?unpaid-invoices-number 1000000)) 
     then (assert (day-to-close MtTh)) 
     else (assert (day-to-close friday)))) 

(defrule determine-billing-size "" 
    (not (billing-size ?)) 
    (not (day-to-close ?)) 
    => 
    ; What is the size of the billing? 
    (printout t "¿Cuál es el tamaño de la facturacion? ") 
    (bind ?size (read)) 
    (assert (billing-size ?size))) 

(defrule determine-unpaid-invoices-number "" 
    (not (unpaid-invoices-number ?)) 
    (not (day-to-close ?)) 
    => 
    ; What is the amount of unpaid bills? 
    (printout t "¿Cuál es la cantidad de facturas no pagadas? ") 
    (bind ?size (read)) 
    (assert (unpaid-invoices-number ?size))) 

(defrule determine-friday-load "" 
    (day-to-close friday) 
    (not (friday-load ?)) 
    => 
    ; What is the burden of closures for Friday? 
    (printout t "¿Cuál es la carga de cierres para el viernes? ") 
    (bind ?load (read)) 
    (assert (friday-load ?load))) 

(defrule determine-saturday-closing "" 
    ?dtc <- (day-to-close friday) 
    (friday-load ?load&:(< ?load 1000000)) 
    => 
    (retract ?dtc) 
    (assert (day-to-close saturday))) 

(defrule day-to-close-conclusion "" 
    (declare (salience -10)) 
    (day-to-close ?day-to-close) 
    => 
    (switch ?day-to-close 
     (case MtTh 
      ; Can be closed from Monday to Thursday. 
      then (printout t "Se puede cerrar de Lunes a Jueves." crlf)) 
     (case friday 
      ; Must be closed Fridays. 
      then (printout t "Se debe cerrar viernes." crlf)) 
     (default 
      ; Must be closed Saturday. 
      then (printout t "Se debe cerrar sabado." crlf)))) 

和輸出它產生:

CLIPS> Loading Buffer... 
****** 
CLIPS> (reset) 
CLIPS> (run) 
¿Cuál es el tamaño de la facturacion? 10 
¿Cuál es la cantidad de facturas no pagadas? 10 
Se puede cerrar de Lunes a Jueves. 
CLIPS> (reset) 
CLIPS> (run) 
¿Cuál es el tamaño de la facturacion? 3000000 
¿Cuál es la cantidad de facturas no pagadas? 3000000 
¿Cuál es la carga de cierres para el viernes? 10 
Se debe cerrar sabado. 
CLIPS> (reset) 
CLIPS> (run) 
¿Cuál es el tamaño de la facturacion? 3000000 
¿Cuál es la cantidad de facturas no pagadas? 3000000 
¿Cuál es la carga de cierres para el viernes? 3000000 
Se debe cerrar viernes. 
CLIPS> 
+0

謝謝你們的幫助!你能告訴我我做錯了什麼嗎?我真的想學習這個CLIPS語法 – Yatiac 2015-02-12 16:07:02

+1

1)用於綁定變量的語法不正確。 – 2015-02-12 17:45:46

+1

2)在確定 - 星期六 - 結束規則中,需要檢查小於1000000的負載的存在的週五負載​​模式,而不是負載小於1000000的事實不存在。 3)當天「關係到結論」的規則需要比其他規則的顯着性要低,以便在所有其他規則應用之後才能執行。如果您刪除突出顯示並運行計費大小和支付3000000的賬單的程序,您會看到原因。 – 2015-02-12 17:51:50