users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: representing 'OR' condition in Prolog.. (removing duplicatesefficien


From: Robert Wolf
Subject: RE: representing 'OR' condition in Prolog.. (removing duplicatesefficiently).
Date: Fri, 1 Nov 2002 10:42:14 +1030

Hector Palacios,

Correct in general but not in this particular report.
This will do exactly what you have programmed: ONLY ONE ANSWER.
In report it is used as a "generator" not as a "filter".
The cut will prevent generating other possible "permanent employees".
Of course assuming there may be more than ONE "permanent employee".
And if there is at least ONE "permanent employee" the program will not
return any of the "satisfactory performance employees".
BTW, you are perfectly correct saying it is more eficient with "cut".

Robert P. Wolf
address@hidden

-----Original Message-----
From: Hector Palacios [mailto:address@hidden
Sent: Friday, 1 November 2002 10:07 AM
To: address@hidden
Subject: Re: representing 'OR' condition in Prolog.. (removing
duplicatesefficiently).



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.




_______________________________________________
Users-prolog mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/users-prolog




reply via email to

[Prev in Thread] Current Thread [Next in Thread]