users-prolog
[Top][All Lists]
Advanced

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

Re: determinism


From: Gregory Bourassa
Subject: Re: determinism
Date: Mon, 12 Feb 2007 12:56:42 -0500

Daniel,

Does your solution not return one solution to the caller before it ascertains whether or not the goal is really deterministic?

This program is a bit simplistic and it actually tries G three times; but it only returns a solution if G is really deterministic.

det(G) :- retractall( success ),  call(G),  backtrack_only_once,  !,  fail.

det(G) :- success, call(G).

backtrack_only_once :- success.

backtrack_only_once :- not( success ),  assertz( success ), !, fail.

Regards.

Gregory Bourassa

 



On Mon Feb 12 12:11 , Daniel Diaz sent:

michel levy a écrit :
> Could you help to write this program :
> det(T,G) succeeds if and only if G succeeds once and only once and give
> the T answer.
> 1) I don't want the solution below by findall, because I want to try at
> most two back tracks on G.
> det(T,G) :- findall(T,G,L),length(L,1)
>
> 2) I know already call_det but it's not the solution because G can have
> choice points, but only one answer.
>

You can do it using a global variable to count solutions. Stop when the
second is reached.


det(Goal) :-
det1(Goal).

det(_) :-
g_read(det_count, 1).


det1(Goal) :-
g_assign(det_count, 0),
call(Goal),
g_inc(det_count, Count), % increment and return the counter
Count = 2, % cut if 2nd solution is reached (else fail)
!,
fail.

Hope this helps



--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.



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



reply via email to

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