2015-11-23 2 views
1

Я делаю программу CLIPS, где у меня есть:Найти наименьшее значение с условиями в клипах

факты отеля: (отель Название отеля город звезды)

Страна факты, где все города, принадлежащих к страна появится: (Pais COUNTRYNAME city1 City2 ....)

цена факты: (Precio kindofroom цены Название отеля availablerooms)

Дело в том, мне нужно найти самый дешевый отель по некоторым характеристикам, например, позволяет предположить, что у меня есть это исходные факты:

(deffacts condiciones-iniciales 
(hotel RiuTaino PuntaCana 5) 
(hotel RiuFelicidad PuntaCana 4) 
(hotel RiuMaracana PuntaCana 4) 
(hotel RiuMaracana2 Baradero 4) 
(hotel RiuRon Baradero 4) 
(hotel RiuMaya RivieraMaya 4) 
(hotel RiuMojito RivieraMaya 4) 
(hotel RiuTequila RivieraMaya 5) 
(hotel RiuSalvaje ElCarmen 4) 
(hotel RiuMontana ElCarmen 4) 
(hotel RiuSantuario ElCarmen 5) 
(pais Rep_Dominicana PuntaCana Baradero SantoDomingo) 
(pais Mejico ELCarmen RivieraMaya Cancun) 
(precio RiuTaino suite 500 3) 
(precio RiuTaino standar 200 20) 
(precio RiuFelicidad suite 400 2) 
(precio RiuFelicidad standar 100 0) 
(precio RiuMaracana suite 600 0) 
(precio RiuMaracana standar 300 22) 
(precio RiuMaracana2 suite 650 1) 
(precio RiuMaracana2 standar 350 2) 
(precio RiuRon suite 900 6) 
(precio RiuRon standar 700 18) 
(precio RiuMaya suite 900 16) 
(precio RiuMaya standar 700 88) 
(precio RiuMojito suite 550 7) 
(precio RiuMojito standar 170 0) 
(precio RiuTequila suite 400 3) 
(precio RiuTequila standar 350 2) 
) 

и, например, я хочу, чтобы найти самый дешевый отель в Rep_Dominicana (любой город) 4 звезды, который имеет стандартные номера и доступные номера. Для того, чтобы найти отели, которые соответствуют этим характеристикам, я сделал:

(defrule busca-hoteles 
(hotel ?hotel ?ciudad ?estrellas) 
(pais Rep_Dominicana $? ?ciudad $?) 
(test (= ?estrellas 4)) 
(precio ?hotel standar ? ?habitaciones) 
(test (> ?habitaciones 0)) 
=> 
(printout t ?hotel crlf) 
) 

, но что я могу сделать, чтобы найти самый дешевый один среди тех, которые заполняют эти требования? Я полностью потерялся там. Заранее спасибо за любую помощь :)

ответ

1

Вот как вы можете изменить правило, чтобы найти самый дешевый номер:

(defrule busca-hoteles 

    ;; The city is in the dominica republic 

    (pais Rep_Dominicana $? ?ciudad $?) 

    ;; The hotel is in the city and 4 stars 

    (hotel ?hotel ?ciudad 4) 

    ;; There are available standard rooms in the hotel 

    (precio ?hotel standar ?price ?habitaciones) 
    (test (> ?habitaciones 0)) 

    ;; There are no other 4 star hotel in the same 
    ;; city with available standard rooms and a 
    ;; lower price 

    (not (and (hotel ?hotel2 ?ciudad 4) 
      (precio ?hotel2 standar ?price2 ?habitaciones2) 
      (test (> ?habitaciones2 0)) 
      (test (< ?price2 ?price)))) 

    => 

    (printout t "Cheapest 4 star hotel in " ?ciudad " is " 
       ?hotel " at " ?price crlf))