2017-02-18 10 views
1

車の前に障害物がないか確認しようとしています。車が場所「2」にあるとしましょう。私の目標は、場所「3」に障害物がないかどうかをチェックすることです。 特定の場所に障害物がないことを意味する障害物の事実が定義されていない可能性があります。 が存在することを確認しますを条件とします。しかし、私はCLIPS構文エラー[PRNTUTIL2]この部分の(+?location_car 1)のルールr6になります。私が追加を破棄すれば動作します。私はどのような選択肢を使うことができますか、あるいは私はいくつかの構文を欠いていますか?存在を条件付きで正しく使う方法は? CLIPS

(deftemplate car 
    (slot location) 
) 
(deftemplate obstacles 
    (slot location) ; location of road segment 
    (slot tlights) ; number of red traffic lights 
    (slot cars) ; number of cars which have priority drive through 
    (slot pedestrians) ; number of pedestrians crossing the road 
    (slot spec_service) ; number of spec service vehicles passing by 
) 

(deffacts faktu-inicializavimas 
(car (location 0)) 
(obstacles (location 9) (tlights 1) (cars 2) (pedestrians 5) (spec_service 2)) 
) 

(defrule r6 "Drive to location" 
    ?fact-id1 <- (car (location ?location_car)) 
    (or 
    (exists (obstacles (location (+ ?location_car 1)) (tlights 0) (cars 0) (pedestrians 0) (spec_service 0))) 
    (not 
     (exists (obstacles (location (+ ?location_car 1)))) 
    ) 
) 
=> 
(printout t "Drive to location") 
(modify ?fact-id1 (location (+ ?location_car 2))) 
) 

答えて

0

戻り値制約(等号、=)を使用して、フィールドを関数呼び出しの戻り値に制限します。

(defrule r6 "Drive to location" 
    ?fact-id1 <- (car (location ?location_car)) 
    (or 
    (exists (obstacles (location =(+ ?location_car 1)) 
         (tlights 0) 
         (cars 0) 
         (pedestrians 0) 
         (spec_service 0))) 
    (not 
     (exists (obstacles (location =(+ ?location_car 1)))) 
    ) 
) 
=> 
(printout t "Drive to location") 
(modify ?fact-id1 (location (+ ?location_car 2))) 
) 
関連する問題