CLIPS. To count students and prinout sum - clips

deftemplate:
(deftemplate student
(multislot fio (type SYMBOL)(cardinality 1 3))
(slot den_rozhdeniya (type INTEGER))
(slot mecyaz_rozhdeniya (type SYMBOL))
(slot god_rozhdeniya (type INTEGER))
(slot den_postupleniya (type INTEGER))
(slot mecyaz_postupleniya (type SYMBOL))
(slot god_postupleniya (type INTEGER))
(multislot data_postupleniya (type SYMBOL NUMBER))
(slot facultet (default fit)(type SYMBOL))
(slot gruppa (type SYMBOL INTEGER))
(multislot adress (type SYMBOL INTEGER))
(multislot telefon (type NUMBER))
(slot sredniy_ball(range 0 10) (type INTEGER FLOAT)))
and 5 students:
(assert (student(fio Semenova Yuliya Igorevna) (den_rozhdeniya 10)(mecyaz_rozhdeniya oktyabr) (god_rozhdeniya 2000) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2014)(gruppa 14-itd) (adress Molodeznaya 108, kv. 10) (telefon 23 56 89) (sredniy_ball 9.5))
(student(fio Korneeva Alina Sergeevna) (den_rozhdeniya 5)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2001) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2015)(gruppa 15-itd) (adress Kalinina 8, kv. 4) (telefon 43 45 02) (sredniy_ball 8.5))
(student(fio Lenskaya Ekaterina Antonovna) (den_rozhdeniya 10)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2000) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2016)(gruppa 16-itd) (adress Molodeznaya 1, kv. 78) (telefon 23 56 89) (sredniy_ball 7))
(student(fio Petrov Slava Andreevich) (den_rozhdeniya 8)(mecyaz_rozhdeniya may) (god_rozhdeniya 2002)(den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2017)(gruppa 17-itd) (adress Pyshkina 5, kv. 13) (telefon 23 85 12) (sredniy_ball 5.5))
(student(fio Ivanova Svetlana Kirilovna)(den_rozhdeniya 25)(mecyaz_rozhdeniya avgust) (god_rozhdeniya 2001) (den_postupleniya 29)(mecyaz_postupleniya avgust) (god_postupleniya 2015)(gruppa 15-itd) (adress Molodeznaya 5, kv. 45) (telefon 78 32 51) (sredniy_ball 9)))
I need a rule whitch will count how many students in on group.
I know that possible to do it with this:
(length$ (find-all-facts ((?f student)) (eq ?f: gruppa 15-itd)))
BUt i woulf like to do it in defrule and also could be with defglobal
Here my effort:
(defglobal ?*gr* = 14-itd)
(bind ?*gr* (read))
(defrule rule1
(student (gruppa ?gruppa))
=>
(printout t (length$ (find-all-facts ((?f student)) (= ?f: gruppa ?*gr*))) crlf))

CLIPS>
(defrule rule1
=>
(printout t "Group? ")
(bind ?gr (read))
(printout t "Matching students: ")
(printout t (length$ (find-all-facts ((?f student)) (eq ?f:gruppa ?gr))) crlf))
CLIPS> (run)
Group? 15-itd
Matching students: 2
CLIPS>

Related

How to accumulate slots of facts?

