[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: representing 'OR' condition in Prolog.. (removing duplicates efficie
From: |
Hector Palacios |
Subject: |
Re: representing 'OR' condition in Prolog.. (removing duplicates efficiently). |
Date: |
Thu, 31 Oct 2002 19:36:54 -0400 (VET) |
hmmm...
I think thats better:
leave_granted(Emp) :-
employee_status(Emp, permanent),!.
leave_granted(Emp) :-
performance(Emp, satisfactory).
The cut (!) is a must because you want that
leave_granted return yes only one time.
BTW, it is more efficient that Wolf version.
On Fri, 1 Nov 2002, Robert Wolf wrote:
> Abhinav-Bhardwaj,
>
> Your program is perfectly correct, this is how you represent "OR" in
> PROLOG.
> To remove duplicates insert negative conditions, something like:
>
> leave_granted(Emp) :-
> employee_status(Emp, permanent),
> NOT (performance (Emp, satisfactory)).
> leave_granted(Emp) :-
> performance(Emp, satisfactory),
> NOT (employee_status (Emp, permanent)).
>
> The first condition will "generate" employees, the second will filter
> them out.
> To make your program absolutely "beautifull" insert second clause to
> your report.
> Something like:
> leave_report :- write ('No (more) answers.').
> This will prevent your report from the "general failure" at the end.
I agree with it.
>
> Best regards and "happy prologing"...
>
> Robert P. Wolf
> address@hidden
>
>
> -----Original Message-----
> From: Abhinav-Bhardwaj [mailto:address@hidden
> Sent: Thursday, 31 October 2002 5:07 PM
> To: address@hidden
> Subject: representing 'OR' condition in Prolog..
>
>
> Hi,
> I want to know something in general about prolog . I want to know that
> how do I represent an 'OR' condition in prolog.
> For eg:- I want to define a leave rule saying that an employee can be
> granted a leave if - employee is a Permanent employee, OR
> - employee's performance is satisfactory.
>
> leave_granted(Emp) :- employee_status(Emp, permanent).
> leave_granted(Emp) :- performance(Emp, satisfactory).
>
> employee_status( raman, permanent).
> employee_status( abhinav, temporary).
>
> performance( raman, satisfactory).
> performance( abhinav, satisfactory).
>
> leave_report :-
> nl, write('leave may be granted to following employees:-'), nl,
> leave_granted(Emp),
> write('-'), write(Emp), nl,
> fail.
>
> Here is a sample output:
> =================
> ?- leave_granted(raman).
>
> yes
> ?- leave_granted(abhinav).
>
> yes
> ?- leave_report.
>
> leave may be granted to following employees:-
> -raman
> -raman
> -abhinav
> no
> ==================
> Now my question is:
> 1) Is this a correct way to represent the rule ?
> 2) The 'leave_report' displays the name 'raman' twice , and what I want
> is a list of unique names of employees that can be granted leave.
>
> thanks and regards,
> Abhinav
>
>
>
>
>
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/users-prolog
>
>
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/users-prolog
>
--
++++++++++++++++++++++++++++++++++++++++++++++
Hector L. Palacios V. - Dpto. Computacion y TI
Grupo de Inteligencia Artificial
Universidad Simon Bolivar - Caracas, Venezuela
+58-212-9063276(Of) +58-212-9063243(Fax)
http://www.ldc.usb.ve/~hlp/
----------------------------------------------
Ama y haz lo que quieras. San Agustin.