lisp实现的专家系统

来源:互联网 发布:service 网络请求 编辑:程序博客网 时间:2024/05/16 12:10

专家系统实现室温调节,用lisp实现

In this report I am going to explore an expert system. The goal of the expert system is to produce a solution to the problem of thermostat setting based on input data. The input data is established by asking questions to users. The questions may be something like “what month is it?” or “what day is it?” or “what time of a day is it?” According to information that user supplied, the expert system is able to recommend proper temperature as following:

Thermostat setting is ’20 degrees’

Thermostat setting is ’15 degrees’

Thermostat setting is ’24 degrees’

Thermostat setting is ’27 degrees s’

Thermostat setting is ’20 degrees’

Thermostat setting is ’16 degrees’

Thermostat setting is ’18 degrees’

Thermostat setting is ’14 degrees’

 

 代码如下:

(defcontext 'tempratureadjusting

 '(

   (month

        (jan feb mar apr may jun jul aug sep oct nov dec)

        ("what is the month"

         "jan feb mar apr may jun jul aug sep oct nov dec "

         )

   )

 

   (season (Summer autumn winter spring)

        ("what is the Season"

         "like Summer autumn winter spring"

         )

    )

   (Day (sat sun mon tue wed thu fri)

        ("what the day of week"

         "sat sun mon tue wed thu fri"

         )

   )

   (today (workday weekend)

        ("what type of day today"

         " workday weekend "

         )

   )

 (setting   string )

 

   (time (9-5 before-9 After-5)

        ("what is the time"

         "9-5 before-9 after-5")

    )

 

 

(operation (working-time spare-time

)

        ("Enter operation "

         " working-time spare-time")

    )

)

'(month)

'(setting)

)

 

----------------------------------------------------------------------------------------------------

 

(defrules

 

(rule01 ($or  (same cntxt Day mon)

              (same cntxt Day tue)

              (same cntxt Day wed)

              (same cntxt Day thu)

           (same cntxt Day fri)

        )

      (conclude cntxt today workday tally 1000))

 

 

 

(rule02 ($or (same cntxt Day sat)

                 (same cntxt Day sun)

        )

      (conclude cntxt today weekend tally 1000))

 

 

(rule03 ($and (same cntxt today workday)

                 (same cntxt time 9-5)

        )

      (conclude cntxt operation working-time tally 1000))

 

(rule04 ($and (same cntxt today workday)

                 (same cntxt time before-9)

        )

      (conclude cntxt operation spare-time tally 1000))

(rule05 ($and (same cntxt today workday)

                 (same cntxt time after-5)

        )

      (conclude cntxt operation spare-time tally 400))

 

(rule06 ($and (same cntxt today weekend)

        )

      (conclude cntxt operation spare-time tally 400))

 

(rule07 ($or (same cntxt month jan)

             (same cntxt month feb)

             (same cntxt month dec)

        )

      (conclude cntxt season summer tally 400))

 

(rule08 ($or (same cntxt month mar)

             (same cntxt month apr)

             (same cntxt month may)

        )

      (conclude cntxt season autumn tally 400))

 

(rule09 ($or (same cntxt month jun)

             (same cntxt month jul)

             (same cntxt month aug)

        )

      (conclude cntxt season winter tally 400))

 

 

(rule10 ($or (same cntxt month sep)

             (same cntxt month oct)

             (same cntxt month nov)

        )

      (conclude cntxt season spring tally 400))

 

(rule11 ($and (same cntxt season spring)

             (same cntxt operation working-time)

                     )

      (conclude cntxt setting  "it-is-set-to-20-degrees" tally 1000))

 

(rule12 ($and (same cntxt season spring)

             (same cntxt operation spare-time)

                     )

      (conclude cntxt setting  "it-is-set-to-15-degrees" tally 1000))

 

(rule13 ($and (same cntxt season summer)

             (same cntxt operation working-time)

                     )

      (conclude cntxt setting  "it-is-set-to-24-degrees" tally 1000))

 

(rule14 ($and (same cntxt season summer)

             (same cntxt operation spare-time)

                     )

      (conclude cntxt setting  "it-is-set-to-27-degrees" tally 1000))

 

(rule15 ($and (same cntxt season autumn)

             (same cntxt operation working-time)

                     )

      (conclude cntxt setting  "it-is-set-to-20-degrees" tally 1000))

 

(rule16 ($and (same cntxt season autumn)

             (same cntxt operation spare-time)

                     )

      (conclude cntxt setting  "it-is-set-to-16-degrees" tally 1000))

 

 

 

 

(rule17 ($and (same cntxt season winter)

             (same cntxt operation working-time)

                     )

      (conclude cntxt setting  "it-is-set-to-18-degrees" tally 1000))

(rule18 ($and (same cntxt season winter)

             (same cntxt operation spare-time)

                     )

      (conclude cntxt setting "it-is-set-to-14-degrees" tally 1000))

 

 

)

运行结果“

 

原创粉丝点击