تجميع الحقائق في نظام خبراء المقاطع لإيجاد الحد الأقصى

StackOverflow https://stackoverflow.com/questions/2382648

  •  24-09-2019
  •  | 
  •  

سؤال

أحاول توضيح فهمي للدلالات في نظام خبراء CLIPS ، لذلك أحاول كتابة بعض القواعد البسيطة لتجميع قائمة من الحقائق لإيجاد الحقيقة بأعلى قيمة فتحة. الاستعارة التي أستخدمها هي العامل البسيط الذي يحاول تحديد ما إذا كان ينبغي أن يأكل أو النوم. يتم توسيع الحقائق التي تصف حالات الوكيل إلى إجراءات محتملة ، ثم تحاول القاعدة العثور على الإجراء النهائي بأعلى فائدة.

هذا هو الكود الخاص بي:

(clear)

(deftemplate state 
    (slot name) 
    (slot level (type NUMBER)) 
) 
(deftemplate action 
    (slot name) 
    (slot utility (type NUMBER)) 
    (slot final (type INTEGER) (default 0)) 
) 
(defrule eat-when-hungry "" 
    (state (name hungry) (level ?level)) 
    => 
    (assert (action (name eat) (utility ?level))) 
) 
(defrule sleep-when-sleepy "" 
    (state (name sleepy) (level ?level)) 
    => 
    (assert (action (name sleep) (utility ?level))) 
) 
(defrule find-final-action "" 
    ?current_final <- (action (name ?current_final_action) (utility ? 
current_final_utility) (final 1)) 
    (action (name ?other_action) (utility ?other_utility) (final 0)) 
    (neq ?current_final_action ?other_action) 
    (< ?current_final_action ?other_action) 
    => 
    (modify ?current_final (name ?other_action) (utility ? 
other_utility)) 
) 
(assert (action (name none) (utility 0.0) (final 1))) 
(assert (state (name hungry) (level 0.5))) 
(assert (state (name sleepy) (level 0.1))) 
(run) 
(facts)

بعد تشغيل هذا ، أتوقع أن يكون الإجراء النهائي:

(action (name eat) (utility 0.5) (final 1)) 

ومع ذلك ، يقيمها Clips على:

(action (name none) (utility 0.0) (final 1)) 

تشير إلى أن قاعدة الإنتاج النهائي لا تنشط أبدًا. لماذا هذا؟ كيف يمكنك التكرار على مجموعة من الحقائق وتجد واحدة ذات قيمة فتحة Min/Max؟

هل كانت مفيدة؟

المحلول

كان لدى حكمك بضعة أخطاء فيه. ها هي النسخة المصححة:

(defrule find-final-action "" 
    ?current_final <- (action (name ?current_final_action) 
                              (utility ?current_final_utility) (final 1)) 
    (action (name ?other_action) (utility ?other_utility) (final 0)) 
    (test (neq ?current_final_action ?other_action))
    (test (< ?current_final_utility ?other_utility)) 
    => 
    (modify ?current_final (name ?other_action) (utility ?other_utility)))

طريقة بديلة لا تتطلب تخزين الحسابات الوسيطة وإطلاقات القواعد المتعددة هي:

(defrule find-final-action-2 "" 
    (declare (salience -10)) ; lower salience to allow all actions to be asserted first
    (action (name ?action) (utility ?utility)) 
    (not (action (utility ?other_utility&:(> ?other_utility ?utility))))
    => 
    (printout t "Final action is " ?action crlf))
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top