I have the following two deftemplates:
(deftemplate effect (slot type) (slot value) (slot explanation))
(deftemplate result (slot type) (slot total_value) (multislot total_explanation))
and the following deffacts:
(effect (type A) (value 1) (explanation "A is 1"))
(effect (type A) (value 2) (explanation "A is 2"))
(effect (type B) (value 3) (explanation "B is 3"))
(effect (type B) (value 4) (explanation "B is 4"))
I want to sum up the total values for facts of the same type resulting in:
(result (type A) (total_value 3) (total_explanation "A is 1" "A is 2"))
(result (type B) (total_value 7) (total_explanation "B is 3" "B is 4"))
How would I accumulate the slots of facts? Here's what I tried:
(defrule accumulate_typeA
(exists (effect (type A)))
=>
(bind ?sum 0)
(do-for-all-facts ((?f effect) (bind ?sum (+ ?sum ?f:value))
(bind ?expl (create$))
(do-for-all-facts ((?f effect) (bind ?expl (inserts ?f:explanation))))
(assert (result (type A) (total_value ?sum) (total_explanation ?expl))
CLIPS (6.4 2/9/21)
CLIPS>
(deftemplate effect
(slot type)
(slot value)
(slot explanation))
CLIPS>
(deftemplate result
(slot type)
(slot total_value)
(multislot total_explanation))
CLIPS>
(deffacts initial
(effect (type A) (value 1) (explanation "A is 1"))
(effect (type A) (value 2) (explanation "A is 2"))
(effect (type B) (value 3) (explanation "B is 3"))
(effect (type B) (value 4) (explanation "B is 4")))
CLIPS>
(defrule accumulate_all_types
=>
(bind ?types (create$))
(do-for-all-facts ((?f effect)) TRUE
(if (not (member$ ?f:type ?types))
then
(bind ?types ?types ?f:type)))
(foreach ?t ?types
(bind ?sum 0)
(bind ?expl (create$))
(do-for-all-facts ((?f effect)) (eq ?f:type ?t)
(bind ?sum (+ ?sum ?f:value))
(bind ?expl ?expl ?f:explanation))
(assert (result (type ?t)
(total_value ?sum)
(total_explanation ?expl)))))
CLIPS> (reset)
CLIPS> (run)
CLIPS> (facts)
f-1 (effect (type A) (value 1) (explanation "A is 1"))
f-2 (effect (type A) (value 2) (explanation "A is 2"))
f-3 (effect (type B) (value 3) (explanation "B is 3"))
f-4 (effect (type B) (value 4) (explanation "B is 4"))
f-5 (result (type A) (total_value 3) (total_explanation "A is 1" "A is 2"))
f-6 (result (type B) (total_value 7) (total_explanation "B is 3" "B is 4"))
For a total of 6 facts.
CLIPS>

Test Templates against each other in CLIPS RULES

How do I test if all variables in template equal variables in different templates or if they don't. Need to have different outcomes from each output.
Attaching my code below:
``;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Sablony pre vstupy ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftemplate mobily
(slot znacka (type SYMBOL))
(slot model (type STRING) )
(slot rozlisenie (type SYMBOL) (allowed-values HD FULL_HD Q_HD))
(slot SD_Karta (type SYMBOL) (allowed-values ano nie))
(slot interna_pamat (type INTEGER) (range 32 512))
(slot operacny_system (type SYMBOL) (allowed-values iOS android ine))
(slot uhlopriecka (type FLOAT) (range 4.0 7.0))
(slot rozlisenie_fotoaparatu (type INTEGER) (range 4 128))
(slot kapacita_baterie (type INTEGER) (range 5 25)))
(deftemplate zakaznik
(slot znacka (type SYMBOL))
(slot model (type STRING))
(slot rozlisenie (type SYMBOL) (allowed-values HD FULL_HD Q_HD))
(slot SD_Karta (type SYMBOL) (allowed-values ano nie))
(slot interna_pamat (type INTEGER) (range 32 512))
(slot operacny_system (type SYMBOL) (allowed-values iOS android ine))
(slot uhlopriecka (type FLOAT) (range 4.0 7.0))
(slot rozlisenie_fotoaparatu (type INTEGER) (range 4 128))
(slot kapacita_baterie (type INTEGER) (range 5 25)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Vstupy ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deffacts mobily_na_sklade
(mobily(znacka Motorola)(model "Defy")(rozlisenie HD)(SD_Karta ano)(interna_pamat 64)(operacny_system android)(uhlopriecka 6.5)(rozlisenie_fotoaparatu 60)(kapacita_baterie 20)) (mobily(znacka Samsung)(model "Galaxy")(rozlisenie FULL_HD)(SD_Karta ano)(interna_pamat 128)(operacny_system android)(uhlopriecka 6.5)(rozlisenie_fotoaparatu 32)(kapacita_baterie 25))
(mobily(znacka Iphone)(model "14")(rozlisenie FULL_HD)(SD_Karta nie)(interna_pamat 128)(operacny_system iOS)(uhlopriecka 6.1)(rozlisenie_fotoaparatu 12)(kapacita_baterie 25))
(mobily(znacka Iphone)(model "13")(rozlisenie Q_HD)(SD_Karta nie)(interna_pamat 128)(operacny_system iOS)(uhlopriecka 6.1)(rozlisenie_fotoaparatu 12)(kapacita_baterie 20))
(mobily(znacka Asus)(model "Zenfone")(rozlisenie HD)(SD_Karta ano)(interna_pamat 32)(operacny_system android)(uhlopriecka 5.9)(rozlisenie_fotoaparatu 64)(kapacita_baterie 14))
(mobily(znacka Samsung)(model "Galaxy")(rozlisenie Q_HD)(SD_Karta nie)(interna_pamat 128)(operacny_system android)(uhlopriecka 6.1)(rozlisenie_fotoaparatu 12)(kapacita_baterie 25))
(mobily(znacka Motorola)(model "Moto")(rozlisenie FULL_HD)(SD_Karta ano)(interna_pamat 32)(operacny_system android)(uhlopriecka 6.3)(rozlisenie_fotoaparatu 13)(kapacita_baterie 15))
(mobily(znacka Xiaomi)(model "Redmi")(rozlisenie HD)(SD_Karta ano)(interna_pamat 64)(operacny_system android)(uhlopriecka 6.5)(rozlisenie_fotoaparatu 108)(kapacita_baterie 16))
)
(defrule vypis_uvod
=>
(printout t "Vitajte v programe na vyber telefonu" crlf)
(printout t "Prosim vyberte vase specifikacie: " crlf))
(defrule osobne_hodnoty
=>
(printout t "Zadajte znacku" crlf)
(bind ?znacka(read))
(printout t "Zadajte model" crlf)
(bind ?model(read))
(printout t "Zadajte ci vas vybrany telefon podporuje SD Karty (ano/nie)" crlf)
(bind ?SD_Karta(read))
(printout t "Zadajte rozlisenie displeja (HD, FULL_HD, Q_HD)" crlf)
(bind ?rozlisenie(read))
(printout t "Zadajte velkost internej pamete (32 - 512)" crlf)
(bind ?interna_pamat(read))
(printout t "Zadajte uhlopriecku (4.0 - 7.0)" crlf)
(bind ?uhlopriecka(read))
(printout t "Zadajte operacny system(iOS, android, ine)" crlf)
(bind ?operacny_system(read))
(printout t "Zadajte rozlisenie_fotoaparatu (4 - 128)" crlf)
(bind ?rozlisenie_fotoaparatu(read))
(printout t "Zadajte kapacitu baterie v hodinach (5 - 25" crlf)
(bind ?kapacita_baterie(read))
(assert (zakaznik (znacka ?znacka)(model ?model)(rozlisenie ?rozlisenie)(SD_Karta ?SD_Karta)(interna_pamat ?interna_pamat)(operacny_system ?operacny_system) (uhlopriecka ?uhlopriecka) (rozlisenie_fotoaparatu ?rozlisenie_fotoaparatu)(kapacita_baterie ?kapacita_baterie))))
(defrule telefon_je_na_sklade
(and
(zakaznik (znacka ?znacka)(model ?model)(rozlisenie ?rozlisenie)(SD_Karta ?SD_Karta)(interna_pamat ?interna_pamat)(operacny_system ?operacny_system) (uhlopriecka ?uhlopriecka) (rozlisenie_fotoaparatu ?rozlisenie_fotoaparatu)(kapacita_baterie ?kapacita_baterie))
(mobily (znacka ?znacka)(model ?model)(rozlisenie ?rozlisenie)(SD_Karta ?SD_Karta)(interna_pamat ?interna_pamat)(operacny_system ?operacny_system) (uhlopriecka ?uhlopriecka) (rozlisenie_fotoaparatu ?rozlisenie_fotoaparatu)(kapacita_baterie ?kapacita_baterie)))
=>
(printout t "Telefon je na sklade:" ?znacka ?model crlf))
(defrule telefon_nie_je_na_sklade
(and
(zakaznik (znacka ?znacka)(model ?model)(rozlisenie ?rozlisenie)(SD_Karta ?SD_Karta)(interna_pamat ?interna_pamat)(operacny_system ?operacny_system) (uhlopriecka ?uhlopriecka) (rozlisenie_fotoaparatu ?rozlisenie_fotoaparatu)(kapacita_baterie ?kapacita_baterie))
(not(mobily (znacka ?znacka)(model ?model)(rozlisenie ?rozlisenie)(SD_Karta ?SD_Karta)(interna_pamat ?interna_pamat)(operacny_system ?operacny_system) (uhlopriecka ?uhlopriecka) (rozlisenie_fotoaparatu ?rozlisenie_fotoaparatu)(kapacita_baterie ?kapacita_baterie))))
=>
(printout t "Bohuzial zadany telefon nemame na sklade" crlf))
`
`
I tried using AND in the rules but when I did this only the last rule was implemented even if the variables were actually the same.
Both of your rules work. You just need to use the exact values specified in your mobily facts including the same case for symbols/strings and the enclosing quotation marks if you are matching a string.
CLIPS> (reset)
CLIPS> (run)
Vitajte v programe na vyber telefonu
Prosim vyberte vase specifikacie:
Zadajte znacku
Xiaomi
Zadajte model
"Redmi"
Zadajte ci vas vybrany telefon podporuje SD Karty (ano/nie)
ano
Zadajte rozlisenie displeja (HD, FULL_HD, Q_HD)
HD
Zadajte velkost internej pamete (32 - 512)
64
Zadajte uhlopriecku (4.0 - 7.0)
6.5
Zadajte operacny system(iOS, android, ine)
android
Zadajte rozlisenie_fotoaparatu (4 - 128)
108
Zadajte kapacitu baterie v hodinach (5 - 25
16
Telefon je na sklade:XiaomiRedmi
CLIPS> (reset)
CLIPS> (run)
Vitajte v programe na vyber telefonu
Prosim vyberte vase specifikacie:
Zadajte znacku
Xiaomi
Zadajte model
"Redmi"
Zadajte ci vas vybrany telefon podporuje SD Karty (ano/nie)
ano
Zadajte rozlisenie displeja (HD, FULL_HD, Q_HD)
HD
Zadajte velkost internej pamete (32 - 512)
64
Zadajte uhlopriecku (4.0 - 7.0)
6.5
Zadajte operacny system(iOS, android, ine)
android
Zadajte rozlisenie_fotoaparatu (4 - 128)
108
Zadajte kapacitu baterie v hodinach (5 - 25
20
Bohuzial zadany telefon nemame na sklade
CLIPS>

How can I get the sum of items in a multislot

I have a template like the one shown bellow. How can I get the sum of items in the multislot grades?
(deftemplate student
(multislot name)
(multislot grades)
)
Here's one way to do it. In the reg6 rule, the + function is given two arguments of 0 in addition to the grades to insure that the + function allows has at least 2 arguments; otherwise, if there were zero or one grades for the student you'd get an error.
CLIPS (6.31 2/3/18)
CLIPS>
(deftemplate student
(multislot name)
(multislot grades))
CLIPS>
(deftemplate sum
(multislot name)
(slot grade))
CLIPS>
(defrule reg6
(student (name $?name)
(grades $?grades))
=>
(assert (sum (name ?name)
(grade (+ 0 0 (expand$ ?grades))))))
CLIPS>
(assert (student (name David Green) (grades))
(student (name Sue Brown) (grades 90))
(student (name Frank Black) (grades 85 75)))
<Fact-3>
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (student (name David Green) (grades))
f-2 (student (name Sue Brown) (grades 90))
f-3 (student (name Frank Black) (grades 85 75))
f-4 (sum (name Frank Black) (grade 160))
f-5 (sum (name Sue Brown) (grade 90))
f-6 (sum (name David Green) (grade 0))
For a total of 7 facts.
CLIPS>
You can use the expand$ function. Check in the Basic Programming Guide the Multifield Expansion Function chapter to know more.
(deftemplate student
(multislot name)
(multislot grades))
(defrule grades-sum
(student (grades $?grades))
=>
(printout t "Student grades sum is " (+ (expand$ ?grades))))
(assert (student (grades (create$ 1 2 3 4 5))))
(student (name) (grades 1 2 3 4 5))
(run)
Student grades sum is 15

CLIPS - to printout age of students (defrule) from slot deftemplate with year of birth

I have deftemplate:
(deftemplate student
(multislot fio (type SYMBOL)(cardinality 1 3))
(slot den_rozhdeniya (type INTEGER))
(slot mecyaz_rozhdeniya (type SYMBOL))
(slot god_rozhdeniya (type INTEGER))
(multislot data_postupleniya (type SYMBOL NUMBER))
(slot facultet (default fit)(type SYMBOL))
(slot gruppa (type SYMBOL INTEGER))
(multislot adress (type SYMBOL INTEGER))
(multislot telefon (type NUMBER))
(slot sredniy_ball(range 0 10) (type INTEGER FLOAT))
)
Also a have 5 students:
(assert (student(fio Semenova Yuliya Igorevna) (den_rozhdeniya 10)(mecyaz_rozhdeniya oktyabr) (god_rozhdeniya 2000) (data_postupleniya 29 avgust 2014)(gruppa 14-itd) (adress Molodeznaya 108, kv. 10) (telefon 23 56 89) (sredniy_ball 9.5))
(student(fio Korneeva Alina Sergeevna) (den_rozhdeniya 5)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2001) (data_postupleniya 29 avgust 2015)(gruppa 15-itd) (adress Kalinina 8, kv. 4) (telefon 43 45 02) (sredniy_ball 8.5))
(student(fio Lenskaya Ekaterina Antonovna) (den_rozhdeniya 10)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2000) (data_postupleniya 29 avgust 2016)(gruppa 16-itd) (adress Molodeznaya 1, kv. 78) (telefon 23 56 89) (sredniy_ball 7))
(student(fio Petrov Slava Andreevich) (den_rozhdeniya 8)(mecyaz_rozhdeniya may) (god_rozhdeniya 2002)(data_postupleniya 29 avgust 2017)(gruppa 17-itd) (adress Pyshkina 5, kv. 13) (telefon 23 85 12) (sredniy_ball 5.5))
(student(fio Ivanova Svetlana Kirilovna)(den_rozhdeniya 25)(mecyaz_rozhdeniya avgust) (god_rozhdeniya 2001) (data_postupleniya 29 avgust 2015)(gruppa 15-itd) (adress Molodeznaya 5, kv. 45) (telefon 78 32 51) (sredniy_ball 9))
)
And i cannot find solution, how to printout with this defrule age of students.
(god_rozhdeniya 2000) this is that slot with year of birth and printout should be like:
Semenova Yuliya Igorevna 18
this is my defrule whitch are not working :
(defrule first
(student (fio ?fio)(god_rozhdeniya ?god_rozhdeniya) (age ?age)
(?age (- 2018 ?god_rozhdeniya))
=>
(printout t ?fio ? age crlf))
CLIPS (6.31 2/3/18)
CLIPS>
(deftemplate student
(multislot fio (type SYMBOL)(cardinality 1 3))
(slot den_rozhdeniya (type INTEGER))
(slot mecyaz_rozhdeniya (type SYMBOL))
(slot god_rozhdeniya (type INTEGER))
(multislot data_postupleniya (type SYMBOL NUMBER))
(slot facultet (default fit)(type SYMBOL))
(slot gruppa (type SYMBOL INTEGER))
(multislot adress (type SYMBOL INTEGER))
(multislot telefon (type NUMBER))
(slot sredniy_ball(range 0 10) (type INTEGER FLOAT)))
CLIPS>
(deffacts students
(student (fio Semenova Yuliya Igorevna)
(den_rozhdeniya 10)
(mecyaz_rozhdeniya oktyabr)
(god_rozhdeniya 2000)
(data_postupleniya 29 avgust 2014)
(gruppa 14-itd)
(adress Molodeznaya 108, kv. 10)
(telefon 23 56 89)
(sredniy_ball 9.5))
(student (fio Korneeva Alina Sergeevna)
(den_rozhdeniya 5)(mecyaz_rozhdeniya yanvar)
(god_rozhdeniya 2001)
(data_postupleniya 29 avgust 2015)
(gruppa 15-itd)
(adress Kalinina 8, kv. 4)
(telefon 43 45 02)
(sredniy_ball 8.5))
(student (fio Lenskaya Ekaterina Antonovna)
(den_rozhdeniya 10)
(mecyaz_rozhdeniya yanvar)
(god_rozhdeniya 2000)
(data_postupleniya 29 avgust 2016)
(gruppa 16-itd)
(adress Molodeznaya 1, kv. 78)
(telefon 23 56 89)
(sredniy_ball 7))
(student (fio Petrov Slava Andreevich)
(den_rozhdeniya 8)
(mecyaz_rozhdeniya may)
(god_rozhdeniya 2002)
(data_postupleniya 29 avgust 2017)
(gruppa 17-itd)
(adress Pyshkina 5, kv. 13)
(telefon 23 85 12)
(sredniy_ball 5.5))
(student (fio Ivanova Svetlana Kirilovna)
(den_rozhdeniya 25)
(mecyaz_rozhdeniya avgust)
(god_rozhdeniya 2001)
(data_postupleniya 29 avgust 2015)
(gruppa 15-itd)
(adress Molodeznaya 5, kv. 45)
(telefon 78 32 51)
(sredniy_ball 9)))
CLIPS>
(defrule first
(student (fio $?fio)
(god_rozhdeniya ?god_rozhdeniya))
=>
;(bind ?year 2018)
(bind ?year (nth$ 1 (local-time)))
(printout t (implode$ ?fio) " " (- ?year ?god_rozhdeniya) crlf))
CLIPS> (reset)
CLIPS> (run)
Ivanova Svetlana Kirilovna 17
Petrov Slava Andreevich 16
Lenskaya Ekaterina Antonovna 18
Korneeva Alina Sergeevna 17
Semenova Yuliya Igorevna 18
CLIPS>

check multiple fields in if() CLIPS

I'm trying to do a comparation in a rule on CLIPS thah check if one of three conditions it's true to assert a new fact. The code is:
(defrule empresa_cae_mucho
(Empresa (nombre ?n)(var_anio ?anio)(var_sem ?sem)(var_tri ?tri))
=>
(or (or (test(> ?anio 30))(test (> ?sem 30))(test (> ?tri 30))))
(assert valor_infravalorado
(nombre ?n))
(assert (Explicacion
(nombre ?n)
(motivo "la empresa ha caido bastante aunque no en el ultimo mes
pero su PER es bajo")))
)
But it doesn't work and I can't find the right form of do this in internet. Any help?
CLIPS> (clear)
CLIPS>
(deftemplate Empresa
(slot nombre)
(slot var_anio)
(slot var_sem)
(slot var_tri))
CLIPS>
(deftemplate valor_infravalorado
(slot nombre))
CLIPS>
(deftemplate Explicacion
(slot nombre)
(slot motivo))
CLIPS>
(deffacts start
(Empresa (nombre 1) (var_anio 40) (var_sem 10) (var_tri 25))
(Empresa (nombre 2) (var_anio 0) (var_sem 35) (var_tri 10))
(Empresa (nombre 3) (var_anio 30) (var_sem 20) (var_tri 55))
(Empresa (nombre 4) (var_anio 30) (var_sem 30) (var_tri 30)))
CLIPS>
(defrule empresa_cae_mucho
(Empresa (nombre ?n)
(var_anio ?anio)
(var_sem ?sem)
(var_tri ?tri))
(test (or (> ?anio 30)
(> ?sem 30)
(> ?tri 30)))
=>
(assert (valor_infravalorado (nombre ?n)))
(assert (Explicacion
(nombre ?n)
(motivo "la empresa ..."))))
CLIPS> (reset)
CLIPS> (watch rules)
CLIPS> (watch facts)
CLIPS> (run)
FIRE 1 empresa_cae_mucho: f-3
==> f-5 (valor_infravalorado (nombre 3))
==> f-6 (Explicacion (nombre 3) (motivo "la empresa ..."))
FIRE 2 empresa_cae_mucho: f-2
==> f-7 (valor_infravalorado (nombre 2))
==> f-8 (Explicacion (nombre 2) (motivo "la empresa ..."))
FIRE 3 empresa_cae_mucho: f-1
==> f-9 (valor_infravalorado (nombre 1))
==> f-10 (Explicacion (nombre 1) (motivo "la empresa ..."))
CLIPS> (facts)
f-0 (initial-fact)
f-1 (Empresa (nombre 1) (var_anio 40) (var_sem 10) (var_tri 25))
f-2 (Empresa (nombre 2) (var_anio 0) (var_sem 35) (var_tri 10))
f-3 (Empresa (nombre 3) (var_anio 30) (var_sem 20) (var_tri 55))
f-4 (Empresa (nombre 4) (var_anio 30) (var_sem 30) (var_tri 30))
f-5 (valor_infravalorado (nombre 3))
f-6 (Explicacion (nombre 3) (motivo "la empresa ..."))
f-7 (valor_infravalorado (nombre 2))
f-8 (Explicacion (nombre 2) (motivo "la empresa ..."))
f-9 (valor_infravalorado (nombre 1))
f-10 (Explicacion (nombre 1) (motivo "la empresa ..."))
For a total of 11 facts.
CLIPS>

Resources